IB Computer Science Revision Booklet — Free Sample (2027 Syllabus)
Free sample · IB CS Hub · IB Diploma Computer Science · 2027 syllabus

IB Computer Science Revision Booklet — Free Sample

A real page from one of our revision booklets, in full — key terms to copy down, a worked example, and a practice question with a full model answer. Every unit in the full course has one of these. Also see the free glossary and the syllabus guide.

B2 Programming · Sample page

Recursion — key terms & worked example

Key terms to copy down

Base case — the condition under which a recursive function stops calling itself and returns a value directly, instead of calling itself again.

Recursive case — the part of the function that calls itself with a smaller or simpler input, moving one step closer to the base case each time.

Call stack — where Python stores each paused function call while it waits for the recursive call beneath it to finish and return a value.

Worked example
def factorial(n):
if n == 0:   # base case
return 1
# recursive case:
return n * factorial(n - 1)

Trace factorial(3): calls stack up as 3 × factorial(2), 2 × factorial(1), 1 × factorial(0) — then unwind: 1, 1, 2, 6.

Practice question & full model answer
Question [4 marks]

A student writes a recursive function to reverse a string but forgets to include a base case.

Identify what will happen when the function is called, and outline the fix.

Model answer — mark scheme

Without a base case, the function keeps calling itself with a shrinking string forever — it never hits a stopping condition. Eventually Python's maximum recursion depth is exceeded and it raises a RecursionError instead of returning a result. (2 marks: identifies infinite recursion + names the resulting error.)

Fix: add a base case that returns directly once the string is empty, e.g. if len(s) == 0: return s, checked before the recursive call. (2 marks: correct fix + correctly placed before recursion.)

Every unit has a booklet like this

Full revision booklets for every unit, plus lesson decks, exam-style practice with worked answer keys, a progress tracker, and AI-powered exam prep — one payment, one year of access.

See what's included →
© 2026 IB CS Hub Home Glossary Syllabus Guide IA Guide Course Hub