1 / 151

In-Place Sorting Viliam Geffert P.J. Š af á rik University , K ošice, Slovakia J o zef Gajdo š

In-Place Sorting Viliam Geffert P.J. Š af á rik University , K ošice, Slovakia J o zef Gajdo š College of International Business ISM Slovakia Prešov , Slovakia. The Problem. n elements. n elements. n elements. 1 hole. 1. n.log n + Δ (n) comparisons O(n) element moves

elvina
Download Presentation

In-Place Sorting Viliam Geffert P.J. Š af á rik University , K ošice, Slovakia J o zef Gajdo š

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. In-Place Sorting Viliam Geffert P.J.Šafárik University, Košice, Slovakia Jozef Gajdoš College of International Business ISM Slovakia Prešov, Slovakia The Problem

  2. n elements

  3. n elements

  4. n elements 1hole 1.n.log n + Δ(n) comparisons O(n)element moves O(1) index variables, of log nbits each

  5. Comparisons Moves Storage log n! ≈ n.log n–1.44n 3/2.n O(1) lower bound

  6. Comparisons Moves Storage log n! ≈ n.log n–1.44n 3/2.n O(1) lower bound n.log n n.log n n mergesort [Kn1973]

  7. Comparisons Moves Storage log n! ≈ n.log n–1.44n 3/2.n O(1) lower bound n.log n +O(n.loglog n)O(n.log n/loglog n) O(1) mergesortADV [KaPa1999]

  8. Comparisons Moves Storage log n! ≈ n.log n–1.44n 3/2.n O(1) lower bound n.log n +O(n.loglog n)O(n.log n/loglog n) O(1) mergesortADV [KaPa1999] Θ(n2) O(n) O(1) selectsort

  9. Comparisons Moves Storage log n! ≈ n.log n–1.44n 3/2.n O(1) lower bound n.log n +O(n.loglog n)O(n.log n/loglog n) O(1) mergesortADV [KaPa1999] Θ(n1+) O(n) O(1) n1/k-heapsort [MuRa1992]

  10. Comparisons Moves Storage log n! ≈ n.log n–1.44n 3/2.n O(1) lower bound n.log n +O(n.loglog n)O(n.log n/loglog n) O(1) mergesortADV [KaPa1999] Θ(n1+) O(n) O(1) n1/k-heapsort [MuRa1992] n.log n O(n) Θ(n) tablesort

  11. Comparisons Moves Storage log n! ≈ n.log n–1.44n 3/2.n O(1) lower bound n.log n +O(n.loglog n)O(n.log n/loglog n) O(1) mergesortADV [KaPa1999] Θ(n1+) O(n) O(1) n1/k-heapsort [MuRa1992] Θ(n.log n) O(n) Θ(n) samplesortADV [MuRa1992]

  12. Comparisons Moves Storage log n! ≈ n.log n–1.44n 3/2.n O(1) lower bound n.log n +O(n.loglog n)O(n.log n/loglog n) O(1) mergesortADV [KaPa1999] Θ(n1+) O(n) O(1) n1/k-heapsort [MuRa1992] Θ(n.log n) O(n) Θ(n) samplesortADV [MuRa1992] 1991-2005: conjectured that an algorithm matching the lower bounds for all criteria does not exist

  13. Comparisons Moves Storage log n! ≈ n.log n–1.44n 3/2.n O(1) lower bound n.log n +O(n.loglog n)O(n.log n/loglog n) O(1) mergesortADV [KaPa1999] Θ(n1+) O(n) O(1) n1/k-heapsort [MuRa1992] Θ(n.log n) O(n) Θ(n) samplesortADV [MuRa1992] log n! +Θ(n.log n) (13+ε).n O(1) [GeFr2005]

  14. Comparisons Moves Storage log n! ≈ n.log n–1.44n 3/2.n O(1) lower bound n.log n +O(n.loglog n)O(n.log n/loglog n) O(1) mergesortADV [KaPa1999] Θ(n1+) O(n) O(1) n1/k-heapsort [MuRa1992] Θ(n.log n) O(n) Θ(n) samplesortADV [MuRa1992] log n! +Θ(n.log n) (13+ε).n O(1) [GeFr2005] log n! +Θ(n.loglog n) (26+ε).n O(1) our result

  15. 1. Initial Preparation

  16. 2n/log2 n largest elements

  17. 2n/log2 n largest elements

  18. 2n/log2 n largest elements Modified heapsort -- branching degree log n instead of 2

  19. 2n/log2 n largest elements Modified heapsort -- branching degree log n instead of 2 -- halts after extracting 2n/log2 n largest elements Com: O(n) Mov : O(n/log n)

  20. 2n/log2 n smallest elements 2n/log2 n largest elements Com: O(n) Mov : O(n/log n)

  21. 2n/log2 n smallest elements 2n/log2 n largest elements Symmetrically, by modified heapsort Com: O(n) Mov : O(n/log n)

  22. 2n/log2 n smallest elements 2n/log2 n largest elements X Y Com: 1 Mov: -- Com: 1 Mov: --

  23. 2n/log2 n smallest elements 2n/log2 n largest elements X Y If X=Y, we are done, the array is sorted

  24. 2n/log2 n smallest elements 2n/log2 n largest elements X Y If X<Y, continue

  25. 2n/log2 n smallest elements 2n/log2 n largest elements Pointer memory

  26. 2n/log2 n smallest elements 2n/log2 n largest elements 0 0 0 0 0 0 Pointer memory

  27. 2n/log2 n smallest elements 2n/log2 n largest elements 1 0 0 0 0 0 Pointer memory

  28. 2n/log2 n smallest elements 2n/log2 n largest elements 1 0 1 0 0 0 Pointer memory

  29. 2n/log2 n smallest elements 2n/log2 n largest elements 1 1 1 1 1 1 2n/log2 n element pairs ≡ 2n/log3 ninteger variables, oflog nbits each

  30. 2. Partition-Based Sorting

  31. ni elements an element of rank ¼.ni b L R

  32. ni elements an element of rank ¼.ni b L R

  33. ni elements an element of rank ¼.ni b L R Com1: O( ni ) Mov1 :  . ni

  34. ni elements an element of rank ¼.ni b L R

  35. ni elements an element of rank ¼.ni b L R A< to be sorted B≥ buffer memory

  36. an element of rank ¼.ni ni,≥≥ 3.ni,< ni,<≤ ¼.ni b L R A< to be sorted B≥ buffer memory

  37. an element of rank ¼.ni ni,≥≥ 3.ni,< ni,<≤ ¼.ni b L R A< to be sorted B≥ buffer memory Com1: O( ni ) Mov1 : 2.ni,<

  38. an element of rank ¼.ni ni,≥≥ 3.ni,< ni,<≤ ¼.ni b L R A< to be sorted B≥ buffer memory Using pointer memory L+R and buffer memory B≥ , sort A<

  39. an element of rank ¼.ni ni,≥≥ 3.ni,< ni,<≤ ¼.ni b L R A< to be sorted B≥ buffer memory Using pointer memory L+R and buffer memory B≥ , sort A<

  40. an element of rank ¼.ni ni,≥≥ 3.ni,< ni,<≤ ¼.ni b L R Pointer memory ≥ 2*2m/log2 m Buffer memory ≥ 3m A< B≥ Com?: m.log m + O(m.loglog m) Mov?: (24+).m Using pointer memory L+R and buffer memory B≥ , sort A<

  41. an element of rank ¼.ni ni,≥≥ 3.ni,< ni,<≤ ¼.ni b L R A< B≥ Com?: m.log m + O(m.loglog m) Mov?: (24+).m

  42. an element of rank ¼.ni ni,≥≥ 3.ni,< ni,<≤ ¼.ni b L R A< B≥ Com?: m.log m + O(m.loglog m) Mov?: (24+).m

  43. an element of rank ¼.ni ni,≥≥ 3.ni,< ni,<≤ ¼.ni b L R A< B≥ Com?: m.log m + O(m.loglog m) Mov?: (24+).m

  44. an element of rank ¼.ni ni,≥≥ 3.ni,< ni,<≤ ¼.ni b L R A< B≥ Com?: m.log m + O(m.loglog m) Mov?: (24+).m

  45. an element of rank ¼.ni ni,>≤ ¾.ni ni,<≤ ¼.ni b L R A< B≥ Com?: m.log m + O(m.loglog m) Mov?: (24+).m

  46. an element of rank ¼.ni ni,>≤ ¾.ni ni,<≤¼ni,= b L R A< B≥ Com1: ni Mov1: 3.ni,= Com?: m.log m + O(m.loglog m) Mov?: (24+).m

  47. an element of rank ¼.ni ni,>≤ ¾.ni ni,<≤¼ni,= L R sorted Com?: m.log m + O(m.loglog m) Mov?: (24+).m

  48. an element of rank ¼.ni ni+1≤ ¾.ni “new” ni ni,<≤¼ ni,= L R sorted Com?: m.log m + O(m.loglog m) Mov?: (24+).m

  49. an element of rank ¼.ni+1 ni+1≤ ¾.ni ni,<≤¼ ni,= L R sorted Com?: m.log m + O(m.loglog m) Mov?: (24+).m

More Related