Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Section 6.1 Recurrence Relations. 2 Recursive definition of a sequence Specify one or more initial terms Specify rule for obtaining subsequent terms.

Similar presentations


Presentation on theme: "1 Section 6.1 Recurrence Relations. 2 Recursive definition of a sequence Specify one or more initial terms Specify rule for obtaining subsequent terms."— Presentation transcript:

1 1 Section 6.1 Recurrence Relations

2 2 Recursive definition of a sequence Specify one or more initial terms Specify rule for obtaining subsequent terms from preceding terms We can use such definitions to solve counting problems that cannot easily be solved using techniques from chapter 4

3 3 Recurrence Relations When rule for finding subsequent terms from previous is used for solving counting problems, we call the rule a recurrence relation Stated more formally: A recurrence relation for the sequence {a n } is an equation that expresses a n in terms of one or more of the previous terms of the sequence a 0, a 1, … a n-1 for all integers n with n  n 0, where n 0 is non-negative

4 4 Solutions A sequence whose terms satisfy a recurrence relation is called a solution of the recurrence relation Example 1: Let {a n } be a sequence that satisfies the recurrence relation a n = a n-1 - a n-2 for n = 2, 3, 4 … –Suppose a 0 =3 and a 1 =5. What are a 2 and a 3 ? –a 2 = a 1 - a 0 = 2, a 3 = a 2 - a 1 = -3

5 5 Example 2 Find the first 5 terms of a sequence defined as follows: –recurrence relation: an = na n-1 + n 2 a n-2 –initial condition: a 0 = 1, a 1 = 1 Applying the rules: a 2 = 2(1) + (2) 2 1 = 6 a 3 = 3(6) + (3) 2 1 = 27 a 4 = 4(27) + (4) 2 6 = 204

6 6 Example 2 Determine whether {an} is a solution of the recurrence relation a n = 2a n-1 -a n-2 for n=2, 3, 4 … where a n = 3n if a n = 3n, then for n  2: 2a n-1 - a n-2 = 2[3(n-1)] - 3(n-2) = 2(3n - 3) - 3n + 6 = 6n - 6 - 3n + 6 = 3n So {a n }, where a n = 3n, is a solution

7 7 Example 3 Determine whether {a n } is a solution of the recurrence relation a n = 2a n-1 -a n-2 for n=2, 3, 4 … where a n = 2 n : –By this rule, a 0 = 2 0 = 1; a 1 = 2 1 = 2; a 2 = 2 2 = 4 –Applying original recurrence relation: a n = 2a n-1 - a n-2 a 2 = 2a 1 - a 0 substituting actual values: 4 = 2*2 - 1 4 = 3 not true, so {a n } where a n = 2 n is not a solution

8 8 Summary of Recurrence Relations Initial conditions for a sequence specify terms that precede the first term where recurrence relation takes effect Recurrence relation & initial conditions uniquely determine a sequence, providing a recursive definition of the sequence Any term of a sequence can be found from initial conditions using recurrence relation a sufficient number of times (but there are better ways for computing certain classes of sequences)

9 9 Example 4: modeling with recurrence relations Suppose you invest $1,000 in a money market account that yields 7% per year (wow!) with interest compounded annually (oh). How much money will be in the account in 25 years? –Let P n = amount in account after n years –Since P n = amount after n-1 years + interest in nth year, {P n } satisfies the recurrence relation: P n = P n-1 +.07(P n-1 ) = 1.07(P n-1 )

10 10 Example 4 continued We are given P 0 = 1000; so P 1 = (1.07)(P 0 ) P 2 = (1.07)(P 1 ) = (1.07)(1.07)(P 0 ) = (1.07) 2 (P 0 ) P 3 = (1.07)(P 2 ) = (1.07)(1.07)(1.07)(P 0 ) = (1.07) 3 (P 0 ) … thus P n = 1.07(P n-1 ) = (1.07) n P( 0 ) so if n=25, P 25 = (1.07) 25 (1000) = $5,427.43

11 11 Example 5: is Fibonacci Italian for “bunny”? Suppose 2 baby rabbits (aw!), a buck and a doe, are placed on an uninhabited island They don’t breed until they’re 2 months old (we don’t know what they’re up to before that) After they are 2 months old, each pair of rabbits produces another pair each month How many rabbits are there after n months, assuming no rabbits die?

12 12 Example 5 continued Let f n = number of rabbit pairs after n months At end of first month, f 1 = 1 (too young to breed) At end of second month, f 2 = 1 (allow for gestation time!)

13 13 Example 5 continued To find the number of pairs after n months, add the number from the previous month (f n-1 ) to the number of newborn pairs (f n-2, since each newborn pair comes from a pair at least 2 months old) So {f n } satisfies the recurrence relation: f n = f n-1 + f n-2 for n  3 with f 1 = f 2 = 1 So the number of pairs of bunnies after n months is the nth Fibonacci number

14 14 Example 6: how long before the world ends? The Towers of Hanoi is an ancient puzzle, with the following characteritics: –You start with 3 pegs, one of which has a stack of disks on it (bird’s-eye view shown) –The disks are stacked by size, with the largest on the bottom and the smallest on top

15 15 Example 6 continued The goal is to move all disks to a second peg in order of size –Only one disk may be moved at a time –A larger disk can never be placed on top of a smaller disk Let H n = number of moves needed to solve a puzzle with n disks; set up a recurrence relation for sequence {H n }

16 16 Example 6 continued Starting with n disks on peg 1, we can transfer n-1 disks to peg 3 using H n-1 moves –It takes 1 move to transfer the largest disk to peg 2 –Then we can move the n-1 disks from peg 3 to peg 2 using another H n-1 additional moves –So H n = 2(H n-1 ) + 1 with initial condition H 1 = 1 (one disk can be transferred in one move)

17 17 Example 6 continued We can use an iterative approach to solve the relation: Hn = 2(H n-1 ) + 1 = 2 (2H n-2 + 1) = 2 2 H n-2 + 2 + 1 = 2 2 (2H n-3 + 1) + 2 + 1 = 2 3 H n-3 + 2 2 + 2 + 1 … = 2 n-1 H 1 + 2 n-2 + 2 n-3 + … + 2 + 1 = 2 n-1 + 2 n-2 + 2 n-3 + … + 2 + 1 (because H 1 = 1) = 2 n - 1 So for 5 disks, it takes 2 5 -1 or 31 moves to solve the puzzle

18 18 Example 6 continued The ancient legend says that the monks of Hanoi must solve a puzzle with 64 disks, taking 1 second to move each disk, and when they are finished the world will end. How long before they’re done? –2 64 - 1 = 18,446,744,073,709,551,615 seconds –At 60 seconds per minute, 60 minutes per hour, 24 hours per day and 365.25 days per year, there are 31,557,600 seconds in a year –So the world should end something over 500 billion years since they started (but we don’t know when they started …)

19 19 Example 7 Find a recurrence relation and give initial conditions for the number of bit strings of length n that do not have consecutive 0s. How many such strings are there of length 5? –Let a n denote the number of bit strings of length n that do not have 2 consecutive 0s; to obtain recurrence relation for {a n }, note that: by the sum rule, the # of bit strings of length n that do not have 2 consecutive 0s = # ending with 0 + # ending with 1 assuming n  3, bit string has at least 3 bits

20 20 Example 7 continued Bit strings of length n ending with 1 that do not have 2 consecutive 0s are precisely the bit strings of length n- 1 with no 2 consecutive 0s and with a 1 added to the end - there are a n-1 such bit strings Bit strings of length n ending with a 0 must have a 1 as their (n-1)th bit (otherwise there’d be 2 0s at the end) - bit strings of length n, ending with 0, without consecutive 0s, are precisely those bit strings of length n-2 with 10 appended to them - there are a n-2 such strings

21 21 Example 7 continued So we conclude: a n = a n-1 + a n-2 for n  3 Initial conditions: a 1 = 2 since bit strings of length 1 have no consecutive bits and there are 2 possible values a 2 = 3 since valid strings are 01, 11, 10 a 5 = a 4 + a 3 ; a 4 = a 3 + a 2 ; a 3 = a 2 + a 1 –a 3 = 5; a 4 = 8; so a 5 = 13

22 22 Catalan numbers The number of ways to parenthesize the product of n+1 numbers to specify the order of multiplication is represented by C n For example, C 3 = 5; since n=3, there are 4 terms: x 0 * x 1 * x 2 * x 3 and 5 ways to parenthesize: (x 0 * x 1 ) * (x 2 * x 3 ), ((x 0 * x 1 ) * x 2 ) * x 3, (x 0 * (x 1 * x 2 )) * x 3, x 0 * ((x 1 * x 2 ) * x 3 ) and x 0 * (x 1 * (x 2 * x 3 ))

23 23 Catalan numbers However we insert parentheses, one multiplication operator remains outside all parentheses (and is therefore the last operation performed) The final operator appears between some pair of the n+1 numbers - say x k and x k+1

24 24 Catalan numbers There are C k C n-k-1 ways to insert parentheses to determine order of multiplication of n-1 numbers when the final operator appears between x k and x k+1 because there are C k ways to insert parentheses in x 0 *x 1 *…*x k and C n-k-1 ways to insert parentheses in x k+1 *x k+2 *… *x n

25 25 Catalan numbers Since the final operator can appear between any 2 of the n+1 numbers, it follows that: C n = C 0 C n-1 + C 1 C n-2 + … + C n-2 C 1 + C n-1 C 0 = C k C n-k-1 with initial conditions C 0 =1, C 1 =1 It can be shown that C n = C(2n,n)/(n+1)

26 26 Section 5.1 Recurrence Relations


Download ppt "1 Section 6.1 Recurrence Relations. 2 Recursive definition of a sequence Specify one or more initial terms Specify rule for obtaining subsequent terms."

Similar presentations


Ads by Google