ConceptComplete

Recurrence Relations - Examples and Constructions

Recurrence relations arise naturally in diverse contexts, from counting problems to algorithm analysis. These examples illustrate both the ubiquity of recurrences and techniques for formulating and solving them.

ExampleCatalan Numbers

The Catalan numbers CnC_n count many combinatorial objects, including:

  • Ways to parenthesize a product of n+1n+1 factors
  • Binary trees with nn internal nodes
  • Paths in a grid that don't cross the diagonal

They satisfy the recurrence: Cn=βˆ‘i=0nβˆ’1CiCnβˆ’1βˆ’iΒ forΒ nβ‰₯1C_n = \sum_{i=0}^{n-1} C_i C_{n-1-i} \text{ for } n \geq 1 with C0=1C_0 = 1.

This is a non-linear recurrence. The closed form (derivable using generating functions) is: Cn=1n+1(2nn)=(2n)!(n+1)!β‹…n!C_n = \frac{1}{n+1}\binom{2n}{n} = \frac{(2n)!}{(n+1)! \cdot n!}

The first few values are: 1,1,2,5,14,42,132,429,…1, 1, 2, 5, 14, 42, 132, 429, \ldots

ExampleDivide-and-Conquer Recurrences

Many algorithms use divide-and-conquer, leading to recurrences of the form T(n)=aT(n/b)+f(n)T(n) = aT(n/b) + f(n).

Merge Sort: Divides array in half, recursively sorts each half, then merges. T(n)=2T(n/2)+Θ(n)T(n) = 2T(n/2) + \Theta(n) Solution: T(n)=Θ(nlog⁑n)T(n) = \Theta(n \log n)

Binary Search: Divides search space in half at each step. T(n)=T(n/2)+Θ(1)T(n) = T(n/2) + \Theta(1) Solution: T(n)=Θ(log⁑n)T(n) = \Theta(\log n)

Karatsuba Multiplication: Multiplies two nn-digit numbers. T(n)=3T(n/2)+Θ(n)T(n) = 3T(n/2) + \Theta(n) Solution: T(n)=Θ(nlog⁑23)β‰ˆΞ˜(n1.585)T(n) = \Theta(n^{\log_2 3}) \approx \Theta(n^{1.585})

The Master Theorem provides a general method for solving such recurrences, comparing f(n)f(n) with nlog⁑ban^{\log_b a} to determine which dominates asymptotically.

ExampleCounting Bit Strings

How many nn-bit binary strings contain no consecutive 1's?

Let ana_n be this count. Such a string either:

  1. Ends in 0: the first nβˆ’1n-1 bits form any valid (nβˆ’1)(n-1)-bit string, giving anβˆ’1a_{n-1} strings
  2. Ends in 01: the first nβˆ’2n-2 bits form any valid (nβˆ’2)(n-2)-bit string, giving anβˆ’2a_{n-2} strings

Therefore: an=anβˆ’1+anβˆ’2a_n = a_{n-1} + a_{n-2} with a1=2a_1 = 2 (0 and 1) and a2=3a_2 = 3 (00, 01, 10).

This is the Fibonacci recurrence with different initial conditions! The solution involves the same characteristic roots: an=2+Ο•5Ο•n+2βˆ’Ο•5Ο•^na_n = \frac{2+\phi}{\sqrt{5}} \phi^n + \frac{2-\phi}{\sqrt{5}} \hat{\phi}^n

where Ο•=1+52\phi = \frac{1+\sqrt{5}}{2} and Ο•^=1βˆ’52\hat{\phi} = \frac{1-\sqrt{5}}{2}.

ExampleJosephus Problem

In the Josephus problem, nn people stand in a circle, and every second person is eliminated until one remains. If J(n)J(n) is the position of the survivor, then: J(2n)=2J(n)βˆ’1J(2n) = 2J(n) - 1 J(2n+1)=2J(n)+1J(2n+1) = 2J(n) + 1 with J(1)=1J(1) = 1.

For n=2m+β„“n = 2^m + \ell where 0≀ℓ<2m0 \leq \ell < 2^m, the solution is: J(n)=2β„“+1J(n) = 2\ell + 1

This can be proven by induction using the recurrence.

Remark

Some recurrences don't have closed-form solutions in terms of elementary functions but can still be analyzed asymptotically. For instance, the Ackermann function grows faster than any primitive recursive function, and recurrences arising from nested recursion can be analyzed using techniques from analytic combinatorics. The Akra-Bazzi method generalizes the Master Theorem to handle more complex divide-and-conquer scenarios with non-equal partitions and non-polynomial combining costs.

These examples demonstrate how recurrence relations provide a natural language for expressing sequential dependencies in discrete structures.