Combinatorics • Topic 14

Recursion

Recursion is the process of defining a sequence or function in terms of itself. It is the heart of induction and dynamic programming.

Building a Recursion

To solve a counting problem recursively:
  1. Define the state: Let be the number of ways to do the task for size .
  2. Find the relation: Express using previous terms (, etc.) by considering the last step.
  3. Base Cases: Calculate small values () manually.
Example (Tiling a 2xn Board)
How many ways to tile a board with dominoes?

Proof. Let be the number of ways. Consider the rightmost column(s):

  1. Place one vertical domino: Remaining space is , so ways.
  2. Place two horizontal dominoes stacked: Remaining space is , so ways.
Relation: . Base cases: . This is the Fibonacci sequence.

Towers of Hanoi

To move disks from peg A to peg C:
  1. Move disks from A to B ().
  2. Move largest disk from A to C (1 move).
  3. Move disks from B to C ().
Solution: .

Practice Problems

Exercise (Problem 1)
Find a recurrence for the number of binary strings of length that do not contain consecutive zeros.
Exercise (Problem 2)
A "derangement" is a permutation where no element appears in its original position. Derive the recurrence .
Exercise (Problem 3)
Let be the number of subsets of that contain no consecutive integers. Find .