OCR H446 A Level Computer Science · 2.1 and 2.2 Computational Thinking and Problem Solving

Stretch tasks Programming Techniques and Computational Methods

Task 1

Quiz Challenge

A quiz game against four computer players, then short and long written answers.

  1. Quiz Blitz12 questions against the clock
  2. Quick Fire4 short answers
  3. Big Think2 long answers

About 20 minutes

Task 2

This or That

Pixel the cat asks 8 questions. Each has two answers: pick the right one.

  • Two answers to every question
  • A fish treat for every right answer
  • Streaks win Pixel shades, then a party hat

About 4 minutes

Task 3

Memory Match

Flip the cards two at a time to match each term card to its meaning card.

  • 12 cards: each term has a meaning
  • One peek at every card
  • Combo points for pairs found in a row

6 pairs, about 4 minutes

Task 4

Sort It

Sort each statement into the right box, like the tick box tables in the exam.

  • 12 cards to sort into 4 boxes
  • Drag a card, tap a box or press its number
  • Combo points for cards sorted in a row

12 cards, about 4 minutes

Task 5

Code Word

Guess the lesson's secret words. Every guess shows which letters are right.

  • A clue for every word
  • Tiles turn green, amber or grey after each guess
  • Fewer guesses win more points

3 words, about 4 minutes

Task 7

Bug Hunt

Two statements are true and one has a bug. Catch the bug before it gets away.

  • Three statements in every round
  • Tap the one with the mistake
  • Streaks win bonus points

5 rounds, about 4 minutes

Brain games

Train your brain on this lesson

Logic, memory and speed, built from this lesson's own key ideas. Win up to three diamonds in each game.

Logic

Odd One Out

Four tiles: three share a link and one does not. Spot the odd one out, then see what links the rest.

  • Three belong together, one does not
  • A hint shows the link, for fewer points
  • Quick answers and streaks win more

8 rounds, about 3 minutes

Memory

Memory Flash

Study the term cards, then they flip over. Find the card that goes with each clue, from memory.

  • Three levels: 3, 4 and 6 cards
  • Two tries to find each card
  • Streaks win bonus points

3 levels, about 4 minutes

Speed

Fact or Fib

Statements fly in one at a time. Is each one a fact or a fib? Decide fast.

  • Swipe, tap or use the arrow keys
  • Every fib comes with its fix
  • Streaks multiply your points

12 statements, about 3 minutes

The final challenge

City Run

Race a robot cat on inline skates through a neon cyber city, from Neon Station to the Hyper Tunnel. Every question is a row of neon gates across the tracks: skate through the one with the right answer, dodge the trains and barriers, and grab diamonds.

  • 20 questions from this lesson, in four parts of the city
  • Swipe, tap or use the arrow keys
  • Dodge trains and holograms, and jump crates and cones

20 questions, about 6 minutes

Bonus challenge

Neon Roll

Roll a glowing ball down an endless neon slope, past towers lit up with neon signs of Pixel the cat. Steer, jump the gaps and dodge the blocks. Questions from this lesson wait at gates along the way: every right answer keeps the ball rolling.

  • Questions from this lesson at every gate
  • Hold the arrow keys or a side of the slope to steer
  • 8 right answers win two diamonds, 15 win three

Endless, about 5 minutes

The games need JavaScript. Every question is below, with the answers at the end.

Read the lesson: Programming Techniques and Computational Methods

Programming Techniques and Computational Methods: the questions

Quiz Challenge, round 1: Quiz Blitz

  1. What stops a recursive subroutine calling itself forever?

    • A global variable
    • A loop counter
    • A second parameter
    • A base case
  2. What does this function return for factorial(4)?

    def factorial(n):
        if n <= 1:
            return 1
        return n * factorial(n - 1)
    • 10
    • 16
    • 4
    • 24
  3. Every recursive algorithm can also be written iteratively.

    • True
    • False
  4. What happens to memory each time a recursive call is made?

    • Nothing, recursion uses no memory
    • The program counter is reset
    • A new stack frame is added
    • The heap is cleared
  5. Which TWO are true of passing by reference?

    Tick 2.

    • A copy of the value is passed
    • The original is always protected
    • It always uses more memory
    • The subroutine can change the original
    • The address is passed
  6. Put the steps of backtracking in order.

    Number these 1 to 4.

    • Find it does not lead to a solution
    • Return to the last decision point
    • Try a different option
    • Follow a path
  7. Which IDE feature pauses a program at a chosen line?

    • A breakpoint
    • Syntax highlighting
    • Auto complete
    • Version control
  8. A heuristic always finds the best possible answer.

    • True
    • False
  9. What error occurs when recursion goes so deep that the stack runs out?

  10. Which method splits a problem into smaller copies of itself and combines the results?

    • Backtracking
    • Data mining
    • Visualisation
    • Divide and conquer
  11. Why are global variables discouraged?

    • They can be changed from anywhere, so faults are hard to trace
    • They use no memory
    • They cannot hold strings
    • They disappear when a subroutine ends
  12. Which computational method looks for unknown patterns in huge datasets?

    • Backtracking
    • Performance modelling
    • Data mining
    • Pipelining

Quiz Challenge, round 2: Quick Fire

  1. Explain the difference between passing a parameter by value and by reference. [2 marks]

  2. Compare recursion with iteration in terms of memory. [2 marks]

  3. Explain why a satnav uses a heuristic rather than checking every possible route. [2 marks]

  4. Explain how backtracking solves a maze. [2 marks]

Quiz Challenge, round 3: Big Think

  1. Compare recursion and iteration, using factorial as an example. [6 marks]

  2. Explain how divide and conquer makes merge sort faster than bubble sort on large lists. [4 marks]

This or That: tick the right answer

  1. Which uses more memory as it goes deeper?

    • Recursion
    • Iteration
  2. A subroutine changes its parameter and the caller's variable changes too. How was it passed?

    • By value
    • By reference
  3. Which is usually faster to run?

    • Iteration
    • Recursion
  4. Which solves a sudoku by undoing wrong guesses?

    • Backtracking
    • Data mining
  5. Which variable exists only while its subroutine runs?

    • A local variable
    • A global variable
  6. A bank simulates a million customers before switching on a new system. What is this?

    • Performance modelling
    • Visualisation
  7. Which helps people spot patterns in ten thousand rows of data?

    • Visualisation
    • Pipelining
  8. Which IDE feature shows a variable's value as the code runs?

    • Auto complete
    • A watch

Memory Match: match each term to its meaning

TermMeaning
A Base case1 A rule of thumb for a good enough answer
B Stack frame2 Returns without making another call
C Scope3 Return to the last choice and try another
D Heuristic4 Pauses the program at a chosen line
E Backtracking5 Where an identifier can be used
F Breakpoint6 Parameters, locals and the return address

Sort It: tick one box in each row

Which computational method does each example use?

StatementDivide and conquerBacktrackingHeuristicsData mining
A satnav picking a good route quickly
A good enough timetable found fast
Finding patterns in millions of loyalty card records
A star using straight line distance
Quicksort around a pivot
Solving a maze by retreating from dead ends
Filling a sudoku and undoing wrong guesses
Spotting early signs a machine will fail
Merge sort
Finding products often bought together
Binary search halving the list
Placing eight queens on a chessboard

Code Word: write the word that fits each clue

  1. A subroutine calling itself, stopped by a base case. (9 letters)

  2. Where in a program an identifier can be accessed. (5 letters)

  3. A rule of thumb that gives a good enough answer quickly. (9 letters)

Link Up: find the three groups

These 12 tiles make 3 groups of 4. Write each group in the table, and what links its tiles.

  • Stack frames
  • Stepping
  • Backtracking
  • Calls to itself
  • Data mining
  • Base case
  • General case
  • Breakpoints
  • Visualisation
  • Auto complete
  • Variable watch
  • Heuristics

Bug Hunt: tick the statement that is wrong

In each set, two statements are true and one has a mistake in it.

    • Each recursive call adds a stack frame.
    • A recursive subroutine needs a base case.
    • Recursion uses less memory than the same loop.
    • Passing by reference passes the address of the variable.
    • Passing by value gives the subroutine a copy.
    • A value parameter changes the original variable.
    • A local variable exists only while its subroutine runs.
    • Global variables make faults easier to trace.
    • A global variable can be changed from anywhere.
    • Backtracking returns to the last decision point when a path fails.
    • Merge sort uses divide and conquer.
    • Data mining finds the best route between two places.
    • Stepping runs a program one line at a time.
    • Performance modelling means building the real system and timing it.
    • A breakpoint pauses a program at a chosen line.

Brain game: Odd One Out

Three tiles in each set share a link. Tick the odd one out, then write what links the other three.

    • Backtracking
    • Calls to itself
    • Visualisation
    • Heuristics

    What links the other three?

    • Stepping
    • Breakpoints
    • Auto complete
    • Heuristics

    What links the other three?

    • Stack frames
    • Base case
    • General case
    • Variable watch

    What links the other three?

    • Stack frames
    • Backtracking
    • Data mining
    • Heuristics

    What links the other three?

    • Stepping
    • Base case
    • Breakpoints
    • Auto complete

    What links the other three?

    • Stack frames
    • Base case
    • General case
    • Visualisation

    What links the other three?

Brain game: Memory Flash, on paper

Which term means this? Write your answer from memory.

  1. A rule of thumb for a good enough answer

  2. Returns without making another call

  3. Return to the last choice and try another

  4. Pauses the program at a chosen line

  5. Where an identifier can be used

  6. Parameters, locals and the return address

Brain game: Fact or Fib

Tick Fact if the statement is true and Fib if it is not.

  1. Performance modelling means building the real system and timing it.

    • Fact
    • Fib
  2. Data mining finds the best route between two places.

    • Fact
    • Fib
  3. Passing by value gives the subroutine a copy.

    • Fact
    • Fib
  4. Backtracking returns to the last decision point when a path fails.

    • Fact
    • Fib
  5. A value parameter changes the original variable.

    • Fact
    • Fib
  6. Recursion uses less memory than the same loop.

    • Fact
    • Fib
  7. A heuristic always finds the best possible answer.

    • Fact
    • Fib
  8. Global variables make faults easier to trace.

    • Fact
    • Fib
  9. Passing by reference passes the address of the variable.

    • Fact
    • Fib
  10. A local variable exists only while its subroutine runs.

    • Fact
    • Fib
  11. Stepping runs a program one line at a time.

    • Fact
    • Fib
  12. Each recursive call adds a stack frame.

    • Fact
    • Fib

City Run

City Run is a race through a neon cyber city, played on screen. It asks 20 of the questions above, from the quiz, This or That, Memory Flash and Fact or Fib.

Neon Roll

Neon Roll is a ball rolling down an endless neon slope, played on screen. Every right answer keeps it rolling. It asks the questions above, from the quiz, This or That, Memory Flash and Fact or Fib.

Answers

Round 1: Quiz Blitz

  1. A base case The base case returns without recursing, and every other call must move towards it.
  2. 24 4 times 3 times 2 times 1 is 24. The base case returns 1 when n reaches 1.
  3. True The choice is about which expresses the problem more clearly, and whether the stack can take the depth.
  4. A new stack frame is added Each frame holds the parameters, local variables and return address, so deep recursion can overflow the stack.
  5. The subroutine can change the original; The address is passed Passing by reference passes the address, so the subroutine works on the original. Passing a copy is passing by value.
  6. Follow a path → Find it does not lead to a solution → Return to the last decision point → Try a different option Backtracking explores, retreats to the last choice when it fails, and tries again.
  7. A breakpoint Once paused, you can step through the code and watch the variables change.
  8. False A heuristic finds a good enough answer quickly. It trades the guarantee of the best answer for speed.
  9. stack overflow Every call adds a stack frame, so very deep recursion uses up the stack.
  10. Divide and conquer Merge sort, quicksort and binary search all work this way.
  11. They can be changed from anywhere, so faults are hard to trace A subroutine that uses globals cannot be understood on its own.
  12. Data mining Finding products often bought together is a classic example.

Round 2: Quick Fire

    • By value passes a copy, so the original is not changed
    • By reference passes the address, so changes affect the original
    Model answer

    Passing by value gives the subroutine a copy, so changes inside it do not affect the original. Passing by reference gives it the address, so changes inside it affect the original variable.

    • Each recursive call adds a stack frame, so memory grows with depth
    • Iteration uses a constant amount of memory
    • Deep recursion can overflow the stack
    Model answer

    Each recursive call adds a stack frame, so memory grows with the depth of recursion and can overflow the stack, while iteration uses a constant amount of memory.

    • Checking every route would take far too long
    • A heuristic gives a good enough route quickly, though not always the best
    Model answer

    Checking every possible route would take far too long, so a heuristic finds a good enough route quickly, even though it is not guaranteed to be the best.

    • It follows a path until it reaches a dead end
    • Then it returns to the last decision point and tries another route
    Model answer

    It follows a path until it reaches a dead end, then goes back to the last decision point and tries a different route, repeating until it finds the exit.

Round 3: Big Think

    • A recursive factorial calls itself
    • A base case stops it, returning 1
    • The general case moves towards the base case
    • Each call adds a stack frame, so memory grows
    • Deep recursion risks a stack overflow
    • An iterative version uses a loop and constant memory
    • Iteration is faster, with no call overhead
    • Recursion is clearer for naturally recursive problems
    Model answer

    A recursive factorial calls itself: the base case returns 1 when n is 1 or less, and the general case returns n times the factorial of n minus 1, which moves towards the base case. Each call adds a stack frame, so memory grows with n and a large n could cause a stack overflow. An iterative version uses a for loop that multiplies a running product, so it uses a constant amount of memory and is faster because there is no call overhead. Recursion is clearer for problems that are naturally recursive, such as tree traversal, but iteration suits simple repetition like this.

    • The list is split in half repeatedly until each part holds one item
    • The sorted parts are combined back together
    • There are about log n levels of splitting
    • Each level handles all n items, so it takes n log n time
    • Bubble sort takes n squared time
    Model answer

    Merge sort repeatedly splits the list in half until each part holds one item, then combines the sorted sub lists. There are about log n levels of splitting and each level handles all n items, so it takes n log n time. Bubble sort compares adjacent pairs pass after pass, which takes n squared time, so on a large list merge sort does far less work.

This or That

  1. Recursion Every recursive call adds a stack frame. A loop reuses the same variables.
  2. By reference Passing by reference gives the address, so the subroutine works on the original.
  3. Iteration Recursion pays for a stack frame on every call. A loop has no call overhead.
  4. Backtracking Backtracking returns to the last choice when a path fails and tries another.
  5. A local variable A local's scope and lifetime are limited to its subroutine. A global lasts for the whole program.
  6. Performance modelling Modelling predicts how the system behaves under load without risking the real thing.
  7. Visualisation A chart shows at a glance a pattern that a table would hide.
  8. A watch A variable watch lets you see a value change as you step through the code.

Memory Match

  • A 2 Base case: Returns without making another call
  • B 6 Stack frame: Parameters, locals and the return address
  • C 5 Scope: Where an identifier can be used
  • D 1 Heuristic: A rule of thumb for a good enough answer
  • E 3 Backtracking: Return to the last choice and try another
  • F 4 Breakpoint: Pauses the program at a chosen line

Sort It

  1. Heuristics A satnav picking a good route quickly A good enough route found fast is a heuristic result.
  2. Heuristics A good enough timetable found fast Accepting good enough to save time is the heuristic trade off.
  3. Data mining Finding patterns in millions of loyalty card records Mining huge datasets for relationships nobody knew about is data mining.
  4. Heuristics A star using straight line distance The straight line estimate is A star's heuristic.
  5. Divide and conquer Quicksort around a pivot Quicksort partitions, then sorts each part the same way.
  6. Backtracking Solving a maze by retreating from dead ends Going back to the last choice when a path fails is backtracking.
  7. Backtracking Filling a sudoku and undoing wrong guesses Undoing a guess and trying another is backtracking.
  8. Data mining Spotting early signs a machine will fail Finding warning patterns in large records is data mining.
  9. Divide and conquer Merge sort Merge sort splits the list, sorts the halves and combines them.
  10. Data mining Finding products often bought together Searching big data for unknown patterns is data mining.
  11. Divide and conquer Binary search halving the list Each step solves a smaller copy of the same problem.
  12. Backtracking Placing eight queens on a chessboard Queens are placed and moved back when a placement fails, a classic backtracking problem.

Code Word

  1. RECURSION A subroutine calling itself, stopped by a base case.
  2. SCOPE Where in a program an identifier can be accessed.
  3. HEURISTIC A rule of thumb that gives a good enough answer quickly.

Link Up

  • Computational methods Backtracking; Data mining; Heuristics; Visualisation
  • IDE features Breakpoints; Stepping; Variable watch; Auto complete
  • Recursion needs Base case; General case; Stack frames; Calls to itself

Bug Hunt: the wrong statement, and why

  1. Recursion uses less memory than the same loop. Every call adds a stack frame, so recursion uses more memory than a loop.
  2. A value parameter changes the original variable. A value parameter is a copy, so the original is untouched. Only passing by reference changes the original.
  3. Global variables make faults easier to trace. A global can be changed from anywhere, so a fault could come from any part of the program.
  4. Data mining finds the best route between two places. That is a job for a heuristic search such as A star. Data mining finds unknown patterns in large datasets.
  5. Performance modelling means building the real system and timing it. Performance modelling simulates the system mathematically, which is cheaper and safer than building it first.

Odd One Out

  1. Calls to itself is the odd one out: it goes with Recursion needs. The other three: Computational methods.
  2. Heuristics is the odd one out: it goes with Computational methods. The other three: IDE features.
  3. Variable watch is the odd one out: it goes with IDE features. The other three: Recursion needs.
  4. Stack frames is the odd one out: it goes with Recursion needs. The other three: Computational methods.
  5. Base case is the odd one out: it goes with Recursion needs. The other three: IDE features.
  6. Visualisation is the odd one out: it goes with Computational methods. The other three: Recursion needs.

Memory Flash

  1. Heuristic A rule of thumb for a good enough answer
  2. Base case Returns without making another call
  3. Backtracking Return to the last choice and try another
  4. Breakpoint Pauses the program at a chosen line
  5. Scope Where an identifier can be used
  6. Stack frame Parameters, locals and the return address

Fact or Fib

  1. Fib Performance modelling means building the real system and timing it. The fix: Performance modelling simulates the system mathematically, which is cheaper and safer than building it first.
  2. Fib Data mining finds the best route between two places. The fix: That is a job for a heuristic search such as A star. Data mining finds unknown patterns in large datasets.
  3. Fact Passing by value gives the subroutine a copy.
  4. Fact Backtracking returns to the last decision point when a path fails.
  5. Fib A value parameter changes the original variable. The fix: A value parameter is a copy, so the original is untouched. Only passing by reference changes the original.
  6. Fib Recursion uses less memory than the same loop. The fix: Every call adds a stack frame, so recursion uses more memory than a loop.
  7. Fib A heuristic always finds the best possible answer. The fix: A heuristic finds a good enough answer quickly. It trades the guarantee of the best answer for speed.
  8. Fib Global variables make faults easier to trace. The fix: A global can be changed from anywhere, so a fault could come from any part of the program.
  9. Fact Passing by reference passes the address of the variable.
  10. Fact A local variable exists only while its subroutine runs.
  11. Fact Stepping runs a program one line at a time.
  12. Fact Each recursive call adds a stack frame.