Single lesson · Written for OCR A Level (H446)

Recursion compared with iteration – OCR A Level Computer Science lesson (H446)

Students learn to draw the call stack for a recursive function and compare recursion with iteration for memory, risk and readability.

Also in a bundle Searching, Sorting and Recursion – OCR A Level Computer Science lessons (H446) 15 lessons for £45 · save 25% on buying separately

Lesson 8 of 15 in unit 12.4 Searching, Sorting and Recursion, taught in Year 12, Autumn 2. It answers one big question: When is recursion better than a loop, and when is it worse?

By the end, students can draw the call stack for a recursive function and compare recursion with iteration for memory, risk and readability.

The Build (the main task)
Compare recursive and iterative versions of Tidewave Audio's totalLength function in terms of memory use, risk of failure and how easy each is to follow (6 marks).
Support version
A comparison grid (memory · risk · readability) with 'whereas' sentence starters and the call stack for n = 3 already drawn.
Challenge
Explain why Python raises a RecursionError when the recursive version totals a 5 000-track Tidewave Audio playlist, and rewrite the function iteratively (5 marks).
Real-world link
Tidewave Audio's longest playlist has 5 000 tracks, which breaks the recursive version.
Key words
Call stack, Stack overflow and Compare, each with a definition, an icon and a common mix-up on the key vocabulary slide.
Misconceptions it tackles
“Every recursive call shares one set of variables”; “Recursion is always faster because the code is shorter”.
OCR H446 specification
2.2.1 (b) (recursion: how it can be used, and how it compares with an iterative approach).

Every lesson follows the same Code & Commerce structure: a Bell Task recall starter, key vocabulary with definitions and icons, short teaching chunks with a check before pupils move on, The Build (one main task), challenge questions that get harder, and an exit question. Answers reveal one at a time on the slides, and everything is editable PowerPoint and Word.

Students need computers for the main task.

Also sold in the Searching, Sorting and Recursion unit bundle, which includes the medium term plan, and in the full-year and complete-course bundles.

An independent resource written for OCR A Level Computer Science (H446). It is not endorsed by OCR or Cambridge University Press & Assessment. Programming project (NEA) lessons teach general skills on a made-up example project and give supervised time, within JCQ's rules on the help a centre may give.

What's included

  • Slide deck (PowerPoint)
  • Lesson plan (Word)
  • Worksheet (Word)
  • Support worksheet with scaffolds (Word)
  • Single-teacher licence: use and adapt it with your own classes

More for A Level Computer Science

See all

Written for the specifications named. Not endorsed by or affiliated with any exam board.