Sorting Algorithms

Visualize how different sorting algorithms organize data

Bubble Sort

Bubble Sort

Bubble Sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. It's easy to understand but inefficient for large datasets.

Time: O(n²)
Space: O(1)
Merge Sort

Merge Sort

Merge Sort is a divide-and-conquer algorithm that divides the array into halves, sorts them recursively, and then merges the sorted halves. It has consistent O(n log n) performance and is stable.

Time: O(n log n)
Space: O(n)
Quick Sort

Quick Sort

Quick Sort is a divide-and-conquer algorithm that picks a pivot element and partitions the array around it. It's one of the fastest sorting algorithms in practice, though worst-case performance is O(n²).

Time: O(n log n) average, O(n²) worst
Space: O(log n)
Insertion Sort

Insertion Sort

Insertion Sort builds the sorted array one element at a time by inserting each element into its correct position. It's efficient for small datasets and nearly sorted arrays.

Time: O(n²)
Space: O(1)
Heapsort

Heapsort

Heapsort is a comparison-based sorting algorithm that uses a binary heap data structure to sort elements.

Time: O(n log n)
Space: O(1)
Selection Sort

Selection Sort

Selection sort repeatedly selects the smallest element from the unsorted portion and places it at the beginning.

Time: O(n^2)
Space: O(1)
Counting Sort

Counting Sort

Counting sort is a non-comparison sorting algorithm that counts occurrences of each element.

Time: O(n + k)
Space: O(k)
Radix Sort

Radix Sort

Radix sort processes digits of numbers from least significant to most significant using a stable sorting algorithm.

Time: O(nk)
Space: O(n + k)