GoalTurn a numbered algorithm into a flowchart, using loops and decisions where the steps ask for them.
New words
algorithm · a list of steps, in the right order, that solves a problemrepeat · to do a step or a group of steps againtrace · to follow a flowchart step by step, writing down what happens
Explanation
An algorithm can be written as a list of numbered steps. To turn the list into a flowchart, go through it one step at a time. Choose a shape for each step and draw it under the one before, with an arrow between them. When a step says ‘repeat’ or ‘go back to step 3’, draw an arrow that goes back up. When a step is a question, draw a diamond with a yes branch and a no branch. At the end check every shape. Each one needs an arrow going in and an arrow going out, except the start and the stop.
Worked examples
Step
Instruction
Shape
1
Start
oval
2
Take the bottle to the tap
parallelogram
3
Turn the tap on
rectangle
4
Is the bottle not full?
diamond
5
If yes, wait one second and go back to step 4
arrow back to the diamond
6
If no, turn the tap off
rectangle
7
Stop
oval
This is the algorithm that the flowchart above comes from. Look at how each numbered step became a shape. Step 5 sends the arrow back to step 4, so the question is asked again.
Kenji draws the algorithm for a library desk. The question ‘Is the book damaged?’ is a diamond with two branches. Both branches join again before the stop.
Here are mistakes to look for when you check a flowchart: a shape with no arrow leaving it, a diamond with only one branch, a loop arrow that points to the wrong step, and a step that sits in the wrong shape.
Class activity
Tidy-up flowchart (no computer): write the steps for ‘put the toys away until the floor is clear’ as a numbered list. Include the question ‘Are there toys on the floor?’. Draw it as a flowchart with arrows, and check that your loop arrow goes back to the question. Now follow your own flowchart in real life with a pencil as a marker: point to each shape as you do the job. If you have a computer or tablet, draw the same flowchart in a drawing program.
Practice
1
Turn this algorithm into a flowchart. 1 Start. 2 Go to the door. 3 Press the bell. 4 Has nobody opened the door? 5 If yes, wait ten seconds, press the bell and go back to step 4. 6 If no, say hello. 7 Stop.
Start (oval), go to the door (rectangle), press the bell (rectangle), diamond ‘Has nobody opened the door?’. The yes branch goes down to ‘wait ten seconds’ and ‘press the bell’, and then an arrow goes back to the diamond. The no branch goes on to ‘say hello’ (parallelogram) and then stop (oval).
2
What question must go in the diamond so that the pencil is sharpened until it is sharp?
‘Is the pencil still blunt?’ While the answer is yes the pencil is sharpened again. When the answer is no the loop ends and the name is written.
3
Write this flowchart as a numbered algorithm. What is shown when the price is 60? What is shown when the price is 20?
1 Start. 2 Type the price. 3 Is the price above 50? 4 If yes, subtract 5. 5 If no, subtract 1. 6 Show the new price. 7 Stop. For 60 it shows 55. For 20 it shows 19.
4
Mia draws a diamond with only one arrow, marked ‘yes’. What is missing, and why does it matter?
There is no ‘no’ branch. A decision needs two ways out, or nobody knows what happens when the answer is no.