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:- Define the state: Let be the number of ways to do the task for size .
- Find the relation: Express using previous terms (, etc.) by considering the last step.
- 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):
- Place one vertical domino: Remaining space is , so ways.
- Place two horizontal dominoes stacked: Remaining space is , so ways.
Towers of Hanoi
To move disks from peg A to peg C:- Move disks from A to B ().
- Move largest disk from A to C (1 move).
- 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 .