Dry run of an algorithm

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Dry run of an algorithm

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What is a dry run of an algorithm?
A Running the program on a computer to see if it crashes
B Working through the algorithm by hand, step by step, with chosen input values
2. Which one is true about the order you follow in a dry run?
A Follow the lines in order, one at a time, as the computer would
B Jump to the lines that look most important first
3. What do you use as the inputs when you dry run an algorithm?
A Chosen test data, such as normal, abnormal, extreme or boundary values
B Random values you make up after finishing the trace
4. Where do you record the changing values of variables during a dry run?
A In a trace table, with a column for each variable and for OUTPUT
B In a flowchart, with a shape for each variable
5. What is a main purpose of a dry run?
A To make the program run faster on a computer
B To find logic errors in an algorithm without running it

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1dry run AThe steps of a dry run should be recorded in a trace table, so that each variable value and OUTPUT is written down and can be checked
2Total ← 0 FOR Count ← 1 TO 3 Total ← Total + Count NEXT Count BAverage ← Total * Count
3A dry run uses chosen test data as the inputs, so you pretend the user typed these values in CA short algorithm you can dry run: Total goes 0, 1, 3, 6 as you follow each line in order and record the values
4A dry run can find a logic error, because the values you record show the algorithm giving a wrong result DINPUT Number // test data: 7
5Dry run: skip the loop lines and just write down the final OUTPUT EA dry run must follow every line in order, so skipping the loop lines means that you miss the changing values and any errors
6Dry run: record the values in your head and do not use a trace table FWorking through an algorithm by hand, line by line, with chosen input values, to see what it does without running it on a computer

Definitions

dry run

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
// A _______ is done by hand
2.
Num ← 5 Num ← Num _ 2 OUTPUT Num
3.
IF Mark >= 50 THEN OUTPUT "Pass" _____
4.
FOR Count ← 1 TO 3 OUTPUT Count ____ Count
5.
OUTPUT "Enter a number" _____ Num OUTPUT Num * 2

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A Total ← 0
B FOR Count ← 1 UNTIL 3
C Total ← Total + Count
D NEXT Count
E OUTPUT Total
Question 2
A OUTPUT Temp
B IF Temp > 30 THEN
C OUTPUT "Hot"
D ELSE
E OUTPUT "Mild"
F ENDIF
Question 3
A Count ← 0
B WHILE Count < 3 DO
C Count ← Count - 1
D ENDWHILE
E OUTPUT Count
Question 4
A Total ← 80 + 60
B Count ← 2
C Average ← Total * Count
D OUTPUT Average
Question 5
A Mark ← 50 // 50 or more passes
B IF Mark > 50 THEN
C OUTPUT "Pass"
D ELSE
E OUTPUT "Fail"
F ENDIF

Answer Key

Dry run of an algorithm
Section A: Quick Questions
Q1
B — Working through the algorithm by hand, step by step, with chosen input values
Q2
A — Follow the lines in order, one at a time, as the computer would
Q3
A — Chosen test data, such as normal, abnormal, extreme or boundary values
Q4
A — In a trace table, with a column for each variable and for OUTPUT
Q5
B — To find logic errors in an algorithm without running it
Section B: Match the Pairs
Q1
dry run → Working through an algorithm by hand, line by line, with chosen input values, to see what it does without running it on a computer
Q2
Total ← 0 FOR Count ← 1 TO 3 Total ← Total + Count NEXT Count → A short algorithm you can dry run: Total goes 0, 1, 3, 6 as you follow each line in order and record the values
Q3
A dry run uses chosen test data as the inputs, so you pretend the user typed these values in → INPUT Number // test data: 7
Q4
A dry run can find a logic error, because the values you record show the algorithm giving a wrong result → Average ← Total * Count
Q5
Dry run: skip the loop lines and just write down the final OUTPUT → A dry run must follow every line in order, so skipping the loop lines means that you miss the changing values and any errors
Q6
Dry run: record the values in your head and do not use a trace table → The steps of a dry run should be recorded in a trace table, so that each variable value and OUTPUT is written down and can be checked
Section C: Definitions
Q1
dry run — Working through an algorithm by hand, line by line, using chosen test data as inputs and recording each step in a trace table, to see what it does and find logic errors without running it.
Section D: Fill in the Blanks
Q1
// A dry run is done by hand
Q2
Num ← 5 Num ← Num * 2 OUTPUT Num
Q3
IF Mark >= 50 THEN OUTPUT "Pass" ENDIF
Q4
FOR Count ← 1 TO 3 OUTPUT Count NEXT Count
Q5
OUTPUT "Enter a number" INPUT Num OUTPUT Num * 2
Section E: Spot the Error
Q1
B — A FOR loop needs the keyword TO between the start and end values, so you cannot dry run this line. UNTIL belongs to REPEAT ... UNTIL. It should be FOR Count ← 1 TO 3.
Q2
A — When you dry run with a test value such as 35, the algorithm must take that value as input. OUTPUT Temp never stores a value in Temp, so the IF has nothing to test. It should be INPUT Temp.
Q3
C — A dry run shows Count going 0, -1, -2 and so on, so Count < 3 is always true and the loop never ends. The line should add 1: Count ← Count + 1.
Q4
C — A dry run gives 280 here, but the average of 80 and 60 is 70. The total must be divided by the count, not multiplied. It should be Average ← Total / Count.
Q5
B — Dry run with the boundary value 50. The test > 50 is false, so the output is Fail, but the comment says 50 passes. The condition should be IF Mark >= 50 THEN.