All subjects · Computer Science · WCP03 Advanced Principles of Computer Science

Problem-solving techniques and trace tables

Edexcel IAL Computer Science · WCP03 Advanced Principles of Computer Science

Before coding, choose a strategy. Unit 3 names six techniques: brute force, divide and conquer, greedy, heuristics, backtracking and recursion, plus tracing algorithms in trace tables.

Practise this in the app: instant marking and a fix for every mistake. Free, no email needed to start.

Practise this lesson

Brute force and divide and conquer

Greedy and heuristics

Backtracking and recursion

def fact(n):
    if n <= 1:          # base case
        return 1
    return n * fact(n - 1)

Trace tables

A trace table records the value of each variable (and any output) as an algorithm runs, one row per change. It is used to find logic errors and to work out what an algorithm does.

total = 0
for i in range(1, 5):
    if i % 2 == 0:
        total = total + i
print(total)
ii % 2 == 0?totaloutput
0
1False0
2True2
3False2
4True6
6

Worked example

Use the greedy method to make 88p from UK coins (50, 20, 10, 5, 2, 1).

  1. Take the largest coin that fits each time: 50 (38 left), 20 (18 left), 10 (8 left), 5 (3 left), 2 (1 left), 1 (0 left).

Answer: 50 + 20 + 10 + 5 + 2 + 1: 6 coins

Key idea: Brute force: try everything. Divide and conquer: split, solve, combine. Greedy: best choice now. Heuristic: good-enough rule of thumb. Backtracking: undo dead ends. Recursion: self-call with a base case. Trace tables: record every change.

Check yourself

  1. Which algorithm is an example of divide and conquer?
    • Merge sort
    • Linear search
    • Bubble sort
    • Greedy coin change
    Show answer

    Merge sort. Merge sort splits the list, sorts the halves and merges them.

  2. Using the greedy method with UK coins (50, 20, 10, 5, 2, 1), how many coins are needed for 67p?
    Show answer

    4. 50 + 10 + 5 + 2.

  3. With coins of 1, 3 and 4 only, how many coins does the greedy method use to make 6?
    Show answer

    3. 4 + 1 + 1 = three coins (the optimum is 3 + 3, two coins).

  4. A brute force attack tries every 3-character code made of the letters A to Z. How many codes are there?
    Show answer

    17576. 26 x 26 x 26 = 17 576.

  5. Using the recursive fact function, what is fact(5)?
    Show answer

    120. 5 x 4 x 3 x 2 x 1 = 120.

  6. Which technique gives a good, but not necessarily optimal, answer quickly to a problem that is too slow to solve exactly?
    • Brute force
    • Recursion without a base case
    • A trace table
    • A heuristic
    Show answer

    A heuristic. Heuristics trade guaranteed optimality for speed on intractable problems.

  7. What does backtracking do when a partial solution breaks the rules?
    • Starts again from the very beginning with random choices
    • Undoes the most recent choice and tries the next option
    • Accepts the solution anyway
    • Sorts the data first
    Show answer

    Undoes the most recent choice and tries the next option. Abandoning dead ends early saves time.

  8. total = 0; for i in range(1, 6): if i % 2 == 1: total = total + i. What is total at the end?
    Show answer

    9. Odd values 1, 3, 5 are added: 9.

Practise with instant feedback

Sources

Last updated 8 November 2026. Spotted a mistake? Tell us.