1 King Fahd University of Petroleum Minerals Information
- Slides: 14
1 King Fahd University of Petroleum & Minerals Information & Computer Science Department ICS 353: Design and Analysis of Algorithms Solving Recurrence Relations
ICS 353: Design and Analysis of Algorithms 2 Solving Recurrence Relations Reading Assignment • Chapter 2 as a whole, but in particular Section 2. 8 • Chapter 4 from Cormen’s Book. • Section 5: Master Method.
3 ICS 353: Design and Analysis of Algorithms Solving Recurrence Relations Outline • 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 Method • Recurrence Expansion • The Change of Variable Method
ICS 353: Design and Analysis of Algorithms 4 Solving Recurrence Relations 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
ICS 353: Design and Analysis of Algorithms 5 Solving Recurrence Relations 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)
ICS 353: Design and Analysis of Algorithms 6 Examples • • • Solving Recurrence Relations
ICS 353: Design and Analysis of Algorithms 7 Solving Recurrence Relations 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 gi(n) is not a constant or g 0(n) 0.
ICS 353: Design and Analysis of Algorithms 8 Solving Recurrence Relations 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
ICS 353: Design and Analysis of Algorithms 9 Solving Recurrence Relations 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(nlogba - ), then f(n) = (nlogba). If g(n)= (nlogba), then f(n) = (nlogba log n). If >0 g(n)= (nlogba + ), and if c<1, n 0 ag(n/b) cg(n) n > n 0, then f(n) = (g(n)).
ICS 353: Design and Analysis of Algorithms 10 Examples • • • Solving Recurrence Relations
ICS 353: Design and Analysis of Algorithms 11 Solving Recurrence Relations Gaps in the Master Theorem • The three cases in 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?
ICS 353: Design and Analysis of Algorithms 12 Solving Recurrence Relations The Expansion Method • When expanding few terms of some recurrences, a solution may become more apparent. • Example: Consider the previous recurrence
ICS 353: Design and Analysis of Algorithms 13 Solving Recurrence Relations 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.
ICS 353: Design and Analysis of Algorithms 14 Example • Solving Recurrence Relations
- Milk alkali syndrome
- Fahd: hi, ryan. where are you going?
- Fuente del rey fahd
- Ufa colleges and universities
- The king is dead, long live the king
- King ___________ of france called himself "the sun king."
- King faisal university college of medicine
- King saud university college of medicine
- Prodofol
- Applied medical sciences
- King saud university mechanical engineering
- King saud university college of pharmacy
- King saud university college of medicine
- King abdulaziz university english language institute
- King saud university college of pharmacy