Teachers' Portal  /  A-Level Computer Science 9618  /  Algorithm design and problem-solving  /  Structured English, flowcharts and pseudocode
Lesson pack · A-Level Computer Science 9618 · 9.2 · AS Level

Structured English, flowcharts and pseudocode

One algorithm, three forms. An algorithm is a sequence of defined steps that solves a problem.

Student lesson Lab, full screen
At a glance

The shape of the lesson

Topic
Algorithm design and problem-solving
Syllabus reference
Cambridge International AS and A Level Computer Science 9618, 9.2
Level
AS Level
Duration
45 minutes, lab-led; stretches to a 60 minute block (see the contingency notes)
Position in topic
Lesson 2 of 3 in Algorithm design and problem-solving; follows Abstraction and decomposition; leads into Stepwise refinement
Central model
Fig. 1: a flowchart that inputs marks until the rogue value -1 and outputs their average
Cooperative structure
Assessment
Stage 1 check and the exam-style plenary from the student lesson, plus the worksheet as the exit task
Learning objectives

By the end of the lesson, learners can

Section by section
  • 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.
Key points to leave on the board
  • 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.
The core visual model

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.

START Total ← 0Count ← 0 INPUT Mark Mark = -1? Total ← Total + MarkCount ← Count + 1 INPUT Mark OUTPUTTotal / Count STOP YesNo
Fig. 1: a flowchart that inputs marks until the rogue value -1 and outputs their average
Lesson sequence

Forty-five minutes, phase by phase

TimePhaseWhat happens in the roomGrouping
0 to 5 minHook: predictOpen 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 minTeach and check: Algorithms and identifiersFig. 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 minTeach and check: Sequence, selection, iterationStep 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 minTeach and check: Changing between formsStructured 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 minCheckThe 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 minPlenaryThe 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 minExit and homeworkSet the worksheet below (6 questions, 19 marks). Learners self-assess against the objectives before they leave.Individual
Timing and contingency

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.

Running the cooperative task

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.

Examiner traps to pre-empt

What to head off, and how

Trap learners fall intoTeaching 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.
Worksheet

Structured English, flowcharts and pseudocode: worksheet

6 questions, 19 marks. Written in the style of the papers; no past paper question is reproduced.

NameClassDate
Q1 · recall[2 marks]

Explain what is meant by an algorithm.

Q2 · apply[3 marks]

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.

Q3 · trace[3 marks]

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.

Q4 · write[5 marks]

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

Q5 · explain[3 marks]

Describe how the pseudocode WHILE Number > 9 ... ENDWHILE would be drawn as part of a flowchart.

Q6 · analysis[3 marks]

Give one advantage of each method of documenting an algorithm: (a) structured English; (b) a flowchart; (c) pseudocode.

Answer key and marking notes
Q1 · 2 marks
  • A solution to a problem / a way of carrying out a task.
  • Expressed as a (finite) sequence of defined steps.
Q2 · 3 marks
  • 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).
Q3 · 3 marks
  • 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).
Q4 · 5 marks
  • Highest ← 0 before the loop.
  • FOR Index ← 1 TO 10 ... NEXT Index.
  • INPUT Score inside the loop.
  • IF Score > Highest THEN Highest ← Score ENDIF inside the loop.
  • OUTPUT Highest after the loop.
Q5 · 3 marks
  • 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.
Q6 · 3 marks
  • (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.
Quiz

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.

Q11 mark

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
Q21 mark

Which is the most suitable identifier for the number of tickets sold at a concert?

  • ATicketsSold
  • BTickets Sold
  • C2Tickets
  • DT
Q31 mark

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

  • A2 177
  • B1 177
  • C2 176
  • D4 177
Q41 mark

Structured English: "Keep asking the user for a PIN until the PIN entered is exactly 4 characters long." Which pseudocode matches this?

  • AREPEAT INPUT PIN UNTIL LENGTH(PIN) = 4
  • BREPEAT INPUT PIN UNTIL LENGTH(PIN) <> 4
  • CWHILE LENGTH(PIN) = 4 INPUT PIN ENDWHILE
  • DFOR Count ← 1 TO 4 INPUT PIN NEXT Count
Q51 mark

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
Q61 mark

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
Q1: A

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.

Q2: A

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.

Q3: A

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.

Q4: A

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.

Q5: A

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.

Q6: A

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.

Lab and demo

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

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.

Also for this topic

Everything else you can use

Original work by the TheLucidSTEM team. The worksheet items are written in the style of the papers; no past paper question is reproduced.
Previous lessonAbstraction and decomposition