12 Trace - Iteration
12 Trace - Iteration
3 CPU Performance
& Assessment
Lesson intention:
• Preform an algorithm trace and use flowgorithm as a problem solving tool and
IT
repeat instructions (iteration) 6 Produce & Navigate
Representation
Grade Descriptors:
2-3 I know what an algorithm is and I can express simple algorithms using symbols.
2-3 I know that computers need precise instructions.
2-3 I can show care and precision to avoid errors 9 Secret code & Assessment
3-4 I know that algorithms are implemented on digital devices as programs.
3-4 I can design simple algorithms using loops, and selection i.e. if statements.
3-4 I can use logical reasoning to predict outcomes. 10 Flowcharts & Pseudocode
3-4 I can find and correct errors i.e. debugging, in algorithms.
4-5 I can design solutions (algorithms) that use repetition and two-way selection i.e. if, then and else. 11 Algorithms - Making
Algorithms
4-5 I can use flowcharts to express solutions. Decisions
4-5 I can use logical reasoning to predict outputs, showing an awareness of inputs.
5-6 I can design solutions by decomposing a problem and creates a sub-solution for each of these parts (decomposition). 12 Trace & Iteration
5-6 I know that different solutions exist for the same problem.
6-7 I know that iteration is the repetition of a process such as a loop. 13 Flowgorithm & Assessment
6-7 I know that different algorithms exist for the same problem.
6-7 I can represent solutions using pseudocode
6-7 I can identify similarities and differences in situations and can use these to solve problems (pattern recognition). 14 Sequencing, Variables &
7-8 I know a recursive solution to a problem repeatedly applies the same solution. Compatibility
7-8 I know the notion of performance for algorithms and I know that some algorithms have different performance characteristics for the same task.
8-9 I know that the design of an algorithm is distinct from its expression in a programming language.
ting a lgorithms is a
es
Do you think that t time?
waste of
What is re
petition?
What is an algorithm trace?
w c h a r t s a nd
Wh a t d o f lo
i n c o m m o n?
o de h a v e
What is differe pseudoc
nt about the
decision symb
ol?
is a fo r l o o p?
What
Lesson intention: Preform an algorithm trace and use flowgorithm as a problem solving tool and repeat instructions (iteration) 2
Flo the hedgehog likes to play a game with her friend Sue.
You may have played this game yourself. This is how it goes:
• Flo thinks of a number between 1 and 100.
• Sue then tries to guess what the number is.
• If Sue’s guess is too low, then Flo will answer: “too low, guess again”.
(No surprises there!)
• If Sue’s guess is too high, then Flo will answer: “too high, guess again”.
• If Sue’s guess is correct, then Flo will answer: “that’s right!”
• Then Sue thinks of a number between 1 and 100 and Flo has to guess.
Is it 50?
Is it 75?
Is it 63?
Lesson intention: Preform an algorithm trace and use flowgorithm as a problem solving tool and repeat instructions (iteration)
Answer
Here’s a better answer. Why is this a better flowchart?
Start
Yes
Is guess too low? Too low – try again.
No
Yes
Is guess too high? Too high – try again.
No
That’s right!
Stop
Algorithm Tracing
Sometimes it’s useful to do an Algorithm Trace. This means stepping through the
algorithm (in this case our flowchart) one step at a time.
Let’s imagine that Person 1 picks the number 26….
Start
Start
Start
Yes
Is guess too low? Too low – try again.
No
Algorithm Tracing
Person 2 now makes a guess of 34.
34 is higher than 26 so this time the result is ‘Too high – try again.’
Start
Yes
Is guess too low?
Yes
Is guess too high? Too high – try again.
Algorithm Tracing
Finally, Person 2 gets lucky and guesses 26.
26 is not lower or higher than 26 so the result is ‘That’s right!’ and the game
is over.
Start
Yes
Is guess too low?
No
Yes
Is guess too high? Too high – try again.
No
That’s right!
Stop
Inputs and Outputs
We can improve our flowchart even further by using inputs and outputs.
Keywords
An input is information (data) that we put into an algorithm.
An output is information that we get out of the algorithm.
This shape is a
Input / Output parallelogram.
Inputs and Outputs
Let’s add these input and output boxes to
Start our High-Low Hedgehog flowchart:
Yes
Is guess too low? Too low – try again.
No
Yes
Is guess too high? Too high – try again.
No
That’s right!
This doesn’t look
much different!
Stop
Flowgorithm
• Time to put our skills and knowledge into action.
Click on OK.
Flowgorithm
Step seven:
Finally …
Double-click on the If box:
Then in the
If Properties window type:
age > 18
Click OK.
Add a screenshot of your flowchart here.
Lesson intention: Preform an algorithm trace and use flowgorithm as a problem solving tool and repeat instructions (iteration)
Source Code
Lesson intention: Preform an algorithm trace and use flowgorithm as a problem solving tool and repeat instructions (iteration)
Testing Flowcharts
Lesson intention: Preform an algorithm trace and use flowgorithm as a problem solving tool and repeat instructions (iteration)
Flo needs your help once again!
Keywords
An input is information (data) that we put into an algorithm.
An output is information that we get out of the algorithm.
Verse 1
Lesson intention: Preform an algorithm trace and use flowgorithm as a problem solving tool and repeat instructions (iteration)
Iteration
Click OK.
Iteration
Click OK.
Iteration
FOR counter = 1 TO 2
OUTPUT “Lights are red ..”
END FOR
FOR counter = 1 TO 2
OUTPUT “Lights are red, amber ..."
END FOR
OUTPUT “Those cars they come at such ..."
FOR counter = 1 TO 2
OUTPUT "Look left, look right ..."
END FOR
FOR counter = 1 TO 2
OUTPUT " Lights are red, amber ..."
END FOR
FOR counter = 1 TO 4
OUTPUT "Look left, look right ..."
END FOR
Let’s Bring It All Together
Key Term
Iteration is the process of repeating one or more instructions over
and over again.
Key Term
A For loop is used to iterate one or more instructions for a
fixed or known number of times.