1 / 18

Recurrence Relations

Recurrence Relations. By: Sean Lyn March 25, 2008. Algorithm Analysis. “The process of deriving the estimates for the time and space required to execute an algorithm.” Direct Proof Proof by Contradiction Proof by Induction. Time Complexity. Θ (g(n)) = is g(n) O(g(n)) = is at most g(n)

etta
Download Presentation

Recurrence Relations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Recurrence Relations By: Sean Lyn March 25, 2008

  2. Algorithm Analysis • “The process of deriving the estimates for the time and space required to execute an algorithm.” • Direct Proof • Proof by Contradiction • Proof by Induction

  3. Time Complexity • Θ(g(n)) = is g(n) • O(g(n)) = is at most g(n) • Ω(g(n)) = is at least g(n)

  4. Examples • for (x=0; x<n; x++) a+=1; • for (x=0; x<n; x++){ for (y=0; y<n; y++) a+=1; }

  5. Algorithm Efficiency

  6. Recurrence Relation • “A recurrence relation relates the nth element of a sequence to [a] certain of its predecessors” • In other words, how do you define An in terms of A1,A2,A3,… An-1 ?

  7. Uses • Used for describing the time required by an algorithm • It can be used in defining a sequence

  8. Fibonacci Sequence • Fn = Fn-1 + Fn-2 where n > 2, F1 = 1, and F2 = 1

  9. Mandlebrot Set • Zn+1 = (Zn)² + C, Z0 = C

  10. Example • Cn is the number of times the statement x=x+1 executes example(n) { if (n==1) return; for (i=1; x<n; x++) x = x+1; example(n/2); } C1 = 0 We get the recurrence relation Cn = n + C[n/2]

  11. Example 2 • Solving a recurrence relation, or producing a solution without using Ci for any i. • Given: Cn = Cn-1 + n, n>=1 and C0 = 0 • Cn-1 = Cn-2 + n-1 -> Cn = (Cn-2+n-1)+n • Repeat…

  12. Example 2 Cont. • Cn = Cn-1 + n • Cn = Cn-2 + (n-1) + n • Cn = Cn-3 + (n-2) + (n-1) + n • Which gives us… • Cn = C1 + 2 + 3 + … (n-2) + (n-1) + n • Cn = C0 + 1 + 2 + … (n-2) + (n-1) + n • Cn = 0 + 1 + 2 +…. n • Cn = n(n+1)/2

  13. Main Recurrence Theorem • Let a, b and k be integers satisfying a>=1, b >= 2, and k >= 0. • The recurrence relation must have the form: T(n) = aT(n/b) + f(n), where f(n) = O(nk) / O(nk) if a < bk • T(n) = | O(nklogn) if a = bk \ O(nlogba) if a > bk This also applies to Θ and Ω

  14. Using the MRT • Find O() for the relation • T(n) = 2T(n/2) + n • a = 2, b = 2, k = 1 • We can see that 2 = 2¹ • Therefore a = bk so we get O(nlogn)

  15. Example 2 • Find O() for the relation • T(n) = 3T(n/2) + n² • a = 3, b = 2, k = 2 • We can see that 3 < 2² • Therefore a < bk so we get O(n²)

  16. Putting it all Together • Recurrence relations can be used to define the time complexity of an algorithm • Recurrence relations can be used to define sequences • Time complexities are important because computers have limited memory. • The main recurrence theorem can be used to solve the time complexities of recurrence relations

  17. Questions • What is one example of a sequence generated by a recurrence relation? • Using the MRT, what is the time complexity of the function: T(n) = T(n)+n ?

  18. Works Cited • Johnsonbaugh, Richard and Marcus Schaefer. Algorithms. New Jersey: Pearson Education, Inc, 2004. • “Recurrence Equation.” http://mathworld.wolfram.com. 2008. 25 March 2008. <http://mathworld.wolfram.com/RecurrenceEquation.html>.

More Related