21.07.2013 Views

Recurrence Relations and their Solution 1. Let an be ... - MavDISK

Recurrence Relations and their Solution 1. Let an be ... - MavDISK

Recurrence Relations and their Solution 1. Let an be ... - MavDISK

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Recurrence</strong> <strong>Relations</strong> <strong><strong>an</strong>d</strong> <strong>their</strong> <strong>Solution</strong><br />

<strong>1.</strong> <strong>Let</strong> <strong>an</strong> <strong>be</strong> num<strong>be</strong>r of subsets of n-element set. Then a1 = 2. For n > 1,<br />

there are <strong>an</strong> equal num<strong>be</strong>r of subsets that contain n <strong><strong>an</strong>d</strong> that don’t. We<br />

obtain the recurrence relation<br />

<strong>Solution</strong>: <strong>an</strong> = 2 n .<br />

a1 = 1, <strong>an</strong> = 2<strong>an</strong>−1 (n ≥ 2).<br />

2. <strong>Let</strong> <strong>an</strong> <strong>be</strong> the regions of the pl<strong>an</strong>e formed by n mutually intersecting<br />

circles. Then a1 = 2, <strong><strong>an</strong>d</strong> for n ≥ 2, the last circle added divides 2(n − 1)<br />

previously existing regions into 2 each, yielding <strong>an</strong> = <strong>an</strong>−1 + 2(n − 1). We<br />

obtain the recurrence relation<br />

<strong>Solution</strong>:<br />

a1 = 2, <strong>an</strong> = <strong>an</strong>−1 + 2(n − 1) (n ≥ 2).<br />

<strong>an</strong> = 2 + 2 + 4 + 6 + · · · + 2(n − 1) = 2 + (n − 1)n = n 2 − n + 2.<br />

3. Assume you have 4 types of 1-cent stamps <strong><strong>an</strong>d</strong> 5 types of 2-cent stamps.<br />

<strong>Let</strong> <strong>an</strong> <strong>be</strong> the num<strong>be</strong>r of ways to paste these stamps in a row on <strong>an</strong> envelope<br />

to create a postage of n cents. Then a1 = 4, a2 = 21, <strong><strong>an</strong>d</strong> for n ≥ 3,<br />

<strong>an</strong> = 4<strong>an</strong>−1 + 5<strong>an</strong>−2. Reason: There are 4 ways to start with a penny stamp,<br />

followed by <strong>an</strong>−1 ways to add n − 1 more cents, <strong><strong>an</strong>d</strong> there are 5 ways to start<br />

with a 2-cent stamp, followed by <strong>an</strong>−2 ways to add n − 2 more stamp. We<br />

obtain the recurrence relation<br />

a1 = 4, a2 = 21, <strong>an</strong> = 4<strong>an</strong>−1 + 5<strong>an</strong>−2 (n ≥ 3).<br />

<strong>Solution</strong>: Write D<strong>an</strong> = <strong>an</strong>−<strong>1.</strong> Then<br />

(1 − 4D − 5D 2 )<strong>an</strong> = 0,<br />

(1 − 5D)(1 + D)<strong>an</strong> = 0.<br />

The most general solution to (1−rD)<strong>an</strong> = 0 is <strong>an</strong> = pr n . Hence two solutions<br />

are <strong>an</strong> = p5 n <strong><strong>an</strong>d</strong> <strong>an</strong> = q(−1) n , <strong><strong>an</strong>d</strong> <strong>an</strong> = p5 n + q(−1) n is <strong>an</strong>other solution.<br />

Choosing p <strong><strong>an</strong>d</strong> q so that a1 = 4 <strong><strong>an</strong>d</strong> a2 = 21 yields p = 5<br />

6<br />

<strong>an</strong> = 5<br />

6 5n + 1<br />

6 (−1)n .<br />

1<br />

<strong><strong>an</strong>d</strong> q = 1<br />

6<br />

. Hence


4. Analyzing the num<strong>be</strong>r of comparisons <strong>an</strong> required to sort a list of 2 n<br />

num<strong>be</strong>rs into ascending order: If there is only one num<strong>be</strong>r, do nothing. Otherwise,<br />

separate the list into two sublists of length 2 n−1 , sort the first sublist<br />

using <strong>an</strong>−1 comparisons, sort the second sublist using <strong>an</strong>−1 comparisons, then<br />

merge the two lists together using 2 n comparisons. Computer scientists refer<br />

to this as the Merge-Sort Algorithm <strong><strong>an</strong>d</strong> our <strong>an</strong>alysis yields the recurrence<br />

relation<br />

a0 = 0, <strong>an</strong> = 2<strong>an</strong>−1 + 2 n (n ≥ 1).<br />

This implies<br />

(1 − 2D)<strong>an</strong> = 2 n ,<br />

(1 − 2D) 2 <strong>an</strong> = 0.<br />

Therefore a homogeneous recurrence relation satisfied by <strong>an</strong> is<br />

<strong>an</strong> − 4<strong>an</strong>−1 + 4<strong>an</strong>−2 = 0 (n ≥ 2).<br />

5. Lemma: <strong>Solution</strong>s to (1 − rD) k <strong>an</strong> are<br />

<strong>an</strong> = r n , <strong>an</strong> = nr n , <strong>an</strong> = n 2 r n , ..., <strong>an</strong> = n k−1 r n .<br />

Proof: We prove this by induction on k. The base case says that r n is a<br />

solution to (1 − rD)<strong>an</strong>. This is true.<br />

Now assume that solutions to (1−rD) k <strong>an</strong> are <strong>an</strong> = r n , nr n , n 2 r n , . . . , n k−1 <strong>an</strong>.<br />

Then these are all solutions to (1 − rD) k+1 <strong>an</strong> = 0 <strong>be</strong>cause<br />

(1 − rD) k+1 <strong>an</strong> = (1 − rD)(1 − rD) k <strong>an</strong> = (1 − rD)0 = 0.<br />

Now consider <strong>an</strong> = n k r n . Then<br />

(1 − rD) k+1 <strong>an</strong> = (1 − rD) k (1 − rD)<strong>an</strong> = (1 − rD) k (<strong>an</strong> − r<strong>an</strong>−1).<br />

<strong>Let</strong>’s calculate <strong>an</strong> − r<strong>an</strong>−<strong>1.</strong> We have<br />

<strong>an</strong> − r<strong>an</strong>−1 = n k r n − r(n − 1) k r n−1 = (n k − (n − 1) k )r n .<br />

2


By the Binomial Theorem,<br />

therefore<br />

For simplicity, we will write<br />

Therefore<br />

(n − 1) k =<br />

k<br />

j=0<br />

j=0<br />

<br />

k<br />

n<br />

j<br />

j (−1) k−j ,<br />

n k − (n − 1) k k−1<br />

<br />

k<br />

= n<br />

j<br />

j (−1) k−j+1 .<br />

n k − (n − 1) k = c0 + c1n + c2n 2 + · · · + ck−1n k−1 .<br />

<strong>an</strong> − r<strong>an</strong>−1 = c0r n + c1nr n + c2n 2 r n + · · · + ck−1n k−1 r n ,<br />

(1 − rD) k+1 <strong>an</strong> = (1 − rD) k (c0r n + c1nr n + c2n 2 r n + · · · + ck−1n k−1 r n ) = 0.<br />

Hence the Lemma is true by the Principle of Mathematical Induction.<br />

6. We return to Problem 4. It satisfies the recurrence relation<br />

a0 = 0, a1 = 2, (1 − 2D) 2 <strong>an</strong> = 0 (n ≥ 2).<br />

Two solutions to (1 − 2D) 2 <strong>an</strong> = 0 are <strong>an</strong> = 2 n <strong><strong>an</strong>d</strong> <strong>an</strong> = n2 n , <strong><strong>an</strong>d</strong> we c<strong>an</strong><br />

combine them to form the solution <strong>an</strong> = p2 n + qn2 n . We need only choose p<br />

<strong><strong>an</strong>d</strong> q so that a0 = 0 <strong><strong>an</strong>d</strong> a1 = 2. Doing this yields p = 0, q = 1, <strong>an</strong> = n2 n .<br />

7. The num<strong>be</strong>r of comparisons required to sort a list of n num<strong>be</strong>rs using<br />

Merge-Sort is ≤ 2n log 2(2n). Reason: <strong>Let</strong> k <strong>be</strong> <strong>an</strong> integer such that<br />

2 k−1 ≤ n < 2 k .<br />

We will pad our list to length 2 k by adding 2 k −n zeros to the end of it. We c<strong>an</strong><br />

sort this list using k2 k comparisons. Given that 2 k ≤ 2n <strong><strong>an</strong>d</strong> k < log 2(2n),<br />

we have k2 k ≤ (log 2(2n))(2n) = 2n log 2(2n).<br />

8. Another sorting algorithm is Bubble Sort. To sort a 1-element list (A1),<br />

do nothing. To sort a 2-element list (A1, A2), set A1 aside, sort the list (A2),<br />

then place A1 in the correct position relative to A<strong>1.</strong> To sort a 3-element<br />

list (A1, A2, A3), set A1 aside, sort the list (A2, A3) into (A ′ 2, A ′ 3), then place<br />

3


A1 in the correct position relative to (A ′ 2, A ′ 3). In general, to sort the list<br />

(A1, A2, . . . , An), set A1 aside, sort the list (A2, . . . , An) into the sorted list<br />

(A ′ 2, . . . , A ′ n), then place A1 in the correct position relative to A ′ 2, . . . , A ′ n.<br />

The algorithm for placing A1 in the correct position is to slide it past all<br />

num<strong>be</strong>rs that are smaller th<strong>an</strong> it (the bubbling operation). This requires at<br />

most n−1 comparisons. Hence if <strong>an</strong> is the worst-case num<strong>be</strong>r of comparisons<br />

required to sort <strong>an</strong> n-element list, then a1 = 0 <strong><strong>an</strong>d</strong> <strong>an</strong> = <strong>an</strong>−1 + (n − 1). The<br />

solution to this recurrence relation is <strong>an</strong> = 0 + 1 + · · · + (n − 1) = 1<br />

2n2 − 1<br />

2n. 9. Consider the recurrence relation<br />

a0 = 5, a1 = 6, <strong>an</strong> = <strong>an</strong>−1 + 6<strong>an</strong>−2 + 2 n + 5 · 3 n + n (n ≥ 2).<br />

We reorg<strong>an</strong>ize this to<br />

<strong>an</strong> − <strong>an</strong>−1 − 6<strong>an</strong>−2 = 2 n + 5 · 3 n + n1 n ,<br />

(1 + 2D)(1 − 3D)<strong>an</strong> = 2 n + 5 · 3 n + n1 n .<br />

By the Lemma in Item 5 above, (1 − 2D)2 n = 0, (1 − 3D)(5 · 3 n ) = 0, <strong><strong>an</strong>d</strong><br />

(1 − D) 2 (n1 n ) = 0. Applying the recurrence relation above by<br />

we obtain<br />

(1 − 2D)(1 − 3D)(1 − D) 2<br />

(1 − 2D)(1 + 2D)(1 − 3D) 2 (1 − D) 2 <strong>an</strong> = 0 (n ≥ 6).<br />

To solve this recurrence relation we need need to provide 6 initial conditions,<br />

a0 through a5. These c<strong>an</strong> <strong>be</strong> produced using the original recurrence relation.<br />

By the Lemma in Item 5 again, solutions to the recurrence relation include<br />

2 n , (−2) n , 3 n , n3 n , 1 n , <strong><strong>an</strong>d</strong> n1 n . A solution involving 6 const<strong>an</strong>ts is<br />

<strong>an</strong> = c12 n + c2(−2) n + c33 n + c4n3 n + c51 n + c6n1 n .<br />

Using the initial conditions<br />

(a0, a1, a2, a3, a4, a5) = (5, 6, 87, 269, 1216, 4082)<br />

we obtain a system of 6 equations in 6 unknowns whose solution is<br />

(c1, c2, c3, c4,5 , c6) = (−1, 176<br />

45<br />

4<br />

, 49<br />

20<br />

, 3, −13,<br />

−1<br />

36 6 ).


Therefore<br />

<strong>an</strong> = −2 n + 176<br />

45 (−2)n + 49<br />

20 3n + 3n3 n − 13<br />

36 1n − 1<br />

6 n1n .<br />

10. A formula for <strong>an</strong> = 1 2 + 3 2 + · · · + (2n − 1) 2 : This satisfies the recurrence<br />

relation<br />

<strong>an</strong> = 1, <strong>an</strong> = <strong>an</strong>−1 + (2n − 1) 2 (n ≥ 2).<br />

We c<strong>an</strong> reorg<strong>an</strong>ize this to<br />

<strong>an</strong> = 1, (1 − D)<strong>an</strong> = 4n 2 − 4n + <strong>1.</strong><br />

Applying (1 − D) 3 to both sides yields<br />

(1 − D) 4 <strong>an</strong> = 0.<br />

<strong>Solution</strong>s to this equation include 1, n, n 2 , n 3 . Setting<br />

<strong><strong>an</strong>d</strong> using the 4 initial conditions<br />

we obtain<br />

This yields<br />

<strong>an</strong> = c0 + c1n + c2n 2 + c3n 3<br />

(a1, a2, a3, a4) = (1, 10, 35, 84)<br />

(c0, c1, c2, c3) = (0, − 1 4<br />

, 0,<br />

3 3 ).<br />

1 2 + 3 2 + · · · + (2n − 1) 2 = 4n3 − n<br />

3<br />

= n(2n − 1)(2n + 1)<br />

.<br />

3<br />

1<strong>1.</strong> A formula for the Fibonacci num<strong>be</strong>rs 1, 2, 3, 5, 8, ... : The recurrence<br />

relation is<br />

<strong>an</strong> = <strong>an</strong>−1 + <strong>an</strong>−2 (n ≥ 2),<br />

(1 − D − D 2 )<strong>an</strong> = 0.<br />

5


Factoring 1 − D − D2 into (1 − rD)(1 − sD) yields r + s = −1 <strong><strong>an</strong>d</strong> rs = −<strong>1.</strong><br />

. Setting<br />

Solving the system of equations yields r = −1−√ 5<br />

2<br />

<strong>an</strong> = p<br />

<br />

<strong><strong>an</strong>d</strong> solving for p <strong><strong>an</strong>d</strong> q yields<br />

<strong>an</strong> =<br />

<br />

−1 − √ n 5<br />

+ q<br />

2<br />

<br />

<strong><strong>an</strong>d</strong> s = −1+√ 5<br />

2<br />

−1 + √ 5<br />

2<br />

n<br />

−1 − √ n+1 <br />

5 −1 +<br />

+<br />

2<br />

√ n+1 5<br />

.<br />

2<br />

6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!