Lesson 103 — Introducing Algorithms: Sequences of Steps and Decisions
Strand: Space | Descriptor: AC9M7SP04 | Duration: 45 minutes
Learning Intentions
- To understand an algorithm as a precise sequence of steps and decisions.
- To follow, write and trace simple algorithms.
Success Criteria
I can:
- Define an algorithm and give everyday examples.
- Follow an algorithm exactly, without adding my own assumptions.
- Recognise a decision step and its two branches.
- Write a short algorithm in numbered steps.
Warmup
(6 minutes — the sandwich disaster, whole class)
The teacher follows student instructions literally to make a jam sandwich (mimed or with real props).
Ask for instructions. Follow each one exactly as stated — “put jam on bread” gets the jar placed on the loaf; “open the bread” gets the bag torn open.
- Why did it go wrong?
- What was missing from the instructions?
- What would it take to make the instructions foolproof?
Answers: 1. Steps assumed knowledge the follower did not have; 2. Precision, order, and unstated sub-steps; 3. Every action broken down, in order, with nothing assumed.
The definition, earned: an algorithm is a precise, ordered sequence of steps that anyone (or any machine) can follow to complete a task, with no guessing required.
Activities
Activity 1 — Explicit Instruction: Steps, Decisions and Tracing (14 min)
Two kinds of step:
| Type | What it does | Example |
|---|---|---|
| Instruction | Do something | ”Measure the longest side.” |
| Decision | Ask a yes/no question, then branch | ”Are all three sides equal? If yes → …; if no → …” |
Writing conventions for this course:
- Number every step.
- Decisions are written as questions with both branches given.
- The algorithm must end — every path reaches a stop.
I do — a non-geometric algorithm (getting to school):
- Is it raining?
- Yes → take an umbrella. Go to step 2.
- No → go to step 2.
- Is the time before 8:15?
- Yes → walk. Stop.
- No → catch the bus. Stop.
Trace it aloud for two cases: raining at 8:00 (umbrella, walk) and dry at 8:30 (no umbrella, bus). Tracing means following the algorithm step by step for a specific input and recording what happens.
I do — a number algorithm:
- Write down your number.
- Is it even?
- Yes → halve it. Go to step 3.
- No → triple it and add
. Go to step 3. - Is the result
?
- Yes → stop.
- No → go back to step 2.
Trace with input
Trace with input
(This is the Collatz algorithm. Whether it always stops is a famous unsolved problem — worth one sentence: some algorithms are easy to write and hard to understand.)
We do — trace together:
- Start with a number.
- Is it greater than
?
- Yes → subtract
. Go back to step 2. - No → go to step 3.
- Write down the result. Stop.
Trace with
The
Activity 2 — Following and Tracing (14 min)
Pairs. Follow exactly; no improvising.
Algorithm A — the sorter.
- Take the first number in your list.
- Is it odd?
- Yes → put it in pile A. Go to step 3.
- No → put it in pile B. Go to step 3.
- Are there numbers left?
- Yes → take the next number. Go back to step 2.
- No → stop.
- Trace with the list
. What is in each pile? - Describe in one sentence what this algorithm does.
Algorithm B — the guessing game.
- Think of the range
to . Guess the middle number. - Is the guess correct?
- Yes → stop.
- No → go to step 3.
- Is the guess too high?
- Yes → the new range is from the bottom to just below the guess. Go to step 1.
- No → the new range is from just above the guess to the top. Go to step 1.
- Trace for the secret number
. List each guess. - What is the greatest number of guesses this could ever need for
– ?
Algorithm C — spot the flaw. Each of these has a problem. Find it.
C1: 1. Add
. 2. Go back to step 1. C2: 1. Is the number big? Yes → stop. No → add
, go to step 1. C3: 1. Divide by the number of sides. 2. Stop.
Socratic scaffolding for Algorithm C:
| Prompt | Purpose |
|---|---|
| For C1, trace it. When does it stop? | Never — an infinite loop; no exit condition. |
| For C2, what is wrong with “big”? | Undefined. One follower’s “big” is another’s “small” — decisions must be testable. |
| For C3, what is missing? | An input. Divide what? Algorithms need their starting materials specified. |
| So what are the three requirements? | Precision, a definite ending, and defined inputs. |
(Answers: 1. Pile A:
Activity 3 — Inquiry: Write Your Own (9 min)
Pairs, then swap and trace.
Write an algorithm, in numbered steps with at least one decision, for one of:
- Deciding whether a number is a multiple of
. - Finding the largest of three numbers.
- Deciding whether a whole number between
and is prime (hard — use Lesson 4’s divisibility ideas). Then swap with another pair and trace their algorithm on three inputs of your choosing, including a deliberately awkward one.
Sample solution for Q2 (teacher reference):
- Call the numbers
, , . - Is
? Yes → let . No → let . - Is
? Yes → the largest is . No → the largest is . - Stop.
Awkward inputs to encourage: equal numbers, zero, negatives. A good algorithm survives them or explicitly excludes them.
Checks for Understanding
(5 minutes — exit ticket)
- Define “algorithm” in one sentence.
- What is the difference between an instruction step and a decision step?
- Trace: start with
; while the number is odd, add ; stop when even. What is the result? - Name two things an algorithm must have to be usable.
- Reasoning. Why is “if the number is large, stop” a badly written decision?
Answers: 1. A precise ordered sequence of steps for completing a task, requiring no guessing; 2. An instruction does something; a decision asks a testable question and branches; 3.
Common Misconceptions
| Misconception | How to pre-empt it |
|---|---|
| Filling gaps with common sense when following. | The sandwich disaster; “follow exactly” is enforced all lesson. |
| Vague decision questions. | Algorithm C2 and exit Q5 make testability a requirement. |
| Algorithms that never stop. | C1’s infinite loop; every algorithm must reach a stop. |
| Treating “greater than” as “greater than or equal”. | The |
| Believing an algorithm is just a list of instructions. | Decisions and branching are what make it powerful. |
| Skipping the trace and assuming it works. | Every written algorithm is traced by another pair. |
Enrichment — Competition-Style Problems
E1 (Kangaroo style). Trace: start at
Answer
E2 (AMC Junior style). An algorithm: “Take a two-digit number; add its digits; if the result is two digits, repeat.” Trace
Answer
E3 (Challenge). Using the halving guessing algorithm on
Answer
Each guess halves the range:
E4 (Challenge). Write an algorithm to find the highest common factor of two numbers using repeated subtraction, then trace it on
Answer
- Are the numbers equal? Yes → that is the HCF, stop. No → go to 2.
- Subtract the smaller from the larger, replacing the larger. Go to 1.
Trace:
Homework
-
Define “algorithm” and give two everyday examples that are not from mathematics.
-
Trace this algorithm for inputs
, and : - Is the number odd? Yes → add
. No → halve it. - Is the result less than
? Yes → stop. No → go to step 1.
- Is the number odd? Yes → add
-
What is wrong with each: (a) “1. Keep going until you’re done.” (b) “1. If the shape looks nice, keep it.” (c) “1. Multiply. 2. Stop.”
-
Write an algorithm with at least one decision for: deciding whether a number is a multiple of
. -
Write an algorithm for finding the smallest of four numbers.
-
Trace Algorithm B (the guessing game) for the secret number
in the range – . List the guesses. -
Reasoning. Explain why an algorithm must always end.
-
Reasoning. Why must decision questions be answerable with a definite yes or no?
-
Challenge. Write an algorithm to decide whether a whole number between
and is prime, using divisibility tests only up to its square root (Lesson 4). Trace it on and on .
Answers: Q2 —