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

Slides:



Advertisements
Similar presentations
Analysis of Algorithms II
Advertisements

Week 6 - Wednesday CS322.
Advanced Counting Techniques
Chapter 8 Recursion. 8.1 Recursively Defined Sequences.
Chapter Recurrence Relations
Fall 2002CMSC Discrete Structures1 Now it’s Time for… RecurrenceRelations.
Chapter 6 Advanced Counting 6.1 Recurrence Relations.
Discrete Mathematics Math 6A Homework 9 Solution.
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
Recursion Lecture 18: Nov 18.
CS 2210 (22C:19) Discrete Structures Advanced Counting
Kavita Math231 Recursion and Iteration. Kavita Math231 We use Recursion when we have to perform a complex task that can be broken into the several subtasks.
Recursion.
Recursion Lecture 17: Nov 11. Quiz int hello(int n) { if (n==0) return 0; else printf(“Hello World %d\n”,n); hello(n-1); } 1.What would the program do.
6.Advanced Counting Techniques 1 Copyright M.R.K. Krishna Rao 2003 Ch 6. Recurrence Relations A recurrence relation for the sequence {a n } is an equation.
Chapter 8 With Question/Answer Animations 1. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Analysis of Recursive Algorithms October 29, 2014
Copyright © Cengage Learning. All rights reserved.
Recursively Defined Sequences Lecture 35 Section 8.1 Wed, Mar 23, 2005.
Applied Discrete Mathematics Week 9: Relations
Advanced Counting Techniques
Data Structures Using C++ 2E Chapter 6 Recursion.
Data Structures Using C++ 2E Chapter 6 Recursion.
Department of Computer Science Data Structures Using C++ 2E Chapter 6: Recursion Learn about recursive Definitions Algorithms Functions Explore the base.
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
The importance of sequences and infinite series in calculus stems from Newton’s idea of representing functions as sums of infinite series.  For instance,
13.2 Recursive Definitions Objective 1) Provide the recursive definition for sequences; 2) Identify the type of a sequence from a recursive definition.
4.6.2 Exponential generating functions
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
Ch. 7: Advanced Counting Techniques
Recurrence Relation. Outline  What is a recurrence relation ?  Solving linear recurrence relations  Divide-and-conquer algorithms and recurrence relations.
CSE 2813 Discrete Structures Recurrence Relations Section 6.1.
Module #20 - Recurrences 1 Ch. 7 Recurrence Relations Rosen 6 th ed., §§7.1.
R. Johnsonbaugh Discrete Mathematics 7 th edition, 2009 Chapter 7 Recurrence Relations Instructor Tianping Shuai.
15.1 CompSci 102© Michael Frank Today’s topics Recurrence relationsRecurrence relations –Stating recurrences –LiHoReCoCo Reading: Sections Reading:
Module #17: Recurrence Relations Rosen 5 th ed., §
Sequences and Summations
Chapter 7 Advance Counting Techniques. Content Recurrence relations Generating function The principle of inclusion-exclusion.
Section 2.4. Section Summary Sequences. Examples: Geometric Progression, Arithmetic Progression Recurrence Relations Example: Fibonacci Sequence Summations.
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Recurrence.
Chapter 8 With Question/Answer Animations. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Complexity 20-1 Complexity Andrei Bulatov Parallel Arithmetic.
Recursion Review: A recursive function calls itself, but with a smaller problem – at least one of the parameters must decrease. The function uses the results.
Recurrence Relation Models
after UCI ICS/Math 6A, Summer AdvancedCounting -1 Recurrence Relations (RRs) A “Recurrence Relation”
Sequences and Summations Section 2.4. Section Summary Sequences. – Examples: Geometric Progression, Arithmetic Progression Recurrence Relations – Example:
Discrete Mathematics Recurrence Relations Chapter 5 R. Johnsonbaugh
22C:19 Discrete Math Advanced Counting Fall 2010 Sukumar Ghosh.
CHAPTER TWO RECURRENCE RELATION
Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.
Mathematical Induction Section 5.1. Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If.
Discrete Mathematics Lecture # 22 Recursion.  First of all instead of giving the definition of Recursion we give you an example, you already know the.
Recursively Defined Sequences Lecture 40 Section 8.1 Wed, Apr 11, 2007.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Advanced Counting Techniques
Discrete Math For Computing II. Contact Information B. Prabhakaran Department of Computer Science University of Texas at Dallas Mail Station EC 31, PO.
CMSC Discrete Structures
Advanced Counting Techniques
Applied Discrete Mathematics Week 11: Relations
COMP108 Algorithmic Foundations Divide and Conquer
Introduction to Recurrence Relations
Copyright © Cengage Learning. All rights reserved.
CS 2210 Discrete Structures Advanced Counting
CMSC Discrete Structures
Applied Discrete Mathematics Week 7: Computation
1A Recursively Defined Functions
CMSC Discrete Structures
Recurrence Relations Discrete Structures.
Chapter 7 Advanced Counting Techniques
ICS 253: Discrete Structures I
Presentation transcript:

1 Section 6.1 Recurrence Relations

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 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 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 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 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 n + 6 = 3n So {a n }, where a n = 3n, is a solution

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* = 3 not true, so {a n } where a n = 2 n is not a solution

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 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 (P n-1 ) = 1.07(P n-1 )

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 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 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 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 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 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 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 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 (2H n-3 + 1) = 2 3 H n … = 2 n-1 H n n-3 + … = 2 n n n-3 + … (because H 1 = 1) = 2 n - 1 So for 5 disks, it takes or 31 moves to solve the puzzle

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? – = 18,446,744,073,709,551,615 seconds –At 60 seconds per minute, 60 minutes per hour, 24 hours per day and 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 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 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 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 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 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 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 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 Section 5.1 Recurrence Relations