&
MIT OpenCourse
Introduction to Algorithms, Lec 4
Tzu-Li Tai (Gordon Tai)
@ NCKU TechOrange
DIVIDE: Divide A[p...r] into left/right partition according to a pivot value, so that elements on the left is smaller than elements on the right. Calculate the index of the pivot.
CONQUER: Recursively Quicksort the partitions
Looks hard...right?
Well... it's actually super easy
WHY?
Lecture 4 allowed me to realize
how fun algorithms can be when
combined with mathematics !!!
Randomly select the pivot element (instead of always using the last element as pivot).
Remember to swap the chosen pivot with last element.