Quick sort
1.Quick sort
divide and conquer algorithm
The partition is not based on the length or an artificial index, it's based on a pivot
The pivot is an element from the list
The list is partitioned with all elements smaller than the pivot on one side and larger than the pivot on the other
The pivot partition is applied to all sub-lists till the list is sorted
2.Code
The "partition" method which finds a pivot and moves elements to before or after the pivot
The "quicksort" method which does the recursive call to sort the sub-list
partition method
quicksort method
3.Complexity
The average case complexity of quick sort is O(NLogN)
The algorithm is not adaptive
It takes O(LogN) extra space for call stack in the recursion
The worst case for space complexity could be O(N): 依實作出來的層數覺定
It is a stable sort
Last updated