1 / 34

Introduction to Algorithms

Introduction to Algorithms. Lecture 2. Agenda. Review Asymptotic Notation Q Notation O (Big Oh) Notation W Notation w Notation o Notation Recurrences Substitution Method Recursion Tree Master Method . In the Last lecture we found that. Define the Analysis of algorithms

jimbo
Download Presentation

Introduction to Algorithms

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. Introduction to Algorithms • Lecture 2

  2. Agenda • Review • Asymptotic Notation • QNotation • O (Big Oh) Notation • WNotation • w Notation • o Notation • Recurrences • Substitution Method • Recursion Tree • Master Method

  3. In the Last lecture we found that • Define the Analysis of algorithms • Discuss What is more important than performance? • Insertion sort algorithms was presented and best and worst case times were calculated. • We discussed Merge sort algorithm and worst case time was calculated. • We concluded that • Θ(nlgn)grows more slowly than Θ(n2). • Merge sort asymptotically beats insertion sort in the worst case. • In practice, merge sort beats insertion sort for n> 30 or so.

  4. Why Asymptotic notation? • A way to describe behavior of functions in the limit. • Describe growth of functions. • Focus on what’s important by abstracting away low-order terms and constant factors. • How we indicate running times of algorithms. • A way to compare “sizes” of functions:

  5. O Notation

  6. Set definition of O-notation • EXAMPLE: • 2n2∈O(n3) ( c = 1 and n0 = 2)

  7. More Examples

  8. W-notation (lower bounds) • O-notation is an upper-bound notation. It makes no sense to say f(n) is at least O(n2). • Ω-notation (lower bounds) • EXAMPLE: (c= 1, n0= 16) 

  9. W-notation Remember

  10. More Examples

  11. Θ-notation (tight bounds) Example: c1 = 1/4, c2 = 1/2, and n0 = 8.

  12. Θ-notation

  13. Theorem f(n) = Q(g(n)) if and only if f(n) = O(g(n)) and f(n) = W(g(n))

  14. O-notation

  15. w - notation

  16. So… Remember

  17. Solving recurrences • The analysis of merge sort from Lecture 1required us to solve a recurrence. • Recurrences are like solving integrals, differential equations, etc. • In the Next Lecture ISA: • Some more detail for solving recurrences • Examples for recurrences • Applications of recurrences to divide-and-conquer algorithms.

  18. Did You remember?

  19. Substitution method • Substitution method steps: • Guess the form of the solution. • Verify by induction. • Solve for constants. The problem here how to guess the form...

  20. Recursion-tree method • A recursion tree models the costs (time) of a recursive execution of an algorithm. • The recursion-tree method can be unreliable, just like any method that uses ellipses (…). • The recursion tree method is good for generating guesses for the substitution method.

  21. Example of recursion tree Solve T(n) = T(n/4) + T(n/2)+ n2

  22. Example of recursion tree Solve T(n) = T(n/4) + T(n/2)+ n2

  23. Example of recursion tree Solve T(n) = T(n/4) + T(n/2)+ n2

  24. Example of recursion tree Solve T(n) = T(n/4) + T(n/2)+ n2

  25. Example of recursion tree Solve T(n) = T(n/4) + T(n/2)+ n2

  26. Example of recursion tree Solve T(n) = T(n/4) + T(n/2)+ n2

  27. The master method • The master method applies to recurrences of the form T(n) = aT(n/b) + f(n) , where a≥1, b> 1, and f is asymptotically positive.

  28. Three common cases

  29. Example

  30. Three common cases

  31. Example

  32. Three common cases

  33. Example

  34. Thanks

More Related