The shape of the lesson
By the end of the lesson, learners can
- Algorithms and identifiers: Fig. 1 is an algorithm: a finite sequence of defined steps that always does the same thing for the same input.
- Sequence, selection, iteration: Step through the programs in the lab and watch the trace table fill.
- Changing between forms: Structured English uses short numbered English sentences with key words such as INPUT, SET, IF and REPEAT.
- Identifier table: name, data type and description for every identifier.
- Constructs: sequence (in order), selection (IF, CASE), iteration (FOR, REPEAT, WHILE).
- Flowchart loops: decision before the body is WHILE; decision after the body is REPEAT.
- 9618 layout: IF ... THEN on one line, ENDIF, WHILE without DO, <> for not equal, ← for assignment.
One picture every idea returns to
An algorithm is a solution to a problem expressed as a sequence of defined steps. Most algorithms take an input, process it and produce an output. Data is named with meaningful identifiers, listed in an identifier table with each one's data type and purpose. Every algorithm is built from three constructs: sequence, selection (IF, CASE) and iteration (FOR, REPEAT, WHILE). It can be documented as structured English, a flowchart or pseudocode.
Forty-five minutes, phase by phase
| Time | Phase | What happens in the room | Grouping |
|---|---|---|---|
| 0 to 5 min | Hook: predict | Open with the question in the title, One algorithm, three forms.. An algorithm is a sequence of defined steps that solves a problem. Put the figure on the board: it is the one picture every idea in the lesson returns to. | Whole class, then pairs |
| 5 to 13 min | Teach and check: Algorithms and identifiers | Fig. 1 is an algorithm: a finite sequence of defined steps that always does the same thing for the same input. Your turn: A program inputs the length and width of a rectangle in metres and outputs its area. Write an identifier table for it. | Whole class, then pairs |
| 13 to 21 min | Teach and check: Sequence, selection, iteration | Step through the programs in the lab and watch the trace table fill. Project tab 1 of the lab (Sequence, selection and iteration) and let a student drive it while the class predicts. Model the worked example Spot the constructs on the board, one line at a time. | Pairs |
| 21 to 30 min | Teach and check: Changing between forms | Structured English uses short numbered English sentences with key words such as INPUT, SET, IF and REPEAT. Model the worked example Flowchart to pseudocode on the board, one line at a time. Your turn: Write pseudocode from this structured English: 1. INPUT the price and the quantity. 2. SET the cost to price times quantity. 3. IF the cost is more than 100, take 10% off the cost. 4. OUTPUT the cost. | Anticipation / Reaction Guide |
| 30 to 36 min | Check | The four Stage 1 questions from the student lesson, answered on mini whiteboards or by show of fingers. Re-teach the one most get wrong. | Individual, then whole class |
| 36 to 43 min | Plenary | The exam-style questions from Stage 2, one at a time: thirty seconds alone, then a random call. The feedback lines in the key give the examiner's wording. | Individual, random call |
| 43 to 45 min | Exit and homework | Set the worksheet below (6 questions, 19 marks). Learners self-assess against the objectives before they leave. | Individual |
Protect the parts that carry the learning
The sequence carries about fifty minutes of material, so the lab is driven by one student while the class predicts rather than explored freely. Times are a guide.
Protected: the check at 30 minutes. It is the only individual read on whether the key idea landed, and it is not cut.
Cut first if the build overruns: the last check in Changing between forms, never the check or the plenary.
In a 60 minute block: run worksheet questions 1 to 3 in class as a Rally Coach set and model both the hardest worked example and its check live.
Anticipation / Reaction Guide
Before the lesson, students mark five statements true or false. After the teaching they mark them again and justify any change of mind in one sentence each. The statements come from the examiner traps below.
The full structure, with its variations and the other twelve, is on the cooperative-learning page.
What to head off, and how
| Trap learners fall into | Teaching move that pre-empts it |
|---|---|
| An identifier table needs three things for each identifier: the name, its data type and what it is used for. | Leaving out the description loses the mark. |
| In 9618 pseudocode the THEN goes on the same line as the IF, and WHILE has no DO: WHILE Mark <> -1. | Use <> for not equal, never!= or =/=. |
| In a flowchart, a loop is drawn with a decision and a flow line going back. | Put the decision before the body for WHILE and after the body for REPEAT, and label both exits of every decision. |
Structured English, flowcharts and pseudocode: worksheet
6 questions, 19 marks. Written in the style of the papers; no past paper question is reproduced.
Explain what is meant by an algorithm.
A program inputs a student's name and the number of hours they studied on each of 5 days, and outputs their name with the total hours. Complete an identifier table for three of the identifiers it needs.
The algorithm in Fig. 1 is run with the inputs 8, 15, 4, 9, -1. State the final values of Total and Count and the output.
Write pseudocode from this structured English description:
1. SET Highest to 0
2. REPEAT the next two steps 10 times
3. INPUT a score
4. IF the score is greater than Highest, SET Highest to the score
5. OUTPUT Highest
Describe how the pseudocode WHILE Number > 9 ... ENDWHILE would be drawn as part of a flowchart.
Give one advantage of each method of documenting an algorithm: (a) structured English; (b) a flowchart; (c) pseudocode.
Answer key and marking notes
- A solution to a problem / a way of carrying out a task.
- Expressed as a (finite) sequence of defined steps.
- StudentName : STRING, the name input.
- Hours : REAL (or INTEGER), hours studied on one day.
- TotalHours : REAL, sum of the hours for the 5 days (also accept Day : INTEGER, loop counter 1 to 5).
- Total = 8 + 15 + 4 + 9 = 36.
- Count = 4 (the rogue value -1 is not added or counted).
- Output 36 / 4 = 9 (a REAL, 9.0).
Highest ← 0before the loop.FOR Index ← 1 TO 10...NEXT Index.INPUT Scoreinside the loop.IF Score > Highest THEN Highest ← Score ENDIFinside the loop.OUTPUT Highestafter the loop.
- A decision symbol (diamond) containing
Number > 9?placed before the loop body. - The Yes / True exit leads to the process box(es) of the body, and a flow line returns from the end of the body to the decision.
- The No / False exit leads to the step after the loop; both exits are labelled.
- (a) Structured English: easy for a non-programmer / the client to read and agree.
- (b) Flowchart: shows the flow of control and loops visually, so the paths are easy to follow.
- (c) Pseudocode: close to program code, so it is quick to convert into a programming language, but is not tied to one language.
6 multiple-choice questions on this lesson
From the topic question bank. Assign them in the app for a marked score in your gradebook, or run the topic as a class game.
A programmer writes an identifier table for an algorithm. What must be recorded for each identifier?
- AIts name, its data type and a description of what it is used for
- BIts name, its value at the end of the run and the line where it is used
- CIts name, its memory address and the number of bytes it needs
- DIts name, whether it is input or output and its first value
Which is the most suitable identifier for the number of tickets sold at a concert?
- A
TicketsSold - B
Tickets Sold - C
2Tickets - D
T
The marks 45, 70, 50, 12 and then −1 are input to this pseudocode. What is output?
Total ← 0
Count ← 0
INPUT Mark
WHILE Mark <> -1
IF Mark >= 50 THEN
Count ← Count + 1
ENDIF
Total ← Total + Mark
INPUT Mark
ENDWHILE
OUTPUT Count, " ", Total- A
2 177 - B
1 177 - C
2 176 - D
4 177
Structured English: "Keep asking the user for a PIN until the PIN entered is exactly 4 characters long." Which pseudocode matches this?
- A
REPEAT INPUT PIN UNTIL LENGTH(PIN) = 4 - B
REPEAT INPUT PIN UNTIL LENGTH(PIN) <> 4 - C
WHILE LENGTH(PIN) = 4 INPUT PIN ENDWHILE - D
FOR Count ← 1 TO 4 INPUT PIN NEXT Count
What is output by this pseudocode?
Total ← 0
FOR i ← 3 TO 15 STEP 4
Total ← Total + i
NEXT i
OUTPUT Total- A36
- B21
- C33
- D4
This pseudocode was written from a flowchart. The first value input is −1. What happens?
Total ← 0
Count ← 0
INPUT Mark
WHILE Mark <> -1
Total ← Total + Mark
Count ← Count + 1
INPUT Mark
ENDWHILE
OUTPUT Total / Count- AThe loop body never runs, so Count is 0 and the division causes a run-time error
- BThe loop body runs once, so the value −1 is output as the average
- CThe loop never ends, because the condition is tested before any mark is added
- DThe value 0 is output, because Total and Count both still hold 0
Quiz key
An identifier table lists every identifier with its data type and its purpose. Final values belong in a trace table, memory addresses are decided by the translator, not the designer, and many identifiers (such as counters) are neither input nor output.
TicketsSold starts with a letter, contains only letters and describes the data. An identifier cannot contain a space or start with a digit, and T is legal but meaningless, so a reader cannot tell what it stores.
70 and 50 satisfy Mark >= 50, so Count = 2, and Total = 45 + 70 + 50 + 12 = 177. The −1 ends the loop before it is added. 1 177 treats the test as > 50, 2 176 wrongly adds the rogue value, and 4 177 counts every mark instead of only those of 50 or more.
REPEAT runs the INPUT at least once and stops when the condition after UNTIL becomes TRUE, a PIN of length 4. Using <> 4 would stop on a wrong PIN. The WHILE version tests a PIN that has not been input yet and keeps looping only while the PIN is valid, the reverse of what is wanted. The FOR loop always asks exactly 4 times, whatever is typed.
i takes 3, 7, 11 and 15 (15 is reached exactly, so it is included), and 3 + 7 + 11 + 15 = 36. 21 stops before 15, 33 misses the start value 3, and 4 is the number of times the loop runs, not the total.
WHILE is a pre-condition loop: −1 makes the condition FALSE at once, so the body runs zero times and Count stays 0. Total / Count is then a division by zero, a run-time error; a safer version checks Count > 0 first. The body does not run once (that would be REPEAT), the loop does end, and 0 / 0 does not give 0.
What to project
The student lesson embeds these tabs. Open them full screen on the projector; every slider has a drag handle on the stage.
Slides for this lesson
A projectable deck for every pack is on the way. Until then, present the student lesson full screen: its sections, figure and lab tabs follow the same order as the plan above.