Solving Recurrence Relations

Slides:



Advertisements
Similar presentations
Fall 2002CMSC Discrete Structures1 Now it’s Time for… RecurrenceRelations.
Advertisements

CS 2210 (22C:19) Discrete Structures Advanced Counting
April 9, 2015Applied Discrete Mathematics Week 9: Relations 1 Solving Recurrence Relations Another Example: Give an explicit formula for the Fibonacci.
Part 5. Computational Complexity (3)
CSE115/ENGR160 Discrete Mathematics 04/19/12 Ming-Hsuan Yang UC Merced 1.
Discrete Structures Chapter 6 Recurrence Relations
Analysis of Recursive Algorithms
Recurrence Relations Reading Material –Chapter 2 as a whole, but in particular Section 2.8 –Chapter 4 from Cormen’s Book.
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.
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
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
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.
Project 2 due … Project 2 due … Project 2 Project 2.
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.
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
Chapter 8 With Question/Answer Animations. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Chapter 8 Recursion. 8.3 More Recurrence Second-Order Recurrence Definition – A second-order linear homogeneous recurrence relation with constant coefficients.
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
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.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
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.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
CSG523/ Desain dan Analisis Algoritma
CSG523/ Desain dan Analisis Algoritma
Recursion Sections 8.1 and 8.2 of Rosen Spring 2013
CMSC Discrete Structures
Analysis of Algorithms
Modeling with Recurrence Relations
Introduction to the Design and Analysis of Algorithms
Applied Discrete Mathematics Week 11: Relations
Introduction to Recurrence Relations
UNIT-6 Recurrence Relations
Design and Analysis of Algorithms
Module #17: Recurrence Relations
演算法概論 Introduction to Algorithms
Divide-and-Conquer 7 2  9 4   2   4   7
Applied Discrete Mathematics Week 6: Computation
CSE 373 Data Structures and Algorithms
Module #17: Recurrence Relations
Recurrences (Method 4) Alexandra Stefan.
Recursion and Recurrence Relations
Applied Discrete Mathematics Week 9: Integer Properties
Divide and Conquer Algorithms Part I
CS 2210 Discrete Structures Advanced Counting
CMSC Discrete Structures
Applied Discrete Mathematics Week 7: Computation
Divide-and-Conquer 7 2  9 4   2   4   7
CMSC Discrete Structures
At the end of this session, learner will be able to:
Recurrence Relations Discrete Structures.
Algorithms Recurrences.
Chapter 7 Advanced Counting Techniques
Recurrence Relations.
Recurrence Relations Rosen 5th ed., §6.2 5/22/2019
ICS 253: Discrete Structures I
Presentation transcript:

Solving Recurrence Relations In general, we would prefer to have an explicit formula to compute the value of an rather than conducting n iterations. For one class of recurrence relations, we can obtain such formulas in a systematic way. Those are the recurrence relations that express the terms of a sequence as linear combinations of previous terms. November 6, 2018 Applied Discrete Mathematics Week 9: Integer Properties

Solving Recurrence Relations Definition: A linear homogeneous recurrence relation of degree k with constant coefficients is a recurrence relation of the form: an = c1an-1 + c2an-2 + … + ckan-k, Where c1, c2, …, ck are real numbers, and ck  0. A sequence satisfying such a recurrence relation is uniquely determined by the recurrence relation and the k initial conditions a0 = C0, a1 = C1, a2 = C2, …, ak-1 = Ck-1. November 6, 2018 Applied Discrete Mathematics Week 9: Integer Properties

Solving Recurrence Relations Examples: The recurrence relation Pn = (1.05)Pn-1 is a linear homogeneous recurrence relation of degree one. The recurrence relation fn = fn-1 + fn-2 is a linear homogeneous recurrence relation of degree two. The recurrence relation an = an-5 is a linear homogeneous recurrence relation of degree five. November 6, 2018 Applied Discrete Mathematics Week 9: Integer Properties

Solving Recurrence Relations Basically, when solving such recurrence relations, we try to find solutions of the form an = rn, where r is a constant. an = rn is a solution of the recurrence relation an = c1an-1 + c2an-2 + … + ckan-k if and only if rn = c1rn-1 + c2rn-2 + … + ckrn-k. Divide this equation by rn-k and subtract the right-hand side from the left: rk - c1rk-1 - c2rk-2 - … - ck-1r - ck = 0 This is called the characteristic equation of the recurrence relation. November 6, 2018 Applied Discrete Mathematics Week 9: Integer Properties

Solving Recurrence Relations The solutions of this equation are called the characteristic roots of the recurrence relation. Let us consider linear homogeneous recurrence relations of degree two. Theorem: Let c1 and c2 be real numbers. Suppose that r2 – c1r – c2 = 0 has two distinct roots r1 and r2. Then the sequence {an} is a solution of the recurrence relation an = c1an-1 + c2an-2 if and only if an = 1r1n + 2r2n for n = 0, 1, 2, …, where 1 and 2 are constants. November 6, 2018 Applied Discrete Mathematics Week 9: Integer Properties

Solving Recurrence Relations Example: What is the solution of the recurrence relation an = an-1 + 2an-2 with a0 = 2 and a1 = 7 ? Solution: The characteristic equation of the recurrence relation is r2 – r – 2 = 0. Its roots are r1 = 2 and r2 = -1. Hence, the sequence {an} is a solution to the recurrence relation if and only if: an = 12n + 2(-1)n for some constants 1 and 2. November 6, 2018 Applied Discrete Mathematics Week 9: Integer Properties

Solving Recurrence Relations Given the equation an = 12n + 2(-1)n and the initial conditions a0 = 2 and a1 = 7, it follows that a0 = 2 = 1 + 2 a1 = 7 = 12 + 2 (-1) Solving these two equations gives us 1 = 3 and 2 = -1. Therefore, the solution to the recurrence relation and initial conditions is the sequence {an} with an = 32n – (-1)n. November 6, 2018 Applied Discrete Mathematics Week 9: Integer Properties

Solving Recurrence Relations Another Example: Give an explicit formula for the Fibonacci numbers. Solution: The Fibonacci numbers satisfy the recurrence relation fn = fn-1 + fn-2 with initial conditions f0 = 0 and f1 = 1. The characteristic equation is r2 – r – 1 = 0. Its roots are November 6, 2018 Applied Discrete Mathematics Week 9: Integer Properties

Solving Recurrence Relations Therefore, the Fibonacci numbers are given by for some constants 1 and 2. We can determine values for these constants so that the sequence meets the conditions f0 = 0 and f1 = 1: November 6, 2018 Applied Discrete Mathematics Week 9: Integer Properties

Solving Recurrence Relations The unique solution to this system of two equations and two variables is So finally we obtained an explicit formula for the Fibonacci numbers: November 6, 2018 Applied Discrete Mathematics Week 9: Integer Properties

Solving Recurrence Relations But what happens if the characteristic equation has only one root? How can we then match our equation with the initial conditions a0 and a1 ? Theorem: Let c1 and c2 be real numbers with c2 0. Suppose that r2 – c1r – c2 = 0 has only one root r0. A sequence {an} is a solution of the recurrence relation an = c1an-1 + c2an-2 if and only if an = 1r0n + 2nr0n, for n = 0, 1, 2, …, where 1 and 2 are constants. November 6, 2018 Applied Discrete Mathematics Week 9: Integer Properties

Solving Recurrence Relations Example: What is the solution of the recurrence relation an = 6an-1 – 9an-2 with a0 = 1 and a1 = 6? Solution: The only root of r2 – 6r + 9 = 0 is r0 = 3. Hence, the solution to the recurrence relation is an = 13n + 2n3n for some constants 1 and 2. To match the initial conditions, we need a0 = 1 = 1 a1 = 6 = 13 + 23 Solving these equations yields 1 = 1 and 2 = 1. Consequently, the overall solution is given by an = 3n + n3n. November 6, 2018 Applied Discrete Mathematics Week 9: Integer Properties

Divide-and-Conquer Relations Some algorithms take a problem and successively divide it into one or more smaller problems until there is a trivial solution to them. For example, the binary search algorithm recursively divides the input into two halves and eliminates the irrelevant half until only one relevant element remained. This technique is called “divide and conquer”. We can use recurrence relations to analyze the complexity of such algorithms. November 6, 2018 Applied Discrete Mathematics Week 9: Integer Properties

Divide-and-Conquer Relations Suppose that an algorithm divides a problem (input) of size n into a subproblems, where each subproblem is of size n/b. Assume that g(n) operations are performed for such a division of a problem. Then, if f(n) represents the number of operations required to solve the problem, it follows that f satisfies the recurrence relation f(n) = af(n/b) + g(n). This is called a divide-and-conquer recurrence relation. November 6, 2018 Applied Discrete Mathematics Week 9: Integer Properties

Divide-and-Conquer Relations Example: The binary search algorithm reduces the search for an element in a search sequence of size n to the binary search for this element in a search sequence of size n/2 (if n is even). Two comparisons are needed to perform this reduction. Hence, if f(n) is the number of comparisons required to search for an element in a search sequence of size n, then f(n) = f(n/2) + 2 if n is even. November 6, 2018 Applied Discrete Mathematics Week 9: Integer Properties

Divide-and-Conquer Relations Usually, we do not try to solve such divide-and conquer relations, but we use them to derive a big-O estimate for the complexity of an algorithm. Theorem: Let f be an increasing function that satisfies the recurrence relation f(n) = af(n/b) + cnd whenever n = bk, where k is a positive integer, a, c, and d are real numbers with a  1, and b is an integer greater than 1. Then f(n) is O(nd), if a < bd, O(nd log n) if a = bd, O(nlogba) if a > bd November 6, 2018 Applied Discrete Mathematics Week 9: Integer Properties

Divide-and-Conquer Relations Example: For binary search, we have f(n) = f(n/2) + 2, so a = 1, b = 2, and d = 0 (d = 0 because here, g(n) does not depend on n). Consequently, a = bd, and therefore, f(n) is O(nd log n) = O(log n). The binary search algorithm has logarithmic time complexity. November 6, 2018 Applied Discrete Mathematics Week 9: Integer Properties