1 / 44

Divide and Conquer: Examples, Scenarios, and Recurrences

Learn about divide and conquer algorithms with examples and scenarios. Solve recurrences and analyze their running time in terms of Big-O notation.

sbraxton
Download Presentation

Divide and Conquer: Examples, Scenarios, and Recurrences

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. L18: Recurrences for Divide-and-Conquer Prob Prob 1 1 1 1 n/2 n-1 n n 1 1 n n L17 Subs Subs n/2 n 1 n/2+1 n-1 n-1 1 1 L18

  2. Page 2 Outline • D&C Examples • D&C Scenarios and Recurrences • Solving the recurrences • Big-O • Running time in terms of big-O • Three asymptotic behaviors of D&C recurrences • Reading: • Textbook: 228-240

  3. D&C Example: Merge Sort 7 2 4 3 1 8 6 5 Divide 1 8 6 5 7 2 4 3 Conquer 2 3 4 7 1 5 6 8 Merge 2 3 4 5 6 7 8 1

  4. D&C Example: Binary Search

  5. D&C Example: Binary Search

  6. Binary Recurrence

  7. Need ceiling function and deal with recurrences like the following What if n is not a power for 2?

  8. Different Types of Recurrences • Which case takes more time?

  9. Page 9 Outline • D&C Examples • D&C Scenarios and Recurrences • Solving the recurrences • Big-O • Running time in terms of big-O • Three Asymptotic behaviors of D&C recurrences

  10. D&C Scenarios and Recurrences

  11. Page 11 Outline • D&C Example : Binary search • D&C Scenarios and Recurrences • Solving the recurrences • Big-O • Running time in terms of big-O • Three Asymptotic behaviors of D&C recurrences

  12. Solving recurrence:

  13. Solving recurrence:

  14. Another Perspective: Recursion Tree

  15. Notes

  16. Notes

  17. Solving recurrence:

  18. Solving recurrence:

  19. Recursion Tree

  20. Page 20 Outline • D&C Example : Binary search • D&C Scenarios and Recurrences • Solving the recurrences • Big-O • Running time in terms of big-O • Three Asymptotic behaviors of D&C recurrences

  21. To get an clear appreciation of when running time differences that matters, we need big-O notation. How different are the running times?

  22. Asymptotically, 100n+10000 is better than

  23. Order of growth of f is upper bounded by order of growth ofg. Big-O/Asymptotic Upper Bound

  24. Big-O Example Show: 5n+10=O(n) Need to do: 6 10 Therefore, 5n+10=O(n) Proved.

  25. Big-O Examples g(n)=n2 In all cases, we can say the running time is O(n2). Convey essential info. & simple.

  26. Big-Theta

  27. Examples

  28. Use of big-O, ϴ If program has running time 3n2+n we can simply say: running time is ϴ(n2) Report dominating term only

  29. Page 30 Outline • D&C Example : Binary search • D&C Scenarios and Recurrences • Solving the recurrences • Big-O • Running time in terms of big-O • Three Asymptotic behaviors of D&C recurrences

  30. Running time in terms of Big-O

  31. Can further simplify using Instead, get big-O expression directly Solving recurrence: Assume n=2j

  32. Solving recurrence: Assume n=2j

  33. Running time in terms of Big-O

  34. Page 37 Outline • D&C Example : Binary search • D&C Scenarios and Recurrences • Solving the recurrences • Big-O • Running time in terms of big-O • Three Asymptotic behaviors of D&C recurrences

  35. Three Asymptotic Behaviors

  36. Case 2 proved already.

  37. Proof for Cases 1 & 3

  38. Case 1: a < 2

  39. Case 3: a > 2

More Related