Presentation is loading. Please wait.

Presentation is loading. Please wait.

Recurrence Relations Reading Material –Chapter 2 as a whole, but in particular Section 2.8 –Chapter 4 from Cormen’s Book.

Similar presentations


Presentation on theme: "Recurrence Relations Reading Material –Chapter 2 as a whole, but in particular Section 2.8 –Chapter 4 from Cormen’s Book."— Presentation transcript:

1 Recurrence Relations Reading Material –Chapter 2 as a whole, but in particular Section 2.8 –Chapter 4 from Cormen’s Book.

2 Recurrence Relations Objective: To discuss techniques for solving recurrence relations. –These techniques will be very important and “handy” tools for analyzing algorithms that are recursive. Linear Homogenous Recurrences –Characteristic Equations Inhomogeneous Recurrences –The Master Theorem –Recurrence Expansion –The Substitution Method –The Change of Variable Method

3 Linear Homogeneous Equations Definition: A recurrence relation is called linear homogeneous with constant coefficients if it is of the form: We restrict our discussion to homogeneous recurrence equations with k=1 or k=2

4 Solution of Linear Homogeneous Equations When k=1, and hence the solution is When k=2, the following steps are followed to solve the recurrence: –Find r 1 and r 2, the solutions to the characteristic equation –If r 1 = r 2 = r, then Otherwise –Determine c 1 and c 2 from the initial values f(n 0 ) and f(n 0 +1)

5 Examples

6 Inhomogeneous Equations Definition: A recurrence relation is called inhomogeneous if it is not a homogeneous recurrence relation. In particular, we will look at where  i 1  i  k  g i (n) is not a constant or g 0 (n)  0.

7 Solution for Inhomogeneous Recurrences No general method for solving inhomogeneous recurrences exists. However, –There are cases where a formula for a class of inhomogeneous recurrence relations exists (Master Theorem) –The rest depend on experience and/or trial and error in choosing one of the following techniques Expansion Substitution Change of variable

8 Master Theorem Theorem: Let a  1 and b>1 be constants, let g(n) be a function, and let f(n) be defined on the nonnegative integers by the recurrence where we interpret n/b to mean either  n/b  or  n/b . Then f(n) can be bounded asymptotically as follows –If  >0  g(n)=O(n log b a -  ), then f(n) =  (n log b a ). –If g(n)=  (n log b a ), then f(n) =  (n log b a log n). –If  >0  g(n)=  (n log b a +  ), and if  c n 0, then f(n) =  (g(n)).

9 Examples

10 Gaps in the Master Theorem The three cases in the theorem do not cover all the possibilities for g(n). There are gaps between cases 1 and 2, and 2 and 3. –For example, can we apply the Master theorem on the following recurrence?

11 The Expansion Method When expanding few terms of some recurrences, a solution may become more apparent. Example: Consider the previous recurrence

12 The Substitution Method If we can have a “good” guess of what the answer may be, then we can use mathematical induction to prove that it is correct. Example: Consider the following recurrence: This recurrence seems similar to (when n is a power of 2, they are exactly equal.) By applying case 2 of the master theorem, the solution to the second recurrence is  (nlog n). Therefore, we can guess that we can find c,d > 0  dnlog n  f(n)=2f(  n/2  ) + n  cnlog n for all values of n.

13 Example (Cont.) We show by induction that f(n)  cnlog n. The other inequality is left as an exercise. –Induction Step –Initial Step

14 The Change of Variables Method The idea is to change the domain of the function and define a new recurrence in the new domain whose solution may be easier to obtain or is already known. Once the solution is obtained, we convert the domain of the function back to its original domain.

15 Example


Download ppt "Recurrence Relations Reading Material –Chapter 2 as a whole, but in particular Section 2.8 –Chapter 4 from Cormen’s Book."

Similar presentations


Ads by Google