🔒
Pro Content
Subscribe to access all 69 OCR H446 A Level lessons.
£7.99/month
or £59/year
Subscribe now →
🔒 Pro · Component 2 · 2.2.1 Problem Solving & Programming
2.2.1d Computational Methods and Problem Classification
OCR H446 · A Level Computer Science · ~20 min read
Notes
Video
Slides
Worksheet
Quiz

Computational Methods Overview

Computational methods are systematic approaches to solving problems using algorithms. The four key methods on the H446 syllabus are: divide and conquer, dynamic programming, backtracking, and greedy algorithms. Each has specific characteristics, use cases, and trade-offs.

1. Divide and Conquer

Divide and conquer breaks a problem into smaller sub-problems of the same type, solves them recursively, then combines the results. The sub-problems are independent (no overlap).

Three steps: Divide (split the problem), Conquer (solve recursively — until base case), Combine (merge the solutions).

Example algorithmHow it uses divide and conquer
Merge SortDivide array in half, sort each half, merge the two sorted halves
Binary SearchDivide search space in half at each step; search the correct half
Quick SortPartition around a pivot; sort left/right partitions recursively

Time complexity

Divide and conquer algorithms often achieve O(n log n) time — the log n comes from halving the problem at each level (log n levels), with O(n) work per level. Binary search is O(log n) — no combining needed.

Exam tip: When answering "why is merge sort O(n log n)?", state: log n levels of recursion (each halving) × O(n) work to merge at each level = O(n log n) total.

2. Dynamic Programming (DP)

Dynamic programming solves problems with overlapping subproblems — it stores the results of subproblems to avoid recomputing them. Two key properties: optimal substructure (optimal solution built from optimal sub-solutions) and overlapping subproblems.

Two approaches:

  • Memoisation (top-down): recursive solution + a cache (dict/array) to store computed results. Computes only what's needed.
  • Tabulation (bottom-up): iterative — fills a table from smallest subproblems upward. No recursion overhead.
# Fibonacci WITHOUT DP — exponential time O(2^n)
def fib_slow(n):
    if n <= 1: return n
    return fib_slow(n-1) + fib_slow(n-2)  # Recomputes same values!

# Fibonacci WITH memoisation — O(n) time
memo = {}
def fib_memo(n):
    if n in memo: return memo[n]
    if n <= 1: return n
    memo[n] = fib_memo(n-1) + fib_memo(n-2)
    return memo[n]

# Fibonacci WITH tabulation — O(n) time, O(n) space
def fib_tab(n):
    if n <= 1: return n
    table = [0] * (n+1)
    table[1] = 1
    for i in range(2, n+1):
        table[i] = table[i-1] + table[i-2]
    return table[n]
Exam tip: The key word for DP is "overlapping subproblems" — if fib(5) calls fib(3) twice, those are overlapping. Divide and conquer sub-problems are INDEPENDENT; DP sub-problems OVERLAP. This is the critical distinction.

3. Backtracking

Backtracking is a brute-force exploration with pruning. It builds a solution incrementally, and abandons (backtracks) a partial solution as soon as it determines the solution cannot be completed. Used when the search space is large but many paths can be eliminated early.

How it works:

  • Choose: pick a candidate option at the current step
  • Check: test if the partial solution is still valid
  • Recurse: explore further from this state
  • Backtrack: if no valid options remain, undo the last choice and try the next

Examples: solving a maze (mark visited cells; backtrack at dead-ends), Sudoku solver (try digit 1–9 in empty cell; backtrack if contradiction), N-Queens problem (place queens on chessboard without attacking each other).

Pruning

Backtracking is more efficient than exhaustive brute force because it prunes the search tree — it never explores paths that are already invalid. However, worst-case complexity is still exponential in the worst case for NP-complete problems.

4. Greedy Algorithms

A greedy algorithm makes the locally optimal choice at each step, hoping to find a global optimum. It never revisits past choices. Greedy algorithms are fast but do not always find the globally optimal solution.

AlgorithmGreedy choiceOptimal?
Dijkstra's shortest pathAlways visit the unvisited node with smallest tentative distanceYes (non-negative weights)
Prim's / Kruskal's MSTAlways pick the cheapest edge that doesn't form a cycleYes
Coin change (standard denominations)Always pick the largest coin that fitsYes for UK coins; no for arbitrary denominations
Activity selectionAlways pick the activity with earliest finish timeYes
Exam tip: Greedy doesn't always work. With coins {1, 6, 10} and target 12: greedy picks 10, then 1+1 = 12 (3 coins). But optimal is 6+6 = 2 coins. Greedy fails here. This is why DP is needed for coin change with arbitrary denominations.

Problem Classification

Decidable and Undecidable Problems

A decidable problem is one for which an algorithm always terminates with a correct yes/no answer. An undecidable problem has no algorithm that can always correctly determine yes/no in finite time.

The classic undecidable problem is the Halting Problem (Turing, 1936): given any program and input, does it halt? It is mathematically impossible to write a general algorithm that correctly answers this for all programs. Turing proved this using proof by contradiction (assuming a halting detector exists leads to a logical paradox).

Tractable and Intractable Problems

TractableIntractable
DefinitionSolvable in polynomial time O(nᵏ) for some kNo known polynomial-time algorithm exists (worst-case exponential or worse)
Practical?Yes — feasible for large inputsOnly feasible for small inputs
ExamplesSorting (O(n log n)), BFS/DFS (O(V+E)), shortest pathTravelling Salesman, satisfiability (SAT), graph colouring

P vs NP (awareness)

Problems in class P can be solved in polynomial time. Problems in class NP can be verified in polynomial time (given a solution, we can check it quickly) but no polynomial-time solution algorithm is known. The question "Does P = NP?" is the greatest unsolved problem in computer science. Most computer scientists believe P ≠ NP but this is unproven. NP-complete problems are the hardest in NP — if any NP-complete problem is solved in polynomial time, ALL NP problems can be.

Computable and Non-computable Problems

A computable problem has an algorithm that will always produce the correct answer (even if it's slow). A non-computable problem has no algorithm — the Halting Problem is an example of a non-computable problem.

Exam tip: Know: Halting Problem = undecidable AND non-computable. Travelling Salesman = decidable AND intractable (no polynomial algorithm known, but we can answer "is there a tour of cost ≤ k?" with brute force — it just takes exponential time). "Undecidable" is stronger than "intractable".
✓ Notes completed!
Video coming soon
Click to advance · Arrow keys also work
Click slide or press arrow keys to navigate

Worksheet — 2.2.1d Computational Methods & Problem Classification

8 questions · 24 marks · instantly marked

Q1Explain the divide and conquer approach. State the three phases and give an example algorithm that uses it.[4 marks]
✓ Mark scheme
Divide and conquer breaks a problem into smaller sub-problems of the same type [1]. Three phases: Divide (split the problem into sub-problems), Conquer (solve sub-problems recursively until base case reached), Combine (merge sub-solutions into overall solution) [2 — award 1 for any 2 phases correctly described]. Example: merge sort — divides array in half, sorts each half recursively, merges sorted halves; OR binary search — divides search space in half each step [1].
Q2What is the key difference between divide and conquer and dynamic programming?[3 marks]
✓ Mark scheme
Divide and conquer: sub-problems are independent — solving one doesn't help solve another; results are not stored [1]. Dynamic programming: sub-problems OVERLAP — the same sub-problem is encountered multiple times. DP stores results (memoises) to avoid recomputation [1]. Example: Fibonacci — fib(5) calls fib(3) twice (overlapping). Merge sort divides into independent halves (no overlap) [1].
Q3Explain memoisation and tabulation as two approaches to dynamic programming.[4 marks]
✓ Mark scheme
Memoisation (top-down): uses a recursive function with a cache (dictionary/array). When a subproblem is first solved, the result is stored. Subsequent calls for the same subproblem return the cached result rather than recomputing [2]. Tabulation (bottom-up): builds a table iteratively from the smallest subproblems upwards, filling each cell using previously computed values. No recursion overhead [2]. Both achieve the same time complexity. Memoisation computes only needed subproblems; tabulation always fills the whole table.
Q4Describe how backtracking works. How does it differ from exhaustive brute force?[3 marks]
✓ Mark scheme
Backtracking builds a solution step by step [1]. At each step, it checks whether the current partial solution can still lead to a valid solution. If not (constraint violated), it backtracks (undoes the last choice) and tries the next option [1]. Difference from brute force: brute force tries every possible combination; backtracking prunes the search tree early when a partial path is already invalid — avoids exploring large portions of the search space [1]. Example: Sudoku — if placing 5 in a cell creates a duplicate in the row, backtrack immediately rather than trying all possibilities for subsequent cells.
Q5A greedy coin-change algorithm uses denominations {1, 5, 10, 20, 50, 100}p. Trace the greedy algorithm to make 63p change using the fewest coins.[3 marks]
✓ Mark scheme
Greedy: always pick the largest coin that fits the remaining amount. 63 - 50 = 13 (1 × 50p) [1]; 13 - 10 = 3 (1 × 10p); 3 - 1 = 2, 2 - 1 = 1, 1 - 1 = 0 (3 × 1p) [1]. Total: 50 + 10 + 1 + 1 + 1 = 5 coins [1]. Note: this greedy approach works optimally for standard UK coin denominations, though not for all arbitrary denomination sets.
Q6Explain the difference between a tractable and an intractable problem. Give an example of each.[4 marks]
✓ Mark scheme
Tractable problem: can be solved by an algorithm with polynomial time complexity O(nᵏ) [1]. Practical for large inputs. Example: sorting (O(n log n)), BFS (O(V+E)), linear search (O(n)) [1]. Intractable problem: no known polynomial-time algorithm exists. Worst-case time is typically exponential (e.g. O(2ⁿ) or O(n!)) [1]. Practical only for small inputs. Example: Travelling Salesman Problem (finding the shortest route visiting all cities once), graph colouring, satisfiability (SAT) [1].
Q7What is the Halting Problem? Why is it undecidable?[3 marks]
✓ Mark scheme
The Halting Problem: given any program and its input, determine whether the program will halt (finish) or run forever [1]. Undecidable: no algorithm exists that correctly answers yes/no for ALL programs in finite time [1]. Turing proved this (1936) by contradiction: assume a halting detector H exists; construct a program P that halts if H says it loops, and loops if H says it halts — this creates a logical paradox, proving H cannot exist [1]. The Halting Problem is therefore non-computable.
Q8Explain the difference between P and NP problem classes. Why does the question "P = NP?" matter?[4 marks]
✓ Mark scheme
P: problems solvable in polynomial time [1]. NP: problems verifiable in polynomial time — given a solution, we can check it's correct quickly — but no polynomial-time solving algorithm is known [1]. If P = NP, every problem whose solution can be verified quickly could also be solved quickly — this would break public-key cryptography (RSA relies on factoring being intractable) and solve many optimisation problems instantly [1]. Most experts believe P ≠ NP but this is unproven — it is the most famous open problem in computer science and one of the Millennium Prize Problems [1].
Topic Quiz
1 of 15
You scored
out of 15
🎯

Mini Test — 2.2.1d Computational Methods

  • 10 questions · 10 marks · 10 minutes
  • 5 MCQ + 5 short answer
Card 1 of 15
Click to reveal
🎉
Complete!
TermDefinition
← 2.2.1c Sets, Maps & Graph Traversal 2.2.1 Problem Solving & Programming Next: 2.2.1e Writing & Tracing Algorithms →