Quicksort-1:快速排序-1
Animation
Animated visualization of the quicksort algorithm. The horizontal lines are pivot values.
Full example of quicksort on a random set of numbers. The shaded element is the pivot. It is always chosen as the last element of the partition. However, always choosing the last element in the partition as the pivot in this way results in poor performance ( O(n2) ) on already sorted arrays, or arrays of identical elements. Since sub-arrays of sorted / identical elements crop up a lot towards the end of a sorting procedure on a large set, versions of the quicksort algorithm which choose the pivot as the middle element run much more quickly than the algorithm described in this diagram on large sets of numbers.
Complexity
Class | Sorting algorithm |
---|---|
Data structure | Array |
Worst case performance | O(n |