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
therefore
k1
X
k j
n (n 1) =
n (1)kj+1 .
j
j=0
k
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
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
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