Back to Topic 6.4 — Programming algorithms
6.4.5Computer Science5 flashcards

Tracing recursion

Practice Flashcards

Flip to reveal answers
Card 1 of 56.4.5
6.4.5
Question

What are the two halves of a recursive trace?

Click to reveal answer

Track your progress — Sign up free to save your progress and get smart review reminders based on spaced repetition.

All 5 Flashcards — Tracing recursion

Sign up free to track progress and get spaced-repetition review schedules.

Card 1process

Question

What are the two halves of a recursive trace?

Answer

**Down** — each call is made and waits, with no arithmetic. **Up** — each returns a value, and the arithmetic happens.

Card 2concept

Question

When does the arithmetic in n + recurse(n-1) happen?

Answer

On the way **up**, once the base case has returned a value to add to. Nothing is computed descending.

Card 3process

Question

How should a recursive trace be laid out?

Answer

Indent each call **one level further** than its caller; leave the return blank going down and fill it in coming back up.

Card 4concept

Question

Which three questions build a recursive function?

Answer

**Base case**: which small input has a known answer? **Smaller step**: how does each call shrink the problem? **Combine**: what is done with the returned value on the way up?

Card 5concept

Question

What happens if the base case is never reached?

Answer

The calls never stop: each adds a frame to the **call stack** until it overflows and the program crashes (**stack overflow**).

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