You are on page 1of 6

Recurrence Relations and their Solution

1. Let an be number of subsets of n-element set. Then a1 = 2. For n > 1,


there are an equal number of subsets that contain n and that dont. We
obtain the recurrence relation
a1 = 1, an = 2an1 (n 2).
Solution: an = 2n .
2. Let an be the regions of the plane formed by n mutually intersecting
circles. Then a1 = 2, and for n 2, the last circle added divides 2(n 1)
previously existing regions into 2 each, yielding an = an1 + 2(n 1). We
obtain the recurrence relation
a1 = 2, an = an1 + 2(n 1) (n 2).
Solution:
an = 2 + 2 + 4 + 6 + + 2(n 1) = 2 + (n 1)n = n2 n + 2.

3. Assume you have 4 types of 1-cent stamps and 5 types of 2-cent stamps.
Let an be the number of ways to paste these stamps in a row on an envelope
to create a postage of n cents. Then a1 = 4, a2 = 21, and for n 3,
an = 4an1 + 5an2 . Reason: There are 4 ways to start with a penny stamp,
followed by an1 ways to add n 1 more cents, and there are 5 ways to start
with a 2-cent stamp, followed by an2 ways to add n 2 more stamp. We
obtain the recurrence relation
a1 = 4, a2 = 21, an = 4an1 + 5an2 (n 3).
Solution: Write Dan = an1 . Then
(1 4D 5D2 )an = 0,
(1 5D)(1 + D)an = 0.
The most general solution to (1rD)an = 0 is an = prn . Hence two solutions
are an = p5n and an = q(1)n , and an = p5n + q(1)n is another solution.
Choosing p and q so that a1 = 4 and a2 = 21 yields p = 56 and q = 16 . Hence
5
1
an = 5n + (1)n .
6
6
1

4. Analyzing the number of comparisons an required to sort a list of 2n


numbers into ascending order: If there is only one number, do nothing. Otherwise, separate the list into two sublists of length 2n1 , sort the first sublist
using an1 comparisons, sort the second sublist using an1 comparisons, then
merge the two lists together using 2n comparisons. Computer scientists refer
to this as the Merge-Sort Algorithm and our analysis yields the recurrence
relation
a0 = 0, an = 2an1 + 2n (n 1).
This implies
(1 2D)an = 2n ,
(1 2D)2 an = 0.
Therefore a homogeneous recurrence relation satisfied by an is
an 4an1 + 4an2 = 0 (n 2).

5. Lemma: Solutions to (1 rD)k an are


an = rn , an = nrn , an = n2 rn , ..., an = nk1 rn .

Proof: We prove this by induction on k. The base case says that rn is a


solution to (1 rD)an . This is true.
Now assume that solutions to (1rD)k an are an = rn , nrn , n2 rn , . . . , nk1 an .
Then these are all solutions to (1 rD)k+1 an = 0 because
(1 rD)k+1 an = (1 rD)(1 rD)k an = (1 rD)0 = 0.
Now consider an = nk rn . Then
(1 rD)k+1 an = (1 rD)k (1 rD)an = (1 rD)k (an ran1 ).
Lets calculate an ran1 . We have
an ran1 = nk rn r(n 1)k rn1 = (nk (n 1)k )rn .
2

By the Binomial Theorem,


k  
X
k j
(n 1) =
n (1)kj ,
j
j=0
k

therefore

k1  
X
k j
n (n 1) =
n (1)kj+1 .
j
j=0
k

For simplicity, we will write


nk (n 1)k = c0 + c1 n + c2 n2 + + ck1 nk1 .
Therefore
an ran1 = c0 rn + c1 nrn + c2 n2 rn + + ck1 nk1 rn ,
(1 rD)k+1 an = (1 rD)k (c0 rn + c1 nrn + c2 n2 rn + + ck1 nk1 rn ) = 0.
Hence the Lemma is true by the Principle of Mathematical Induction.
6. We return to Problem 4. It satisfies the recurrence relation
a0 = 0, a1 = 2, (1 2D)2 an = 0 (n 2).
Two solutions to (1 2D)2 an = 0 are an = 2n and an = n2n , and we can
combine them to form the solution an = p2n + qn2n . We need only choose p
and q so that a0 = 0 and a1 = 2. Doing this yields p = 0, q = 1, an = n2n .
7. The number of comparisons required to sort a list of n numbers using
Merge-Sort is 2n log2 (2n). Reason: Let k be an integer such that
2k1 n < 2k .
We will pad our list to length 2k by adding 2k n zeros to the end of it. We can
sort this list using k2k comparisons. Given that 2k 2n and k < log2 (2n),
we have k2k (log2 (2n))(2n) = 2n log2 (2n).
8. Another sorting algorithm is Bubble Sort. To sort a 1-element list (A1 ),
do nothing. To sort a 2-element list (A1 , A2 ), set A1 aside, sort the list (A2 ),
then place A1 in the correct position relative to A1 . To sort a 3-element
list (A1 , A2 , A3 ), set A1 aside, sort the list (A2 , A3 ) into (A02 , A03 ), then place
3

A1 in the correct position relative to (A02 , A03 ). In general, to sort the list
(A1 , A2 , . . . , An ), set A1 aside, sort the list (A2 , . . . , An ) into the sorted list
(A02 , . . . , A0n ), then place A1 in the correct position relative to A02 , . . . , A0n .
The algorithm for placing A1 in the correct position is to slide it past all
numbers that are smaller than it (the bubbling operation). This requires at
most n1 comparisons. Hence if an is the worst-case number of comparisons
required to sort an n-element list, then a1 = 0 and an = an1 + (n 1). The
solution to this recurrence relation is an = 0 + 1 + + (n 1) = 12 n2 12 n.
9. Consider the recurrence relation
a0 = 5, a1 = 6, an = an1 + 6an2 + 2n + 5 3n + n (n 2).
We reorganize this to
an an1 6an2 = 2n + 5 3n + n1n ,
(1 + 2D)(1 3D)an = 2n + 5 3n + n1n .
By the Lemma in Item 5 above, (1 2D)2n = 0, (1 3D)(5 3n ) = 0, and
(1 D)2 (n1n ) = 0. Applying the recurrence relation above by
(1 2D)(1 3D)(1 D)2
we obtain
(1 2D)(1 + 2D)(1 3D)2 (1 D)2 an = 0 (n 6).
To solve this recurrence relation we need need to provide 6 initial conditions,
a0 through a5 . These can be produced using the original recurrence relation.
By the Lemma in Item 5 again, solutions to the recurrence relation include
2n , (2)n , 3n , n3n , 1n , and n1n . A solution involving 6 constants is
an = c1 2n + c2 (2)n + c3 3n + c4 n3n + c5 1n + c6 n1n .
Using the initial conditions
(a0 , a1 , a2 , a3 , a4 , a5 ) = (5, 6, 87, 269, 1216, 4082)
we obtain a system of 6 equations in 6 unknowns whose solution is
(c1 , c2 , c3 , c4 ,5 , c6 ) = (1,
4

13 1
176 49
, , 3, , ).
45 20
36 6

Therefore
an = 2n +

13
176
49
1
(2)n + 3n + 3n3n 1n n1n .
45
20
36
6

10. A formula for an = 12 + 32 + + (2n 1)2 : This satisfies the recurrence


relation
an = 1, an = an1 + (2n 1)2 (n 2).
We can reorganize this to
an = 1, (1 D)an = 4n2 4n + 1.
Applying (1 D)3 to both sides yields
(1 D)4 an = 0.
Solutions to this equation include 1, n, n2 , n3 . Setting
an = c0 + c1 n + c2 n2 + c3 n3
and using the 4 initial conditions
(a1 , a2 , a3 , a4 ) = (1, 10, 35, 84)
we obtain

4
1
(c0 , c1 , c2 , c3 ) = (0, , 0, ).
3
3

This yields
12 + 32 + + (2n 1)2 =

4n3 n
n(2n 1)(2n + 1)
=
.
3
3

11. A formula for the Fibonacci numbers 1, 2, 3, 5, 8, ... : The recurrence


relation is
an = an1 + an2 (n 2),
(1 D D2 )an = 0.

Factoring 1 D D2 into (1 rD)(1 sD) yields


r + s = 1 and rs = 1.

1 5
Solving the system of equations yields r = 2 and s = 1+2 5 . Setting
!n
!n
1 5
1 + 5
an = p
+q
2
2
and solving for p and q yields
an =

1
2

!n+1
5

1 +
2

!n+1
5