Skip to main content
← AT CS Study Guide

Unit 1 · Foundational

Recursion

Solving a problem by defining a smaller version of itself. The unit is less about writing recursive code than about arguing that it terminates and that the recursive step actually covers the problem.

What a strong answer looks like

A strong Unit 1 answer names the base case, shows every call moves toward it, and states what the recursive step assumes.

Topics in this unit

1

Base Cases

Know

A base case stops the recursion. It must be reachable from every possible call, which is a stronger requirement than merely existing.

Apply

Write the base case first, then check that each recursive call strictly reduces the input toward it.

Watch out

A base case that exists but is unreachable for some inputs, such as testing equality when the input decreases by two.

Study move

Write a recursion whose base case is unreachable for odd inputs, then repair it.

2

The Call Stack

Know

Each pending call occupies a stack frame, so recursion depth costs memory even when the code looks small.

Apply

State the recursion depth for a given input to reason about space, not only time.

Watch out

Assuming recursion is free. Depth proportional to input size means linear extra space.

Study move

Compare the space used by a recursive and an iterative sum over a list of length n.

3

Recursive Correctness

Know

A recursive method is argued correct by assuming the recursive call works on a smaller input and showing the combination step is right.

Apply

Write the argument in two parts: base case correct, and recursive step correct given the assumption.

Watch out

Tracing one example and calling it a proof. A trace is evidence, not an argument.

Study move

Write the two-part correctness argument for a recursive tree height method.

4

Recursion Versus Iteration

Know

Some problems are naturally recursive because their structure is recursive, such as trees. Others are clearer as loops.

Apply

Choose recursion where the data is self-similar and iteration where progress is linear.

Watch out

Forcing recursion onto a simple accumulation, which adds stack cost for no clarity.

Study move

Convert a recursive list sum to iteration and say which reads better and why.

Emphasized in this unit

Connections and techniques that receive extra attention in this unit.

  • Writing the base case before the recursive step
  • Reasoning about recursion depth as a space cost
  • Producing a correctness argument rather than a trace

Varies by course

Related topics some schools attach to this unit and others leave out. Covered on request rather than assumed.

  • Tail recursion. Discussed in some sections; Java does not optimise it away.
  • Mutual recursion. Occasionally introduced as an extension.

Mastery checklist

  • Write a base case that is reachable from every call.
  • State the recursion depth for a given input.
  • Give a two-part correctness argument.
  • Choose between recursion and iteration with a reason.

Check yourself

  • What makes a base case unreachable?
  • Why does recursion cost memory even when the method body is tiny?
  • Why is tracing one example not a correctness argument?

Modeling drill

Write a recursive method returning the height of a binary tree, then give its base case, its recursive step, and its worst-case space cost.

Base caseRecursive stepCall stackStack frameRecursion depthCorrectness argument