An efficient in-place divide-and-conquer sorting algorithm. [Best: O(nlgn), Average: O(nlgn), Worst: O(n2), Space: O(n)]
Idea
The idea of quick sort is a divide-and-conquer approach that partitions the array into subarrays with pivots. When an item is picked as pivot, the items are rearranged such that all smaller items are moved to the left of pivot and all larger items are to the right. The array becomes sorted when all subarrays are all sorted (at most 1 item).
Implementation
Below is an implementation of quick sort in golang.
package sorting |
References: