Sorting Algorithm Summary

Algorithm Complexity Table

Sorting Algorithms
Algorithm Average Time Worst Time Best Time Space Complexity Stable In-place Type
Bubble Sort O(n²) O(n²) O(n) O(1) Comparison
Selection Sort O(n²) O(n²) O(n²) O(1) X Comparison
Insertion Sort O(n²) O(n²) O(n) O(1) Comparison
Merge Sort O(n log n) O(n log n) O(n log n) O(n) X Comparison
Quick Sort O(n log n) O(n²) O(n log n) O(log n) X Comparison
Heap Sort O(n log n) O(n log n) O(n log n) O(1) X Comparison
Radix Sort O(nk) O(nk) O(nk) O(n + k) X Non-comparison
Shell Sort O(n3/2) O(n2) O(n log n) O(1) X Comparison
You can click on and scroll the table.

Key Definitions

Sorting: Sorting is the process of arranging elements in a specific order (ascending or descending) based on a criterion, typically numerical or lexicographical.

In-place Sorting: An algorithm is in-place if it requires a constant amount of extra space (O(1)) to rearrange the elements. These algorithms do not use additional data structures for storage.

Stable Sorting: A sorting algorithm is stable if it maintains the relative order of equal elements in the input array. In other words, two equal elements retain their positions relative to each other even after sorting.

Dummy button