All Articles

Time and Space Complexities of Popular Sorting Algorithms

Sort Worst Case TC Avg Case TC Best Case TC Space Complexity Is Stable
Bubble Sort O(N2)O(N^2) Θ(N)\Theta(N) Ω(N)\Omega(N) O(1)O(1) Yes
Selection Sort O(N2)O(N^2) Θ(N2)\Theta(N^2) Ω(N2)\Omega(N^2) O(1)O(1) No1
Insertion Sort O(N2)O(N^2) Θ(N2)\Theta(N^2) Ω(N)\Omega(N) O(1)O(1) Yes
Merge Sort O(NlogN)O(N logN) Θ(NlogN)\Theta(N logN) Ω(NlogN)\Omega(N logN) O(N)O(N) Yes
Quick Sort O(N2)O(N^2) Θ(NlogN)\Theta(N logN) Ω(NlogN)\Omega(N logN) O(N),O(logN)O(N), O(logN) No
Heap Sort O(NlogN)O(N logN) Θ(NlogN)\Theta(N logN) Ω(NlogN)\Omega(N logN) O(1)O(1) No1
Counting Sort O(N+R)O(N + R) Θ(N+R)\Theta(N + R) Ω(N+R)\Omega(N + R) O(R)O(R) Yes

  1. The default implementation is not stable, however it can be made stable using some special technique.