after UCI ICS/Math 6A, Summer 20079-AdvancedCounting -1 Recurrence Relations (RRs) A “Recurrence Relation”

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.
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.
Transparency No. 5-1 Discrete Mathematics Chapter 5 Advanced Counting Techniques.
Discrete Structures Chapter 6 Recurrence Relations
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.
Analysis of Recursive Algorithms October 29, 2014
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.
4.6.2 Exponential generating functions
Ch. 7: Advanced Counting Techniques
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.
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., §
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.
Module #20 - Recurrences Solving Recurrences Rosen 6 th ed., §7.2.
Discrete Mathematics Recurrence Relations Chapter 5 R. Johnsonbaugh
Chapter 8 Recursion. 8.3 More Recurrence Second-Order Recurrence Definition – A second-order linear homogeneous recurrence relation with constant coefficients.
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.
Recurrence Relations. Outline Recurrence relationsSolving recurrence relationsRecurrence and Divide-and-conquer algorithmsGenerating functions
RECURRENCE Sequence Recursively defined sequence
1 RECURRENCE 1. Sequence 2. Recursively defined sequence 3. Finding an explicit formula for recurrence relation.
Mathematical Analysis of Recursive Algorithm CSG3F3 Lecture 7.
Recursively Defined Sequences Lecture 40 Section 8.1 Wed, Apr 11, 2007.
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
Modeling with Recurrence Relations
A0=0 a1=2 an a2=6 an-1 a3=12 a4=20 a2 a1 a0.
Introduction to Recurrence Relations
Module #17: Recurrence Relations
Module #17: Recurrence Relations
Recursion and Recurrence Relations
CS 2210 Discrete Structures Advanced Counting
CMSC Discrete Structures
Solving Recurrence Relations
CMSC Discrete Structures
Recurrence Relations Discrete Structures.
Chapter 7 Advanced Counting Techniques
Recurrence Relations (RRs)
Recurrence Relations Rosen 5th ed., §6.2 5/22/2019
ICS 253: Discrete Structures I
Presentation transcript:

after UCI ICS/Math 6A, Summer AdvancedCounting -1 Recurrence Relations (RRs) A “Recurrence Relation” for a sequence {a n } is an equation that expresses a n in terms of one or more of the previous terms in the sequence (i.e., a 0,a 1,a 2,…,a n-1 ) for all n≥n 0. Examples: a 0 =1, a 1 =3, a 2 =4; for n ≥3, a n = a n-1 +a n-2 -a n-3 1,3,4,6,7,9,10,12,13,15,16,18,19,21,22,… a 0 =2, a 1 =4, a 2 =3; for n ≥3, a n = a n-1 +a n-2 -a n-3 2,4,3,5,4,6,5,7,6,8,7,9,8,10,9,11,… a 0 =4, a 1 =3, a 2 =3; for n ≥3, a n = a n-1 +a n-2 -a n-3 4,3,3,2,2,1,1,0,0,-1,-1,-2,-2,-3,-3,-4,-4,…

after UCI ICS/Math 6A, Summer AdvancedCounting -2 Solutions to Recurrence Relations A sequence {a n } is called a “solution” of the recurrence relation if its terms satisfy the recurrence relation. Examples: For n ≥3, a n = a n-1 +a n-2 -a n-3 ; Initial conditions: a 0 =1, a 1 =3, a 2 =4. Solution: 1,3,4,6,7,9,10,12,13,15,16,18,19,21,22,… For n ≥3, a n = a n-1 +a n-2 -a n-3 ; Initial conditions: a 0 =2, a 1 =4, a 2 =3. Solution: 2,4,3,5,4,6,5,7,6,8,7,9,8,10,9,11,… For n ≥3, a n = a n-1 +a n-2 -a n-3 ; Initial conditions: a 0 =4, a 1 =3, a 2 =3. Solution: 4,3,3,2,2,1,1,0,0,-1,-1,-2,-2,-3,-3,-4,-4,… Every recurrence relationship has many solutions each determined uniquely by its own initial conditions. We say a function f:N→R is a “solution” to a recurrence relation if the sequence {f(n)} is a solution to it. Example: f(n)=5 ∙2 n is a solution to the recurrence relation a n =2∙a n-1.

after UCI ICS/Math 6A, Summer AdvancedCounting -3 Solving Recurrence Relations If a n =4a n-1 and a 0 =3, find a function f such that f(n)=a n. a n =4a n-1 =4 2 a n-2 =4 3 a n-3 =...=4 n a 0 =3  4 n. If a n =a n-1 +n and a 0 =4, find a function f such that f(n)=a n. a n =a n-1 +n=a n-2 +n+(n-1) =a n-2 +n+(n-1)+(n-2)=... =a 0 +n+(n-1)+(n-2)+...+1=4+n(n+1)/2=(n 2 +n+8)/2. If a n =2na n-1 and a 0 =5, find a function f such that f(n)=a n. a n =2na n-1 =2 2 n(n-1)a n-2 =2 3 n(n-1)a n-3 =...=2 n n!a 0 =5  2 n n!. If a n =2a n-1 +1 and a 0 =0, find a function f such that f(n)=a n. a n =2a n-1 +1=2 2 a n =2 3 a n =2 4 a n =... =2 n-1 +2 n-2 +2 n =2 n -1.

after UCI ICS/Math 6A, Summer AdvancedCounting -4 Modeling with Recurrence Relations An initial deposit of P 0 dollars deposited at 7% annual interest. P n =(1+0.07)P n-1 is the value after n years. P n =(1+0.07) n P 0 Rabbits on an island. Each pair producing a new pair every month. Fibonacci Numbers: f 0 =0, f 1 =1; for n ≥2, f n = f n-1 +f n-2. Tower of Hanoi Disks of decreasing diameter on 1 of 3 pegs. Move disks to another peg, always maintaining decreasing disk diameters on each peg. H n = number of moves to transfer n disks from 1 peg to another. H 1 =1; for n ≥2, H n = H n H n-1 = 2H n ,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535, H n = 2 n -1.

after UCI ICS/Math 6A, Summer AdvancedCounting -5 RRs for Counting Bit Strings How many bit strings of length n do not contain 2 consecutive 0’s? b 1 =2 ({0,1}), b 2 =3 ({01,10,11}) For n ≥2: 01counted or 1counted b n = b n-2 + b n-1. Recognize this? How many bit strings of length n contain 2 consecutive 0’s? b 0 =b 1 =0 For n ≥2: 00any or 01counted or 1counted b n = 2 n-2 + b n-2 + b n-1.

after UCI ICS/Math 6A, Summer AdvancedCounting -6 Counting Code Words How many strings of n digits have an even number of 0’s? a 1 =9 For n ≥2: Either the first digit isn’t 0 and the rest has an even number of 0’s (there are 9a n-1 of these) or the first digit is 0 and the rest does not have an even number of digits (there are 10 n-1 -a n-1 of these) a n = 9a n-1 +(10 n-1 -a n-1 )=8a n n-1

after UCI ICS/Math 6A, Summer AdvancedCounting -7 Catalan Numbers C n = number of ways to parenthesize the product of n+1 numbers. C 1 =1: (1x2); C 2 =2: (1x(2x3)), ((1x2)x3) C 3 =5: (1x(2x(3x4))), (1x((2x3)x4)), ((1x2)x(3x4)), ((1x(2x3))x4), (((1x2)x3)x4) C 0 =C 1 =1 C n =C 0 C n-1 +C 1 C n-2 +C 2 C n-3 +…+C n-3 C 2 +C n-2 C 1 +C n-1 C 0 (Covered in Sec.7.4, Ex.41) C n = Number of binary trees with n+1 leaves.

after UCI ICS/Math 6A, Summer AdvancedCounting -8 Solving Recurrence Relations We’ve seen several examples of Recurrence Relations a n = a∙a n-1 b n = n∙b n-1 f n =f n-2 +f n-1 b n =2 n-2 +b n-2 +b n-1 b n =2 n-3 +b n-3 +b n-2 +b n-1. b n = b n-1 +b n-2 -b n-3 H n =2H n-1 +1 In each case, many sequences satisfy the relationship and one also needs to set/have initial conditions get a unique solution. Goal: “closed form” expression for function, f, for the sequence, giving the n th term in a formula that doesn’t depend on earlier ones. Example: a n =d*a n instead of a n = a∙a n-1 H n =2 n -1 instead of H n =2H n-1 +1 We’ll look at a class of useful recurrence relations where deriving a closed form formula is easy.

after UCI ICS/Math 6A, Summer AdvancedCounting -9 Recurrence Relations When c 1, c 2, …, c k are constants and c k ≠0, a n = c 1 a n-1 +c 2 a n-2 +…+c k a n-k +F(n) is said to be a linear recurrence relation of degree k with constant coefficients. Linear = each a j appears only to the 1 st power, no a j 2, a j 3,... degree k = k previous terms, c k ≠0. constant coefficients = c j are constants, not functions c j (n). Additionally, if F(n)=0, the relation is called homogeneous. Homogeneous linear recurrence relation of degree k with constant coefficients: a n = c 1 a n-1 +c 2 a n-2 +…+c k a n-k where c k ≠0 We like these because we can solve them explicitly.

after UCI ICS/Math 6A, Summer AdvancedCounting -10 Examples of Recurrence Relations HLRRwCC = Homogeneous linear recurrence relation with constant coefficients a n = a∙a n-1 HLRRwCC of degree 1 a n = (a n-1 ) 2 Not Linear a n = n∙a n-1 Coefficients are not constant f n =f n-2 +f n-1 HLRRwCC of degree 2 b n =2 n-2 +b n-2 +b n-1. Not Homogeneous b n =2 n-3 +b n-3 +b n-2 +b n-1 Not Homogeneous a n = a n-1 +a n-2 -a n-4 HLRRwCC of degree 4 H n =2H n-1 +1 Not Homogeneous Remember: A recurrence relation has many solutions. Only when the initial conditions are specified is the solution unique. For degree k, you need k contiguous initial conditions.

after UCI ICS/Math 6A, Summer AdvancedCounting -11 Solving Linear (degree 1) HLRRwCC The relation is a n = c∙a n-1 All solutions are of the form a n = d∙c n The function is f (n)= d∙c n With the initial condition a 0 specified, the unique solution is a n = a 0 c n We saw this in computing compound interest An initial deposit of P 0 dollars deposited at 7% annual interest. P n =(1+0.07)P n-1 is the value after n years. P n =(1+0.07) n P 0

after UCI ICS/Math 6A, Summer AdvancedCounting -12 Fibonacci Solved Degree 1: f(n)=c*f(n-1); solution: f(n)=a*r n for some a and r Degree 2: f(n)=c 1 *f(n-1)+c 2 *f(n-2); solution: ? Consider Fibonacci numbers: F(n)=F(n-1)+F(n-2), and let’s try F(n)=r n. It follows that r 2 =r+1. There are 2 solutions to this quadratic equation: r 1 =(1+√5)/2, r 2 =(1-√5)/2 Therefore F 1 (n)=[(1+√5)/2] n and F 2 (n)=[(1-√5)/2] n are both solutions. Observe: If F 1,F 2 are solutions then so is F(n) = d 1 *F 1 (n) + d 2 *F 2 (n) Theorem (next slide): Every solution to this recurrence relation is of the form F(n) = d 1 *F 1 (n) + d 2 *F 2 (n) for some d 1,d 2 For our initial conditions: F(0)=0 and F(1)=1 we get d 1 +d 2 =0 and d 1 ∙r 1 +d 2 ∙r 2 =1 Therefore 1=d 1 ∙(r 1 -r 2 )=d 1 ∙(√5). Therefore d 1 = 1/√5 and d 2 = -1/√5 Therefore the closed formula for Fibonacci numbers is:

after UCI ICS/Math 6A, Summer AdvancedCounting -13 Solutions to HLRRwCC We like HLRRwCC because we can solve them explicity. That is, we can find functions f:N→R so that the sequence {f(n)} solves the recurrence relation. Here’s part of the reason why. Lemma: If functions f and g are solutions to the HLRRwCC a n = c 1 a n-1 +c 2 a n-2 +c 3 a n-3 +…+c k a n-k then f+g is also a solution as is d∙f for any constant d. Definitions: The characteristic equation of this HLRRwCC is r k = c 1 r k-1 +c 2 r k-2 +c 3 r k-3 +…+c k-1 r+c k The solutions (roots) of this equation are called the characteristic roots of the recurrence relation

after UCI ICS/Math 6A, Summer AdvancedCounting -14 (Fibonacci) Degree 2 HLRRwCC 1) Write out the characteristic equation. (For Fibonacci: r 2 =r+1) 2) Find the characteristic roots (r 1 and r 2 ). ( r 1 =(1+√5)/2, r 2 =(1-√5)/2 ) 3) Any function of the form f(n)=d 1 ∙r 1 n +d 2 ∙r 2 n (d 1 and d 2 constants) solves this recurrence relation. 4a) If the characteristic roots are distinct, we can pick d 1 and d 2 to produce the required initial values. 4b) If there is only 1 characteristic root (r 1 =r 2 =r 1 ), then any function of the form f(n)=(d 1 +d 2 ∙n)∙r n (d 1 and d 2 constants) solves the recurrence relation. Example: a 0 =1, a 1 =4; for n ≥2, a n = 4a n-1 -4a n-2 1,4,12,32,80,192,448, Characteristic Equation: r 2 =4r-4  r 2 -4r+4=0  r=2 (twice) f(n)=(d 1 +d 2 ∙n)∙2 n & 1=d 1 & 4=2d 1 +2d 2  d 1 =d 2 =1; f(n)=(1+n) ∙ 2 n Check: f(6)=(1+6)∙2 6 =7∙64=448

after UCI ICS/Math 6A, Summer AdvancedCounting -15 All Solutions For Any HLRRwCC Thrm: If r k = c 1 r k-1 +c 2 r k-2 +…+c k-1 r+c k ( c k ≠0) has k distinct roots, r 1,r 2,…,r k, then every solution of the recursion relation a n =c 1 a n-1 +c 2 a n-2 +…+c k a n-k has the form a n = d 1 r 1 n +d 2 r 2 n +…+d k r k n for some d 1, d 2, …, d k and every such sequence solves/satisfies the recursion relation. If there are t distinct roots, each with multiplicity m i, the sequences {a n } solving the recursion relation are given by

after UCI ICS/Math 6A, Summer AdvancedCounting -16 Degree 3 HLRRwCC Examples a 0 =2, a 1 =5, a 2 =15; for n ≥3, a n = 6∙a n-1 -11∙a n-2 - 6∙a n-3 r 3 = 6∙r 2 -11∙r-6  r 3 -6∙r 2 +11∙r+6=0  (r-1)(r-2)(r-3)=0 General solution: a n = x∙1 n +y∙2 n +z∙3 n. Initial values: 2=x+y+z; 5=x+2y+3z; 15=x+4y+9z  x=1; y=-1; z=2 Specific solution: a n = 1-2 n +2∙3 n. a 0 =1, a 1 =-2, a 2 =-1; for n ≥3, a n = -3∙a n-1 -3∙a n-2 -a n-3 r 3 = -3∙r 2 -3∙r-1  r 3 +3∙r 2 +3∙r+1=0  (r+1) 3 =0  r=-1 with multiplicity 3 General solution: a n =(x+y∙n+z∙n 2 )∙(-1) n. Initial values: 1=x; 2=x+y+z; -1=x+2y+4z  x=1; y=3; z=-2 Specific solution: a n = (1+3n-2n 2 ) (-1) n.