HIGHER CS STANDARD ALGORITHMSPart 2- Techniques to help with learning about standard algorithms
Session Overview
• Visualising hidden mechanisms- Limitations of visualisation only- Weaknesses of existing methods for visualising
hidden mechanisms- Introduction to the mechanism visualiser
Visualising the hidden mechanisms
Is showing them in action enough?
Getting students to create a visualisation instead• Current methods and their limitations• Introduction to the mechanism visualiser
- Short demonstration- Tracing through a small linear search
Is showing them in action enough?
• Pupils need to build a causal model
• Watching a process helps but it’s not enough
• Too much work for the eyes and not enough work for the brain
What current methods do you use?
• Drawing a flowchart from a piece of code
• Drawing a structure diagram from a piece of code
• Tracing through a piece of code with a trace table
• Asking pupils to predict what will happen next
• Getting pupils to evaluate expressions
Limitations
Flow of Control
• Flowcharts• Predict
what happens next
Data Flow
• Expressions
• Trace Tables
Block Structure
• Structure Diagram
All of them develop understanding of part of the mechanismsSome involve having to learn another notation
MECHANISM VISUALISER EXAMPLE
Variables Table
SET total TO 0
RECEIVE nextInput FROM (INTEGER) KEYBOARD
WHILE nextInput != -1 DO
SET total TO total + nextInput
RECEIVE nextInput FROM (INTEGER) KEYBOARD
END WHILE
SEND total TO DISPLAY
Step 1- Draw a red rectangle around all expressions
Expression evaluator
SET total TO 0
RECEIVE nextInput FROM (INTEGER) KEYBOARD
WHILE nextInput != -1 DO
SET total TO total + nextInput
RECEIVE nextInput FROM (INTEGER) KEYBOARD
END WHILE
SEND total TO DISPLAY
Step 1- Draw a rectangle around all expressions Variables Table
Expression evaluator
SET total TO 0
RECEIVE nextInput FROM (INTEGER) KEYBOARD
WHILE nextInput != -1 DO
SET total TO total + nextInput
RECEIVE nextInput FROM (INTEGER) KEYBOARD
END WHILE
SEND total TO DISPLAY
Variables Table
Expression evaluator
Step 2- Draw in the flow of control as arrows
SET total TO 0
RECEIVE nextInput FROM (INTEGER) KEYBOARD
WHILE nextInput != -1 DO
SET total TO total + nextInput
RECEIVE nextInput FROM (INTEGER) KEYBOARD
END WHILE
SEND total TO DISPLAY
Step 2- Draw in the flow of control as arrows
T
F
Variables Table
Expression evaluator
SET total TO 0
RECEIVE nextInput FROM (INTEGER) KEYBOARD
WHILE nextInput != -1 DO
SET total TO total + nextInput
RECEIVE nextInput FROM (INTEGER) KEYBOARD
END WHILE
SEND total TO DISPLAY
Step 3- Hand execute the program with inputs 20, 7, -1
T
F
Variables Table
Expression evaluator
Total
1. 0
Variables Table
SET total TO 0
RECEIVE nextInput FROM (INTEGER) KEYBOARD
WHILE nextInput != -1 DO
SET total TO total + nextInput
RECEIVE nextInput FROM (INTEGER) KEYBOARD
END WHILE
SEND total TO DISPLAY
Step 3- Hand execute the program with inputs 20, 7, -1
T
F
1
Expression evaluator
Total nextInput
1. 0 2. 20
Variables Table
SET total TO 0
RECEIVE nextInput FROM (INTEGER) KEYBOARD
WHILE nextInput != -1 DO
SET total TO total + nextInput
RECEIVE nextInput FROM (INTEGER) KEYBOARD
END WHILE
SEND total TO DISPLAY
Step 3- Hand execute the program with inputs 20, 7, -1
T
F
1.
2.
Expression evaluator
Total nextInput
1. 0 2. 20
Variables Table
SET total TO 0
RECEIVE nextInput FROM (INTEGER) KEYBOARD
WHILE nextInput != -1 DO
SET total TO total + nextInput
RECEIVE nextInput FROM (INTEGER) KEYBOARD
END WHILE
SEND total TO DISPLAY
Step 3- Hand execute the program with inputs 20, 7, -1
T
F
1.
2.
3.3. nextInput !- -1
20 != -1True
Expression evaluator
(3)
Total nextInput
1. 0 2. 20
4. 20
3. nextInput !- -120 != -1True
4. total + nextInput0 + 2020
Variables Table
Expression evaluator
SET total TO 0
RECEIVE nextInput FROM (INTEGER) KEYBOARD
WHILE nextInput != -1 DO
SET total TO total + nextInput
RECEIVE nextInput FROM (INTEGER) KEYBOARD
END WHILE
SEND total TO DISPLAY
Step 3- Hand execute the program with inputs 20, 7, -1
T
F
1.
2.
3.
4.
(3)(4)
Total nextInput
1. 0 2. 20
4. 20 5. 7
3. nextInput !- -120 != -1True
4. total + nextInput0 + 2020
Variables Table
Expression evaluator
SET total TO 0
RECEIVE nextInput FROM (INTEGER) KEYBOARD
WHILE nextInput != -1 DO
SET total TO total + nextInput
RECEIVE nextInput FROM (INTEGER) KEYBOARD
END WHILE
SEND total TO DISPLAY
Step 3- Hand execute the program with inputs 20, 7, -1
T
F
1.
2.
3.
4.
5.
(3)(4) (4)
Total nextInput
1. 0 2. 20
4. 20 5. 7
3. nextInput !- -120 != -1True
4. total + nextInput0 + 2020
6. nextInput != -17 != -1True
Variables Table
Expression evaluator
SET total TO 0
RECEIVE nextInput FROM (INTEGER) KEYBOARD
WHILE nextInput != -1 DO
SET total TO total + nextInput
RECEIVE nextInput FROM (INTEGER) KEYBOARD
END WHILE
SEND total TO DISPLAY
Step 3- Hand execute the program with inputs 20, 7, -1
T
F
1.
2.
3.
4.
5.
6.
(3)(4)
(6)
(4)
Total nextInput
1. 0 2. 20
4. 20 5. 7
7. 27
3. nextInput !- -120 != -1True
4. total + nextInput0 + 2020
6. nextInput != -17 != -1True
7. total + nextInput20 + 727
Variables Table
Expression evaluator
SET total TO 0
RECEIVE nextInput FROM (INTEGER) KEYBOARD
WHILE nextInput != -1 DO
SET total TO total + nextInput
RECEIVE nextInput FROM (INTEGER) KEYBOARD
END WHILE
SEND total TO DISPLAY
Step 3- Hand execute the program with inputs 20, 7, -1
T
F
1.
2.
3.
4. 7.
5.
6.
(3)(4)
(6)(7)
(4)
(7)
total nextInput
1. 0 2. 20
4. 20 5. 7
7. 27 8. -1
3. nextInput !- -120 != -1True
4. total + nextInput0 + 2020
6. nextInput != -17 != -1True
7. total + nextInput20 + 727
Variables Table
Expression evaluator
SET total TO 0
RECEIVE nextInput FROM (INTEGER) KEYBOARD
WHILE nextInput != -1 DO
SET total TO total + nextInput
RECEIVE nextInput FROM (INTEGER) KEYBOARD
END WHILE
SEND total TO DISPLAY
Step 3- Hand execute the program with inputs 20, 7, -1
T
F
1.
2.
3.
4. 7.
5. 8.
6.
(3)(4)
(6)(7)
(4)
(7)
total nextInput
1. 0 2. 20
4. 20 5. 7
7. 27 8. -1
3. nextInput !- -120 != -1True
4. total + nextInput0 + 2020
6. nextInput != -17 != -1True
7. total + nextInput20 + 727
9. nextInput != -1-1 != -1False
Variables Table
Expression evaluator
SET total TO 0
RECEIVE nextInput FROM (INTEGER) KEYBOARD
WHILE nextInput != -1 DO
SET total TO total + nextInput
RECEIVE nextInput FROM (INTEGER) KEYBOARD
END WHILE
SEND total TO DISPLAY
Step 3- Hand execute the program with inputs 20, 7, -1
T
F
1.
2.
3.
4. 7.
5. 8.
6. 9.
(3)(4)
(6)(7)
(4)
(7)
(9)
total nextInput
1. 0 2. 20
4. 20 5. 7
7. 27 8. -1
3. nextInput !- -120 != -1True
4. total + nextInput0 + 2020
6. nextInput != -17 != -1True
7. total + nextInput20 + 727
9. nextInput != -1-1 != -1False
Variables Table
Expression evaluator
SET total TO 0
RECEIVE nextInput FROM (INTEGER) KEYBOARD
WHILE nextInput != -1 DO
SET total TO total + nextInput
RECEIVE nextInput FROM (INTEGER) KEYBOARD
END WHILE
SEND total TO DISPLAY
Step 3- Hand execute the program with inputs 20, 7, -1
T
F
1.
2.
3.
4. 7.
5. 8.
6. 9.
(3)(4)
(6)(7)
(4)
(7)
(9)
10.
In Pairs• Identify all of the expressions by
drawing a box around them• Identify the control flow by drawing
arrows showing what the next instruction will be
• Hand execute the program making sure to evaluate complicated expressions and create and update variables
SET found TO FALSE
SET numList TO [8,9,13,4]
RECEIVE searchKey FROM (INTEGER) KEYBOARD
SET pos TO 0
WHILE found TRUE AND pos < length (numList) DO
IF numList [ pos ] = searchKey THEN
SET found TO TRUE
ELSE
SET pos TO pos + 1
END IF
END WHILE
Array
Variables Table
Expression evaluator
Hand execute program with 13 as input for searchKey
SET found TO FALSE
SET numList TO [8,9,13,4]
RECEIVE searchKey FROM (INTEGER) KEYBOARD
SET pos TO 0
WHILE found TRUE AND pos < length (numList) DO
IF numList [ pos ] = searchKey THEN
SET found TO TRUE
ELSE
SET pos TO pos + 1
END IF
END WHILE
Step 1 and 2 Complete
FT
FT
Array
Variables Table
Expression evaluator
F
T 13.
T
found searchKey pos
1.FALSE (5) 3. 13 (6)(9)(12) 4. 0 (5) (6)
13.TRUE (14)
Array 2. numList
[0] [1] [2] [3]
8 (6) 9 (9) 13 (12) 4
Variables Table
SET found TO FALSE
SET numList TO [8,9,13,4]
RECEIVE searchKey FROM (INTEGER) KEYBOARD
SET pos TO 0
WHILE found TRUE AND pos < length (numList) DO
IF numList [ pos ] = searchKey THEN
SET found TO TRUE
ELSE
SET pos TO pos + 1
END IF
END WHILE
6 numList[ pos ] = searchKeynumList[ 0 ] = 138 = 13False
9 numList[ pos ] = searchKeynumList[ 1 ] = 139 = 13False
12 numList[ pos ] = searchKeynumList[ 2 ] = 1313 = 13True
Expression evaluator
Step 3 Complete-
F
Hand execute program with 13 as input for searchKey
1.
2.
3.
4.
5.
6. 9. 12.
7. 10..
8.11.14..
15.
Recommended