1 / 14

External Quicksort

External Quicksort. Optimierung des Quicksort-Verfahrens für Speicherhierarchien Martin Gronemann, Bernd Zey. Überblick. Quicksort - Erinnerung Intuitive Lösung Distribution-Sort (external Quicksort). 12. 12. 42. 22. 1. 1. 60. 55. 60. 5. 12. 12. 5. 22. 1. 17. 23. 55. 55.

neka
Download Presentation

External Quicksort

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. External Quicksort Optimierung des Quicksort-Verfahrens für Speicherhierarchien Martin Gronemann, Bernd Zey

  2. Überblick • Quicksort - Erinnerung • Intuitive Lösung • Distribution-Sort (external Quicksort)

  3. 12 12 42 22 1 1 60 55 60 5 12 12 5 22 1 17 23 55 55 60 22 42 23 17 23 17 55 12 5 22 1 60 17 23 55 22 60 42 1 5 12 22 17 23 42 55 60 L L L R R L L R R 12 12 5 5 5 23 23 23 1 1 60 60 17 17 55 55 22 22 22 42 42 42 12 5 22 1 23 60 17 55 22 60 42 12 5 23 22 1 60 17 55 23 22 42 1 5 12 17 22 23 42 55 60 Quicksort - Erinnerung Pivot-Element: 23 12 42 23 1 60 17 55 22 5

  4. Intuitive Lösung • Lade den Wert des Pivot-Elements und die ersten und letzen B Array-Elemente in den Main Memory • Starte normalen Quicksort • Laden und Schreiben bei Bedarf

  5. R R R R R R R R R R L L L L L L L L L L Pivot Intuitive Lösung: Beispiel EM: MM:

  6. Analyse: Intuitive Lösung • Analyse der I/O‘s äquivalent zur Laufzeitanalyse von Quicksort • Pro Rekursionstiefe: O(N/B) I/O‘s benötigt • Im average case beträgt die Rekursionstiefe O(log2 N) • I/O-Anzahl O(N/B log2 N/B) • interne Laufzeit O(N log2 N) • Im worst case (N2)

  7. Distribution Sort • Mit mehreren Pivot-Elementen arbeiten • Pivot-Elemente definieren „Buckets“ • Element muss in „Bucket“ einsortiert werden • Jeden „Bucket“ rekursiv sortieren bis Blockgröße B erreicht ist

  8. Berechnung der Pivot-Elemente (1) • Unterteile Eingabemenge in N/MChunks • Sortiere jeden Chunk • Nehme jedes a-te Element aus jedem Chunk in Array U auf (|U| = N/a) • Sortiere U • Berechne µ-1 äquidistante Pivot-Elemente aus dem Array U mit BFPRT (Blum-Floyd-Pratt-Rivest-Tarjan)

  9. Berechnung der Pivot-Elemente (2) Chunks (sortiert) Array U (sortiert) BFPRT µ-1 Pivot-Elemente

  10. Analyse:Berechnung der Pivot-Elemente • U kann mit O(N/B) I/O‘s erzeugt werden. • BFPRT benötigt O((|U|/B) lg µ) = O((N/aB) lg µ) I/O‘s Für a ≥ lg µ: O(N/B) • Insgesamt O(N/B) I/O‘s für die Berechnung der Pivot-Elemente

  11. Rekursion • Sortiere jedes Element in den richtigen „Bucket“ (Distribution) Bi := {x | pi ≤ x < pi+1} • Starte Rekursion auf jedem „Bucket“ • Wenn „Bucket“ Blockgröße erreicht hat dann intern sortieren

  12. -∞ Pivot 1 Pivot 2 Pivot 3 ∞ Beispiel µ=4 Blockgröße Rekursionstiefe: O(logµN/B)

  13. Analyse • Rekursionstiefe bis zur Blockgröße: O(logµ N/B) I/O‘s • Einsortieren kostet pro Rekursionstiefe O(N/B) I/O‘s • Gesamt: O(N/B logµ N/B) I/O‘s

  14. Literatur • Alok Aggarwal and Jerey Scott Vitter, 1988: „The Input/Output Complexity of Sorting and Related Problems“ • Jeff Erickson - Prof. an der University of Illinois: „Introduction: the standard external-memory model; upper and lower bounds for scanning (Θ(n)), searching (Θ(logB n) via B-trees), and sorting (Θ(n logm n) via mergesort); external comparison trees“ http://compgeom.cs.uiuc.edu/~jeffe/teaching/473/01-search+sort.pdf

More Related