Practice Flashcards
Flip to reveal answersWhat are the two parts of a recursive function?
Track your progress — Sign up free to save your progress and get smart review reminders based on spaced repetition.
All 5 Flashcards — Recursion
Sign up free to track progress and get spaced-repetition review schedules.
Question
What are the two parts of a recursive function?
Answer
A **base case** that returns without recursing, and a **recursive case** that calls itself on a smaller problem.
Question
Why does deep recursion cause a stack overflow?
Answer
Each call keeps a **stack frame** — parameters, locals, return address — and none is released until the base case is reached.
Question
Why do recursive calls need a stack?
Answer
They return in the **reverse order** they were made, most recent first — last in, first out.
Question
When is recursion genuinely better than iteration?
Answer
When the **data is self-similar** — a tree, a folder structure, a nested expression. Iterating those needs an explicit stack managed by hand.
Question
Is recursive factorial a good choice?
Answer
It is a good **teaching example**, not a good choice — a loop is faster and uses constant memory.
Read the notes
Full study notes for Recursion
Topic 6.4 hub
Programming algorithms
More from Topic 6.4
All flashcards in this topic
Computer Science exam skills
Paper structures & tips
Track your progress with spaced repetition
Sign up free — Aimnova tells you exactly which cards to review and when, so you remember everything before your IB exam.
Start Free