B2.4 Programming algorithmsB2.4.5

Constructing and Tracing Recursive Algorithms (AHL)

Construct and trace recursive algorithms in a programming language

AHL≈ 60 minCommand term: ConstructPremium

In this lesson

  • Constructing simple, non-branching recursive functions in Java and Python
  • Tracing recursive calls with a trace table, including the values returned
  • Following code that runs before and after a recursive call
  • Comparing a recursive function with an iterative version

This lesson is part of Premium

Every topic has one free lesson. Premium unlocks every interactive lesson, the exam-style questions at the end of each one, and the rest of Praxis IB.

What's inside

  1. LearnWriting a recursive function
  2. CodeThe sum of 1 to n
  3. CodeRaising to a power
  4. CheckTrace the calls
  5. CodeRecursion on strings
  6. LabBefore and after the call
  7. CodeA mystery function
  8. CheckQuick check
  9. CodeTry it: counting a character
  10. LearnRecursion or a loop?
  11. CodeFactorial without recursion
  12. ExamWorked exam answer
  13. ReviewMistakes examiners see
  14. Exam practiceExam-style questions

Ends with 4 exam-style questions worth 13 marks, with a self-marking markscheme.