Sorting
Ordering data step by step
Bubble Sort
Repeatedly swaps adjacent elements that are out of order, bubbling the largest value to the end on each pass.
Time O(n²) · Space O(1)
Selection Sort
Scans the unsorted part for the smallest element and swaps it into the next position of the sorted prefix.
Time O(n²) · Space O(1)
Insertion Sort
Grows a sorted prefix one element at a time, shifting larger values right until the new element fits.
Time O(n²) · Space O(1)
Shell Sort
Insertion sort over shrinking gaps: distant elements move first, so the final pass has little work left.
Time O(n log² n) · Space O(1)
Merge Sort
Recursively splits the array in half, sorts each half, then merges the two sorted halves back together.
Time O(n log n) · Space O(n)
Quick Sort
Divide-and-conquer sort that partitions the array around a pivot, then recursively sorts each side.
Time O(n log n) · Space O(log n)
Heap Sort
Builds a max-heap, then repeatedly swaps the root to the end and re-heapifies the shrinking prefix.
Time O(n log n) · Space O(1)
Radix Sort
Sorts without comparisons: runs a stable counting pass per digit, from least to most significant.
Time O(d · (n + k)) · Space O(n + k)
Counting Sort
Tallies how many times each value occurs, prefix-sums the counts into final positions, then places each element directly — no comparisons.
Time O(n + k) · Space O(n + k)
Bucket Sort
Scatters values into a few range buckets, sorts each bucket, then concatenates them back — fast when the data spreads evenly.
Time O(n + k) · Space O(n + k)