All modules

Intermediate -- Module 03

Functions & Recursion

Function declarations vs. definitions, pass-by-value semantics, static vs. global state, and recursion -- including how to reason about a call stack and when to prefer iteration.

Video lesson

Downloadable notes

Plain-text lecture notes for Functions & Recursion.

Download notes (.txt)

Practice problems

GCD by recursion

Implement Euclid's algorithm for greatest common divisor recursively.

Warm-up

Memoized Fibonacci

Write recursive fib(n) with an array-based memo table so fib(40) returns instantly.

Core

Towers of Hanoi

Print the full move sequence for n disks and count total moves recursively.

Stretch
Try these in the playground →

Module quiz

1. C passes arguments to functions by:

2. A `static` local variable inside a function:

3. Every recursive function needs at minimum:

4. Deep uncontrolled recursion typically fails with: