Basic ideas:
Selection sort: Find the smallest item, put it at the front.
Heap sort: Use MaxPQ to find the maximum element, put it at the front.
Merge sort: Merge two sorted halves into one sorted whole.
Insertion sort: Determine where to insert the current item.
Quick sort: Partition the array into two halves around a pivot, then recursively sort the subarrays.
Selection Sort
Θ(N2)\Theta (N²)Θ(N2)
Θ(N2)\Theta(N²)Θ(N2)
Θ(1)\Theta(1)Θ(1)
Heap Sort
Θ(N)∗\Theta (N)^*Θ(N)∗
Θ(NlogN)\Theta(N \log N)Θ(NlogN)
Bad cache performance.
Merge Sort
Θ(N)\Theta(N)Θ(N)
Insertion Sort
Best for small N or almost sorted.
Last updated 1 year ago