Algorithm Visualizer
Watch sorting algorithms in action with step-by-step visualization.
O(n²) | Space: O(1)Visualizing Sorting Algorithms
Sorting algorithms are fundamental to computer science. This visualizer lets you watch how different algorithms work step by step. See comparisons in yellow, swaps in red, and sorted elements in green.
Understanding how these algorithms work helps you choose the right one for your data. Bubble sort is simple but slow. Quick sort is fast but recursive. Each has trade-offs.
Bubble Sort
Bubble sort repeatedly steps through the list, compares adjacent elements, and swaps them if in wrong order. Simple to understand but O(n²) makes it impractical for large datasets.
Selection Sort
Selection sort finds the minimum element and places it at the beginning. Also O(n²) but makes fewer swaps than bubble sort. Good for minimizing write operations.
Insertion Sort
Insertion sort builds the sorted array one element at a time. Efficient for small or nearly sorted data. O(n²) worst case but O(n) best case.
Quick Sort
Quick sort uses divide and conquer with pivot partitioning. Average O(n log n) makes it practical for large datasets. Most real-world sorting uses quick sort variants.