15.1 CompSci 102© Michael Frank Today’s topics Recurrence relationsRecurrence relations –Stating recurrences –LiHoReCoCo Reading: Sections 6.1-6.2Reading:

Slides:



Advertisements
Similar presentations
Week 6 - Wednesday CS322.
Advertisements

Chapter Recurrence Relations
Fall 2002CMSC Discrete Structures1 Now it’s Time for… RecurrenceRelations.
Chapter 6 Advanced Counting 6.1 Recurrence Relations.
section 6.2 Solving Recurrence Relations
1 Recursive Algorithm Analysis Dr. Ying Lu RAIK 283: Data Structures & Algorithms September 13, 2012.
CS 2210 (22C:19) Discrete Structures Advanced Counting
1 Copyright M.R.K. Krishna Rao Solving Recurrence Relations Steps for solving a linear homogeneous recurrence relation of degree 2 : Step #1.
Recursion Sections 7.1 and 7.2 of Rosen Fall 2008 CSCE 235 Introduction to Discrete Structures Course web-page: cse.unl.edu/~cse235 Questions:
1 Section 6.1 Recurrence Relations. 2 Recursive definition of a sequence Specify one or more initial terms Specify rule for obtaining subsequent terms.
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.
1 Linear Recurrence Relations Part I Jorge Cobb The University of Texas at Dallas.
Applied Discrete Mathematics Week 9: Relations
7.2 Solving Recurrence Relations. Definition 1 (p. 460)- LHRR-K Def: A linear homogeneous recurrence relations of degree k with constant coefficients.
Advanced Counting Techniques
Jessie Zhao Course page: 1.
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
Chap. 7 (c) , Michael P. Frank1 Chapter 7: Advanced Counting Techniques.
Copyright © Cengage Learning. All rights reserved. CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
4.6.2 Exponential generating functions
Chapter 8 With Question/Answer Animations 1. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
14.1 CompSci 102© Michael Frank Today’s topics Recurrence relationsRecurrence relations –Stating recurrences –LiHoReCoCo –Divide & conquer –Master’s method.
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.
Module #17: Recurrence Relations Rosen 5 th ed., §
Solving Second-Order Recursive Relations Lecture 36 ½ Section 8.3 Wed, Apr 19, 2006.
RECURRENCE Sequence Recursively defined sequence
Based on Rosen, Discrete Mathematics & Its Applications, 5e Prepared by (c) Michael P. Frank Modified by (c) Haluk Bingöl 1/18 Module.
Chapter 7 Advance Counting Techniques. Content Recurrence relations Generating function The principle of inclusion-exclusion.
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.
after UCI ICS/Math 6A, Summer AdvancedCounting -1 Recurrence Relations (RRs) A “Recurrence Relation”
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Module #20 - Recurrences Solving Recurrences Rosen 6 th ed., §7.2.
Discrete Mathematics Recurrence Relations Chapter 5 R. Johnsonbaugh
CHAPTER TWO RECURRENCE RELATION
7.2 Solving Linear Recurrence Relations Some of these recurrence relations can be solved using iteration or some other ad hoc technique. However, one important.
CSE 2813 Discrete Structures Solving Recurrence Relations Section 6.2.
Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.
ADVANCED ALGORITHMS REVIEW OF ANALYSIS TECHNIQUES (UNIT-1)
Recurrence Relations. Outline Recurrence relationsSolving recurrence relationsRecurrence and Divide-and-conquer algorithmsGenerating functions
CS 312: Algorithm Analysis Lecture #7: Recurrence Relations a.k.a. Difference Equations Slides by: Eric Ringger, with contributions from Mike Jones, Eric.
RECURRENCE Sequence Recursively defined sequence
Mathematical Analysis of Recursive Algorithm CSG3F3 Lecture 7.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
Solving Linear Homogeneous Recurrence Relations ICS 6D Sandy Irani.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
Discrete Math For Computing II. Contact Information B. Prabhakaran Department of Computer Science University of Texas at Dallas Mail Station EC 31, PO.
CSG523/ Desain dan Analisis Algoritma
CSG523/ Desain dan Analisis Algoritma
CMSC Discrete Structures
Advanced Counting Techniques
Modeling with Recurrence Relations
A0=0 a1=2 an a2=6 an-1 a3=12 a4=20 a2 a1 a0.
Introduction to Recurrence Relations
UNIT-6 Recurrence Relations
Module #17: Recurrence Relations
Module #17: Recurrence Relations
CS 2210 Discrete Structures Advanced Counting
CMSC Discrete Structures
CMSC Discrete Structures
Recurrence Relations Discrete Structures.
Chapter 7 Advanced Counting Techniques
Recurrence Relations Rosen 5th ed., §6.2 5/22/2019
ICS 253: Discrete Structures I
Presentation transcript:

15.1 CompSci 102© Michael Frank Today’s topics Recurrence relationsRecurrence relations –Stating recurrences –LiHoReCoCo Reading: Sections Reading: Sections UpcomingUpcoming –Graphs

15.2 CompSci 102© Michael Frank §6.1: Recurrence Relations A recurrence relation (R.R., or just recurrence) for a sequence {a n } is an equation that expresses a n in terms of one or more previous elements a 0, …, a n−1 of the sequence, for all n≥n 0.A recurrence relation (R.R., or just recurrence) for a sequence {a n } is an equation that expresses a n in terms of one or more previous elements a 0, …, a n−1 of the sequence, for all n≥n 0. –I.e., just a recursive definition, without the base cases. A particular sequence (described non-recursively) is said to solve the given recurrence relation if it is consistent with the definition of the recurrence.A particular sequence (described non-recursively) is said to solve the given recurrence relation if it is consistent with the definition of the recurrence. –A given recurrence relation may have many solutions.

15.3 CompSci 102© Michael Frank Recurrence Relation Example Consider the recurrence relationConsider the recurrence relation a n = 2a n−1 − a n−2 (n≥2). Which of the following are solutions? a n = 3n a n = 2 nWhich of the following are solutions? a n = 3n a n = 2 n a n = 5 Yes No

15.4 CompSci 102© Michael Frank Example Applications Recurrence relation for growth of a bank account with P% interest per given period:Recurrence relation for growth of a bank account with P% interest per given period: M n = M n−1 + (P/100)M n−1 Growth of a population in which each organism yields 1 new one every period starting 2 time periods after its birth.Growth of a population in which each organism yields 1 new one every period starting 2 time periods after its birth. P n = P n−1 + P n−2 (Fibonacci relation)

15.5 CompSci 102© Michael Frank Solving Compound Interest RR M n = M n−1 + (P/100)M n−1M n = M n−1 + (P/100)M n−1 = (1 + P/100) M n−1 = r M n−1 (let r = 1 + P/100) = r (r M n−2 ) = r·r·(r M n−3 )…and so on to… = r n M 0

15.6 CompSci 102© Michael Frank Tower of Hanoi Example Problem: Get all disks from peg 1 to peg 2.Problem: Get all disks from peg 1 to peg 2. –Rules: (a) Only move 1 disk at a time. –(b) Never set a larger disk on a smaller one. Peg #1Peg #2Peg #3

15.7 CompSci 102© Michael Frank Hanoi Recurrence Relation Let H n = # moves for a stack of n disks.Let H n = # moves for a stack of n disks. Here is the optimal strategy:Here is the optimal strategy: –Move top n−1 disks to spare peg. (H n−1 moves) –Move bottom disk. (1 move) –Move top n−1 to bottom disk. (H n−1 moves) Note that: H n = 2H n−1 + 1Note that: H n = 2H n−1 + 1 –The # of moves is described by a Rec. Rel.

15.8 CompSci 102© Michael Frank Solving Tower of Hanoi RR H n = 2 H n−1 + 1 = 2 (2 H n−2 + 1) + 1 = 2 2 H n− = 2 (2 H n−2 + 1) + 1 = 2 2 H n− = 2 2 (2 H n−3 + 1) = 2 3 H n− = 2 2 (2 H n−3 + 1) = 2 3 H n− … = 2 n−1 H n−2 + … = 2 n−1 H n−2 + … = 2 n−1 + 2 n−2 + … (since H 1 = 1) = 2 n−1 + 2 n−2 + … (since H 1 = 1) = = 2 n − 1 = 2 n − 1

15.9 CompSci 102© Michael Frank Another R.R. Example Find a R.R. & initial conditions for the number of bit strings of length n without two consecutive 0s.Find a R.R. & initial conditions for the number of bit strings of length n without two consecutive 0s. We can solve this by breaking down the strings to be counted into cases that end in 0 and in 1.We can solve this by breaking down the strings to be counted into cases that end in 0 and in 1. –For each ending in 0, the previous bit must be 1, and before that comes any qualifying string of length n−2. –For each string ending in 1, it starts with a qualifying string of length n−1. Thus, a n = a n−1 + a n−2. (Fibonacci recurrence.)Thus, a n = a n−1 + a n−2. (Fibonacci recurrence.) –The initial conditions are: a 0 = 1 (ε), a 1 = 2 (0 and 1). 10(n−2 bits)1(n−1 bits)

15.10 CompSci 102© Michael Frank Yet another R.R. example… Give a recurrence (and base cases) for the number of n-digit decimal strings containing an even number of 0 digits.Give a recurrence (and base cases) for the number of n-digit decimal strings containing an even number of 0 digits. Can break down into the following cases:Can break down into the following cases: –Any valid string of length n−1 digits, with any digit 1-9 appended. –Any invalid string of length n−1 digits, + a 0. a n = 9a n−1 + (10 n−1 − a n−1 ) = 8a n− n−1. a n = 9a n−1 + (10 n−1 − a n−1 ) = 8a n− n−1. –Base cases: a 0 = 1 (ε), a 1 = 9 (1-9).

15.11 CompSci 102© Michael Frank §6.2: Solving Recurrences A linear homogeneous recurrence of degree k with constant coefficients (“k-LiHoReCoCo”) is a rec. rel. of the form a n = c 1 a n−1 + … + c k a n−k, where the c i are all real, and c k ≠ 0.A linear homogeneous recurrence of degree k with constant coefficients (“k-LiHoReCoCo”) is a rec. rel. of the form a n = c 1 a n−1 + … + c k a n−k, where the c i are all real, and c k ≠ 0. The solution is uniquely determined if k initial conditions a 0 …a k−1 are provided.The solution is uniquely determined if k initial conditions a 0 …a k−1 are provided. General Solution Schemas

15.12 CompSci 102© Michael Frank Solving LiHoReCoCos Basic idea: Look for solutions of the form a n = r n, where r is a constant.Basic idea: Look for solutions of the form a n = r n, where r is a constant. This requires solving the characteristic equation: r n = c 1 r n−1 + … + c k r n−k, i.e., r k − c 1 r k−1 − … − c k = 0This requires solving the characteristic equation: r n = c 1 r n−1 + … + c k r n−k, i.e., r k − c 1 r k−1 − … − c k = 0 The solutions r to this equation are called the characteristic roots of the LiHoReCoCo.The solutions r to this equation are called the characteristic roots of the LiHoReCoCo. –They can yield an explicit formula for the sequence. (rearrange & × by r k−n )

15.13 CompSci 102© Michael Frank Solving 2-LiHoReCoCos Consider an arbitrary 2-LiHoReCoCo: a n = c 1 a n−1 + c 2 a n−2Consider an arbitrary 2-LiHoReCoCo: a n = c 1 a n−1 + c 2 a n−2 It has the characteristic equation (C.E.): r 2 − c 1 r − c 2 = 0It has the characteristic equation (C.E.): r 2 − c 1 r − c 2 = 0 Theorem 1: If the CE has 2 roots r 1 ≠r 2, then the solutions to the RR are given by: a n = α 1 r 1 n + α 2 r 2 n for n≥0 for any and all constants α 1, α 2.Theorem 1: If the CE has 2 roots r 1 ≠r 2, then the solutions to the RR are given by: a n = α 1 r 1 n + α 2 r 2 n for n≥0 for any and all constants α 1, α 2. Special case: a n = r 1 n and a n = r 2 n are, of course, solutions.

15.14 CompSci 102© Michael Frank Example Solve the recurrence a n = a n−1 + 2a n−2 given the initial conditions a 0 = 2, a 1 = 7.Solve the recurrence a n = a n−1 + 2a n−2 given the initial conditions a 0 = 2, a 1 = 7. Solution: Use theorem 1:Solution: Use theorem 1: –We have c 1 = 1, c 2 = 2 –The characteristic equation is: r 2 − r − 2 = 0 –Solve it: –so, r = 2 or r = −1. –So, a n = α 1 2 n + α 2 (−1) n. (Using the quadratic formula here.)

15.15 CompSci 102© Michael Frank Example Continued… To find α 1 and α 2, just solve the equations for the initial conditions a 0 and a 1 : a 0 = 2 = α α 2 (−1) 0To find α 1 and α 2, just solve the equations for the initial conditions a 0 and a 1 : a 0 = 2 = α α 2 (−1) 0 a 1 = 7 = α α 2 (−1) 1 Simplifying, we have the pair of equations: 2 = α 1 + α 2 7 = 2α 1 − α 2 which we can solve easily by substitution: α 2 = 2−α 1 ; 7 = 2α 1 − (2−α 1 ) = 3α 1 − 2; 9 = 3α 1 ; α 1 = 3; α 2 = −1. Using α 1 and α 2, our final answer is: a n = 3·2 n − (−1) nUsing α 1 and α 2, our final answer is: a n = 3·2 n − (−1) n Check: {a n≥0 } = 2, 7, 11, 25, 47, 97 …

15.16 CompSci 102© Michael Frank Proof of Theorem 1 Proof that a n = α 1 r 1 n +α 2 r 2 n is always a solution:Proof that a n = α 1 r 1 n +α 2 r 2 n is always a solution: –We know r 1 2 = c 1 r 1 + c 2 and r 2 2 = c 1 r 2 + c 2. –Now we can show the proposed sequence satisfies the recurrence a n = c 1 a n−1 + c 2 a n−2 : c 1 a n−1 + c 2 a n−2 = c 1 (α 1 r 1 n−1 +α 2 r 2 n−1 ) + c 2 (α 1 r 1 n−2 +α 2 r 2 n−2 ) = α 1 r 1 n−2 (c 1 r 1 +c 2 ) + α 2 r 2 n−2 (c 1 r 2 +c 2 ) = α 1 r 1 n−2 r α 2 r 2 n−2 r 2 2 = α 1 r 1 n + α 2 r 2 n = a n. □ Can complete the proof by showing that for any initial conditions, we can find corresponding α’s.Can complete the proof by showing that for any initial conditions, we can find corresponding α’s. –But it turns out this goes through only if r 1 ≠r 2.

15.17 CompSci 102© Michael Frank The Case of Degenerate Roots Now, what if the C.E. r 2 − c 1 r − c 2 = 0 has only 1 root r 0 ?Now, what if the C.E. r 2 − c 1 r − c 2 = 0 has only 1 root r 0 ? Theorem 2: Then, a n = α 1 r 0 n + α 2 nr 0 n, for all n≥0, for some constants α 1, α 2.Theorem 2: Then, a n = α 1 r 0 n + α 2 nr 0 n, for all n≥0, for some constants α 1, α 2.

15.18 CompSci 102© Michael Frank Degenerate Root Example Solve a n = 6a n−1 −9a n−2 with a 0 =1, a 1 =6.Solve a n = 6a n−1 −9a n−2 with a 0 =1, a 1 =6. The C.E. is: r 2 −6r+9=0.The C.E. is: r 2 −6r+9=0. –Note that b 2 −4ac = (−6) 2 −4·1·9 = 36−36 = 0. Therefore, there is only one root, namely −b/2a = −(−6)/2 = 3.Therefore, there is only one root, namely −b/2a = −(−6)/2 = 3.

15.19 CompSci 102© Michael Frank k-LiHoReCoCos Consider a k-LiHoReCoCo:Consider a k-LiHoReCoCo: It’s C.E. is:It’s C.E. is: Theorem 3: If this has k distinct roots r i, then the solutions to the recurrence are of the form:Theorem 3: If this has k distinct roots r i, then the solutions to the recurrence are of the form: for all n≥0, where the α i are constants.

15.20 CompSci 102© Michael Frank Degenerate k-LiHoReCoCos Suppose there are t roots r 1,…,r t with multiplicities m 1,…,m t. Then:Suppose there are t roots r 1,…,r t with multiplicities m 1,…,m t. Then: for all n≥0, where all the α are constants.

15.21 CompSci 102© Michael Frank LiNoReCoCos Linear nonhomogeneous RRs with constant coefficients may (unlike LiHoReCoCos) contain some terms F(n) that depend only on n (and not on any a i ’s). General form:Linear nonhomogeneous RRs with constant coefficients may (unlike LiHoReCoCos) contain some terms F(n) that depend only on n (and not on any a i ’s). General form: a n = c 1 a n−1 + … + c k a n−k + F(n) The associated homogeneous recurrence relation (associated LiHoReCoCo).

15.22 CompSci 102© Michael Frank Solutions of LiNoReCoCos A useful theorem about LiNoReCoCos:A useful theorem about LiNoReCoCos: –If a n = p(n) is any particular solution to the LiNoReCoCo: –Then all of its solutions are of the form: a n = p(n) + h(n), where a n = h(n) is any solution to the associated homogeneous RR

15.23 CompSci 102© Michael Frank LiNoReCoCo Example Find all solutions to a n = 3a n−1 +2n. Which solution has a 1 = 3?Find all solutions to a n = 3a n−1 +2n. Which solution has a 1 = 3? –Notice this is a 1-LiNoReCoCo. Its associated 1-LiHoReCoCo is a n = 3a n−1, whose solutions are all of the form a n = α3 n. Thus the solutions to the original problem are all of the form a n = p(n) + α3 n. So, all we need to do is find one p(n) that works.

15.24 CompSci 102© Michael Frank Trial Solutions If the extra terms F(n) are a degree-t polynomial in n, you should try a general degree-t polynomial as the particular solution p(n).If the extra terms F(n) are a degree-t polynomial in n, you should try a general degree-t polynomial as the particular solution p(n). This case: F(n) is linear so try a n = cn + d.This case: F(n) is linear so try a n = cn + d. cn+d = 3(c(n−1)+d) + 2n(for all n) (2c+2)n + (2d−3c) = 0 (collect terms) So c = −1 and d = −3/2. So a n = −n − 3/2 is a solution. Check: a n≥1 = {−5/2, −7/2, −9/2, … }Check: a n≥1 = {−5/2, −7/2, −9/2, … }

15.25 CompSci 102© Michael Frank Finding a Desired Solution From the previous, we know that all general solutions to our example are of the form:From the previous, we know that all general solutions to our example are of the form: a n = −n − 3/2 + α3 n. Solve this for α for the given case, a 1 = 3: 3 = −1 − 3/2 + α3 1 α = 11/6 The answer is a n = −n − 3/2 + (11/6)3 n.The answer is a n = −n − 3/2 + (11/6)3 n.

15.26 CompSci 102© Michael Frank Double Check Your Answer! Check the base case, a 1 =3:Check the base case, a 1 =3: a n = −n − 3/2 + (11/6)3 n a 1 = −1 − 3/2 + (11/6)3 1 = −2/2 − 3/2 + 11/2 = −5/2 + 11/2 = 6/2 = 3 a 1 = −1 − 3/2 + (11/6)3 1 = −2/2 − 3/2 + 11/2 = −5/2 + 11/2 = 6/2 = 3 Check the recurrence, a n = 3a n−1 +2n:Check the recurrence, a n = 3a n−1 +2n: −n − 3/2 + (11/6)3 n = 3[−(n−1) − 3/2 + (11/6)3 n−1 ]+2n = 3[−n − 1/2 + (11/6)3 n−1 ] + 2n = −3n − 3/2 + (11/6)3 n + 2n = −n − 3/2 + (11/6)3 n ■