Download presentation
Presentation is loading. Please wait.
1
High level version Partition AlmostQuickSort
9/21/2018 CS 303 – Quick Sort Lecture 16
2
QuickSort QuickSort(l,r) If (r-l) < 1 Return i Partition(l,r)
QuickSort(l,i-1) QuickSort(i+1,r) Partition(l,r) <= x x >=x r l i 9/21/2018 CS 303 – Quick Sort Lecture 16
3
Partition How can you Partition, so that: Partition is O(n) Why?
If both these conditions are met, then QuickSort is O(n log n) If not...not! Discuss various Partition techniques scan from l,r inwards – swap when stuck scan from l r – swap when <x Discuss choice of pivot use statistical sample to improve odds 9/21/2018 CS 303 – Quick Sort Lecture 16
4
AlmostQuickSort AlmostQuickSort(l,r) If (r-l) < 15 Return
i Partition(l,r) AlmostQuickSort(l,i-1) AlmostQuickSort(i+1,r) QuickSort(l,r) InsertionSort(l,r) Partition becomes easier to code Final InsertionSort is O(n) alas...(Almost)QuickSort is still O(n2) (in theory...but...) 9/21/2018 CS 303 – Quick Sort Lecture 16
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.