# HIGHER CS STANDARD ALGORITHMS Part 2- Techniques to help with learning about standard algorithms.

## Presentation on theme: "HIGHER CS STANDARD ALGORITHMS Part 2- Techniques to help with learning about standard algorithms."— Presentation transcript:

HIGHER CS STANDARD ALGORITHMS Part 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 mechanisms Some 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

TotalnextInput 1. 02. 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

TotalnextInput 1. 02. 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. nextInput !- -1 20 != -1 True Expression evaluator (3)

TotalnextInput 1. 02. 20 4. 20 3.nextInput !- -1 20 != -1 True 4.total + nextInput 0 + 20 20 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)

TotalnextInput 1. 02. 20 4. 205. 7 3.nextInput !- -1 20 != -1 True 4.total + nextInput 0 + 20 20 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)

TotalnextInput 1. 02. 20 4. 205. 7 3.nextInput !- -1 20 != -1 True 4.total + nextInput 0 + 20 20 6.nextInput != -1 7 != -1 True 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)

TotalnextInput 1. 02. 20 4. 205. 7 7. 27 3.nextInput !- -1 20 != -1 True 4.total + nextInput 0 + 20 20 6.nextInput != -1 7 != -1 True 7.total + nextInput 20 + 7 27 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)

totalnextInput 1. 02. 20 4. 205. 7 7. 278. -1 3.nextInput !- -1 20 != -1 True 4.total + nextInput 0 + 20 20 6.nextInput != -1 7 != -1 True 7.total + nextInput 20 + 7 27 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)

totalnextInput 1. 02. 20 4. 205. 7 7. 278. -1 3.nextInput !- -1 20 != -1 True 4.total + nextInput 0 + 20 20 6.nextInput != -1 7 != -1 True 7.total + nextInput 20 + 7 27 9.nextInput != -1 -1 != -1 False 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)

totalnextInput 1. 02. 20 4. 205. 7 7. 278. -1 3.nextInput !- -1 20 != -1 True 4.total + nextInput 0 + 20 20 6.nextInput != -1 7 != -1 True 7.total + nextInput 20 + 7 27 9.nextInput != -1 -1 != -1 False 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 F T F T Array Variables Table Expression evaluator

F T 13. T foundsearchKeypos 1.FALSE (5)3. 13 (6)(9)(12)4. 0 (5) (6) 13.TRUE (14) Array2. 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 6numList[ pos ] = searchKey numList[ 0 ] = 13 8 = 13 False 9numList[ pos ] = searchKey numList[ 1 ] = 13 9 = 13 False 12numList[ pos ] = searchKey numList[ 2 ] = 13 13 = 13 True Expression evaluator Step 3 Complete- F Hand execute program with 13 as input for searchKey 1.1. 2. 3.3. 4. 5. 6. 9. 12. 7. 10.. 8.11.14.. 15.