GoalPredict the outcome of a flowchart by finding its type, inputs, processes and outputs and by tracing it with test values.
New words
predict · to say what will happen before it happenstrace · to follow a flowchart step by step with real valuestest value · an input chosen so that you can check what a flowchart does
Explanation
You can predict what a flowchart will do without a computer. First find its type: linear, with a loop or with a decision. Then list the inputs, the processes and the outputs. Count the decisions, because they tell you how many different outcomes there can be. Then choose test values and trace the flowchart with each one. Write down what changes at every step. Choose test values that send you down every path, including values that sit right on the edge of a question.
Worked examples
Age typed
Age below 12?
Shown
9
yes
child ticket
12
no
adult ticket
40
no
adult ticket
The ticket flowchart is a decision flowchart. Its input is the age, its process is the comparison with 12 and its outputs are the two messages. It has two outcomes. Here it is traced with three test values. Notice that 12 is not below 12.
Chen traces a flowchart with a loop. The coins start at 0. Each time round the loop adds 2 coins. The question is asked before every addition. The program stops when the answer is no and then shows the coins.
Coins now
Below 5?
What happens
0
yes
add 2, now 2
2
yes
add 2, now 4
4
yes
add 2, now 6
6
no
show 6
Chen’s trace table shows that the loop runs three times and the output is 6, not 5. The coins jump over 5, so the question is only answered no when they reach 6.
Class activity
Be the computer (no computer): ask a partner to write a flowchart on paper with one input, one decision and two outputs, for example ‘roll a die: is the number more than 3? yes: say Big, no: say Small’. Roll a real die six times. Each time, trace the flowchart with your finger and say the output out loud. Your partner checks you. Then swap jobs. Write down which test values you needed to visit both outputs. If you have a computer or tablet, you can use a die-rolling tool instead of a real die.
Practice
1
Say the type of this flowchart, its input and how many outcomes it has. What is shown for a mark of 10? What is shown for 9?
It is a flowchart with a decision. The input is the mark. It has two outcomes. For 10 it shows Pass, because 10 is 10 or more. For 9 it shows Try again.
2
What is shown at the end of this flowchart?
4. The stars go 10, then 7, then 4. At 4 the question ‘Are the stars above 4?’ is answered no, so the loop ends and 4 is shown.
3
The ticket flowchart shows Child ticket if the age is below 12. Which two test values would check both paths, and why is 12 a good extra test value?
For example 8 and 30. The value 12 is on the edge of the question and shows whether the comparison treats 12 as ‘below 12’. It does not, so 12 gets the adult ticket.
4
A flowchart takes a number, multiplies it by 3 and adds 1, then shows the result. Fill in the outputs.
Number typed
Shown
4
?
10
?
0
?
For 4: 4 × 3 + 1 = 13. For 10: 10 × 3 + 1 = 31. For 0: 0 × 3 + 1 = 1.