Year 11 · Computer Science · Spring 1
Paper 2 practice: algorithms, programming, logic, databases · Lesson 1 of 5
Trace tables and error finding
Exam practice7.7 Trace tables7.8 Finding and fixing errors
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 1 of 5
You will learn to
- Complete a trace table for an algorithm with a loop and selection.
- Use a trace table to find the output of an algorithm.
- Identify the errors in a given algorithm, stating the line number of each.
- Write a correct replacement line for each error.
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 1 of 5
Success criteria
You have got it when you can say:
- I can fill a trace table with every variable change, one row at a time.
- I can give the exact output of the algorithm.
- I can find each error, give its line number and write the corrected line.
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 1 of 5
Retrieval starter
Questions from before. Write your answers, then show them.
- Last unit
The register that holds the address of the next instruction is the…
A Accumulator (ACC)B Memory address register (MAR)C Program counter (PC)
C. Program counter (PC)
- Last unit
Machine learning means…
A A programmer types every ruleB The system changes its own rules from dataC A robot with wheels
B. The system changes its own rules from data
- Earlier this year
Pharming is…
A Being sent to a fake website even when you type the right addressB A fake email asking for a passwordC Guessing every password
A. Being sent to a fake website even when you type the right address
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 1 of 5
Key words (1 of 2)
- Algorithm
- A precise, ordered set of steps that solves a problem.
- Program development life cycle
- The four stages of making a program: analysis, design, coding and testing.
- Pseudocode
- A structured, code-like way of writing an algorithm that is not tied to one language.
- Counting
- Adding 1 to a counter each time something happens.
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 1 of 5
Key words (2 of 2)
- Check digit
- An extra digit calculated from the other digits, used to catch typing errors.
- Trace table
- A table used in a dry run to record the value of each variable as an algorithm runs.
7.7 Trace tables · The explanation · step 1 of 5 · part 1 of 2
What a trace table is
A dry run means working through an algorithm by hand, line by line, without a computer.
A trace table records the dry run. It has one column for each variable, and one for the output.
Write a new value in a column only when that variable changes. Move to a new row when the loop goes round again.
A dry run lets you check an algorithm before it is coded. It also shows exactly where a logic error happens.
7.7 Trace tables · The explanation · step 1 of 5 · part 2 of 2
What a trace table is (continued)
Do not fill every cell. Cambridge mark schemes usually want a value only where it changes. Copying values down is not wrong but takes time and causes mistakes.
7.7 Trace tables · The explanation · step 2 of 5 · part 1 of 6
Worked dry run
This algorithm reads numbers until the user types -1. A value that only means 'stop' is called a rogue value.
Input data: 12, 7, 20, 9, -1. Follow each row of the table below and check you agree.
Then use the toy. Pick Counting (WHILE), a similar rogue-value loop, and press Step to run it one line at a time.
7.7 Trace tables · The explanation · step 2 of 5 · part 2 of 6
Worked dry run (continued)
| Value | Total | Count | Highest | OUTPUT |
|---|---|---|---|---|
| 0 | 0 | 0 | ||
| 12 | 12 | 1 | 12 | |
| 7 | 19 | 2 | ||
| 20 | 39 | 3 | 20 | |
| 9 | 48 | 4 | ||
| -1 | 12 20 |
7.7 Trace tables · The explanation · step 2 of 5 · part 3 of 6
Worked dry run (continued)
7.7 Trace tables · The explanation · step 2 of 5 · part 4 of 6
Worked dry run (continued)
DECLARE Value : INTEGER
DECLARE Total : INTEGER
DECLARE Count : INTEGER
DECLARE Highest : INTEGER
Total ← 0
Count ← 0
Highest ← 0
INPUT Value
WHILE Value <> -1 DO
Total ← Total + Value
Count ← Count + 1
IF Value > Highest
THEN
Highest ← Value
ENDIF
INPUT Value
ENDWHILE
OUTPUT Total / Count, " ", Highest7.7 Trace tables · The explanation · step 2 of 5 · part 5 of 6
Worked dry run (continued)
total = 0
count = 0
highest = 0
value = int(input())
while value != -1:
total = total + value
count = count + 1
if value > highest:
highest = value
value = int(input())
print(total / count, highest)7.7 Trace tables · The explanation · step 2 of 5 · part 6 of 6
Worked dry run (continued)
The rogue value -1 is not added to the total. The loop checks the value before using it. That is why there is an `INPUT` before the loop and another at the end of it.
There is something to try for this step in the IGCSE library.
7.8 Finding and fixing errors · The explanation · step 3 of 5 · part 1 of 2
Two kinds of error
A syntax error breaks the rules of the language, like a spelling mistake in a keyword. The program will not run.
A logic error means the program runs but gives the wrong answer. Examples: `<` instead of `>`, or a total that starts at 1.
Exam questions mostly test logic errors. Trace tables and test data are how you find them.
7.8 Finding and fixing errors · The explanation · step 3 of 5 · part 2 of 2
Two kinds of error (continued)
| Error | Example | What happens |
|---|---|---|
| Syntax | `OUTPT Total` | Translator reports an error; program does not run |
| Logic | `Count ← 1` instead of `0` | Runs, but the count is 1 too high |
| Logic | `FOR Index ← 1 TO 9` for 10 items | Runs, but misses the last item |
A translator finds syntax errors for you. Nothing finds logic errors automatically, so you need to think and test.
The explanation · 2 more steps
More on the lesson page
The lesson page has the rest of the explanation, step by step:
- Worked example: find four errors
- The corrected algorithm
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 1 of 5
Quick quiz · 1 of 3
The four stages of the program development life cycle are…
- A Input, process, output, storage
- B Fetch, decode, execute, store
- C Analysis, design, coding, testing
C. Analysis, design, coding, testing
Analyse the problem, design the solution, write the code, test it.
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 1 of 5
Quick quiz · 2 of 3
Abnormal test data is…
- A Data that should be rejected
- B Data at the edge of the range
- C Typical data
A. Data that should be rejected
Normal works, abnormal is rejected, extreme sits on the edge, boundary is either side of it.
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 1 of 5
Quick quiz · 3 of 3
A range check on age 0 to 120 would reject…
- A 0
- B 150
- C 120
B. 150
0 and 120 are the edges and are allowed. 150 is outside.
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 1 of 5
Exit ticket
Answer on paper before you go. Then check.
Typing an email address twice to check it is…
A A trace tableB VerificationC Validation
B. Verification Validation checks the data is sensible; verification checks it was entered as intended.
In a trace table you write a new row…
A Each time a value changesB Only for OUTPUTC Only at the end
A. Each time a value changes One column per variable, one row per change.