Computer science · Grades 6–10
Algorithm tracing and useful tests
These examples use plain pseudocode; inclusive bounds are stated explicitly.
Understand the idea
Specify the rule
These examples use plain pseudocode; inclusive bounds are stated explicitly.
Trace state
Keep a record of variable values after each instruction.
Test boundaries
Try typical inputs and values at the limits of the rule.
Worked examples
Pseudocode: x ← 4; x ← x + 3; x ← 2 × x. What is x at the end?
4 becomes 7, then 14.
14
Pseudocode: total ← 0; add 2, then 5, then 1 to total. Find the final total.
0 + 2 + 5 + 1 = 8.
8
Try it yourself
A rule admits ages 12 or above. Which boundary pair is especially useful to test?
- 100 and 200
- 40 and 50
- 20 and 30
- 11 and 12
What is an off-by-one error in a loop?
FOR i FROM 1 TO 4 INCLUSIVE: total ← total + i, starting total = 0. Find total.
Which test is best for a function meant to return the larger of two numbers?
- Only a screenshot of the code
- Different orders, equal values and relevant boundary values
- Only the function's name
- Only one pair with the larger number first
Answers and marking notes
Answers and marking notes
- 11 and 12
The pair straddles the decision threshold.
- A boundary or count is one too high or low, causing an extra or missing iteration or wrong index.
Credit a correct boundary example.
- 10
1 + 2 + 3 + 4 = 10.
- Different orders, equal values and relevant boundary values
Varying cases can reveal assumptions and edge errors.
Preview material · independent educational review required. Grade bands are approximate, not official curriculum alignment.