Download
design analysis of algorithms comp 482 elec 420 john greiner n.
Skip this Video
Loading SlideShow in 5 Seconds..
Design & Analysis of Algorithms COMP 482 / ELEC 420 John Greiner PowerPoint Presentation
Download Presentation
Design & Analysis of Algorithms COMP 482 / ELEC 420 John Greiner

Design & Analysis of Algorithms COMP 482 / ELEC 420 John Greiner

96 Views Download Presentation
Download Presentation

Design & Analysis of Algorithms COMP 482 / ELEC 420 John Greiner

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Design & Analysis of Algorithms COMP 482 / ELEC 420John Greiner

  2. Order Statistics: Select ith-ranked item Least:i= 1 Greatest:i= n Assume collection is unordered, otherwise trivial. To do: [CLRS] 9 #3 Lower median Upper median

  3. Simple Algorithms Could sort first: O(n lg n), but can do better: O(n). What are algorithms for i=1, 2, 3? How do these generalize?

  4. Modify Quicksort First, to get average-caseO(n). Then, to get worst-caseO(n). With a very unobvious detail!

  5. Blum, Floyd, Pratt, Rivest, Tarjan(1973) All this to find a good split. T( ) Only one done. Select(A,n,i): Divide input into groups of size 5. /* Partition on median-of-medians */ medians = array of each group’s median. pivot = Select(medians, , ) L,G = partition(A, pivot) /* Find ith element in L, pivot, or G */ k = # of lesser elements + 1 If i=k, return pivot If i<k, return Select(L, k-1, i) If i>k, return Select(G, n-k, i-k) T(n) O(n) O(n) O(n) O(1) O(1) T(k-1) T(n-k)

  6. Analysis How to simplify? #less #greater

  7. Groups of 5 Lesser Elements Median Greater Elements One group of 5 elements.

  8. Groups of Groups of 5 Lesser Medians Median of Medians Greater Medians All groups of 5 elements. (And at most one smaller group.)

  9. Elements Not Needed Definitely Lesser Elements Definitely Greater Elements

  10. 1st Way to Count Must recur on all elements outside one of these boxes. How many?

  11. 1st Way to Count partial groups of 2 full groups of 5 At most Count elements outside smaller box.

  12. 2nd Way to Count Equivalently, must recur on all elements not inside one of these boxes. How many?

  13. 2nd Way to Count At most 1 groups of 3 Count elements in smaller box & pivot.

  14. Plugging Count Back into Recurrence

  15. Using Substitution Method Prove Overestimate ceiling Algebra when c,k, can find a n0 such that this holds n≥n0.

  16. Why Groups of 5?