Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week #10 – 28/30 October and 1 November 2002 Prof. Marie desJardins

Similar presentations


Presentation on theme: "Week #10 – 28/30 October and 1 November 2002 Prof. Marie desJardins"— Presentation transcript:

1 Week #10 – 28/30 October and 1 November 2002 Prof. Marie desJardins
CMSC 203 / 0201 Fall 2002 Week #10 – 28/30 October and 1 November 2002 Prof. Marie desJardins

2 TOPICS Recurrence relations and solutions
Divide-and-conquer recurrences

3 MON 10/28 RECURRENCE RELATIONS (5.1)

4 Concepts/Vocabulary Recurrence relations
Solution / solution sequence Initial conditions Useful examples: compound interest, bunny rabbits / Fibonacci, Tower of Hanoi, Catalan numbers

5 Examples Exercise 5.1.4: For each of the following sequences, find a recurrence relation satisfied by this sequence: (b) an = 2n (d) an = 5n (f) an = n2 + n (g) an = n + (-1)n

6 Examples II Save early and often: Exercise 5.1.6: A person deposits $1000 in an account that yields 9% interest compounded yearly. (a) Set up a recurrence relation for the amount in the acount at the end of n years. (b) Find an explicit formula for the amount in the account at the end of n years. (c) How much money will the account contain after 100 years?

7 Examples III Exercise : Use mathematical induction to verify the formula derived in Example 5 for the number of moves required to complete the Tower of Hanoi puzzle: Hn = 2n - 1 Catalan numbers: Example (p. 315): Find a recurrence relation for Cn, the number of ways to parenthesize the product of n+1 numbers, x0x1…xn. Cn = k=0n-1 Ck Cn-k-1 C0 = C1 = 1

8 Examples IV Exercise 5.23: A ternary string contains only 0s, 1s, and 2s. (a) Find a recurrence relation for the number of ternary strings that do not contain two consecutive 0s. (b) What are the initial conditions? (c) How many ternary strings of length six do not contain two consecutive 0s? Exercise 5.25: (a) Find a recurrence relation for the number of ternary strings that do not contain two consecutive 0s or two consecutive 1s. (c) How many ternary strings of length six do not contain two consecutive 0s or two consecutive ones?

9 WED 10/30 - FRI 11/1 DIVIDE-AND-CONQUER (5.3)
** HOMEWORK #7 DUE ** ** FEEDBACK SESSION TODAY **

10 Concepts / Vocabulary Divide-and-conquer recurrence relations
f(n) = a f(n/b) + g(n)

11 Examples Exercise 5.3.7: Suppose that f(n) = f(n/3) + 1 when n is divisible by 3, and f(1) = 1. Find (a) f(3) (b) f(27) (c) f(729) = f(36) Fast multiplication (Example 5.3.3, p. 333) ab = (22n + 2n) A1B1 + 2n(A1-A0)(B0-B1) + (2n+1)A0B0 Exercise 5.3.3: Multiply (1110)2 and (1010)2 using the fast multiplication algorithm. Exercise 5.3.4: Express the fast multiplication algorithm in pseudocode.

12 Examples II Exercises 5.3.14-16:
Suppose that there are n = 2k teams in an elimination tournament, where there are n/2 games in the first round, with the n/2 = 2k-1 winners playing in the second round, and so on. Develop a recurrence relation for the number of rounds in the tournament. How many rounds are there when there are 32 teams? Solve the recurrence relation for the number of rounds in the tournament.

13 Examples III Theorem 1: for a recurrence relation f(n) = a f(n/b) + c whenever b|n, a1, integer b>1, and real c>0, f(n) = O(nlogba) if a > 1 and f(n) = O(log n) if a=1.


Download ppt "Week #10 – 28/30 October and 1 November 2002 Prof. Marie desJardins"

Similar presentations


Ads by Google