StudyBrixFree worksheets, study guides and courses

Computer science · Grades 6–10

Algorithm tracing and useful tests

These examples use plain pseudocode; inclusive bounds are stated explicitly.

Make a worksheet

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

  1. A rule admits ages 12 or above. Which boundary pair is especially useful to test?

    1. 100 and 200
    2. 40 and 50
    3. 20 and 30
    4. 11 and 12
  2. What is an off-by-one error in a loop?

  3. FOR i FROM 1 TO 4 INCLUSIVE: total ← total + i, starting total = 0. Find total.

  4. Which test is best for a function meant to return the larger of two numbers?

    1. Only a screenshot of the code
    2. Different orders, equal values and relevant boundary values
    3. Only the function's name
    4. Only one pair with the larger number first

Answers and marking notes

Answers and marking notes
  1. 11 and 12

    The pair straddles the decision threshold.

  2. A boundary or count is one too high or low, causing an extra or missing iteration or wrong index.

    Credit a correct boundary example.

  3. 10

    1 + 2 + 3 + 4 = 10.

  4. 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.