Bubble Sort
Click 'Play' or 'Step Forward' to begin visualization.
Algorithm Concept & Mechanics
Theory & Analysis
Step-by-Step Execution Mechanics
Ideal Real-World Use Cases
Strengths & Advantages
Limitations & Trade-offs
Supported Sorting Algorithms
Click on any algorithm card to inspect its Big-O performance metrics, pseudocode, and launch it directly into the interactive visualizer.
Bubble Sort
StableBubble Sort is a foundational comparison sort that repeatedly steps through an array, compares adjacent pairs, and swaps them if out of order. Larger values continuously bubble up to the end of the array.
Selection Sort
UnstableSelection Sort divides the array into a sorted prefix and an unsorted suffix. In each pass, it scans the entire unsorted region to locate the minimum element and places it at the end of the sorted prefix.
Insertion Sort
StableInsertion Sort mimics how people sort cards in their hand. It inspects elements sequentially and inserts each item into its correct relative position within an expanding sorted prefix.
Merge Sort
StableMerge Sort is a classic divide-and-conquer algorithm. It recursively splits the array into single-element sub-lists, then merges adjacent sorted lists back together in sorted order.
Quick Sort
UnstableQuick Sort is a high-performance divide-and-conquer algorithm. It selects a pivot element and partitions the array so all items smaller than the pivot precede it, while larger items follow it, then recursively sorts the sub-partitions.
Heap Sort
UnstableHeap Sort uses a Binary Max-Heap array structure to find and extract the maximum element repeatedly, placing it at the end of the array.
Counting Sort
StableCounting Sort is an integer-based non-comparison algorithm. It counts occurrences of each key value and computes prefix sums to place elements directly into sorted positions.
Radix Sort
StableRadix Sort processes numbers digit-by-digit from Least Significant Digit (LSD) to Most Significant Digit (MSD) using a stable sub-sort like Counting Sort for each digit position.
Shell Sort
UnstableShell Sort generalizes Insertion Sort by comparing and swapping elements separated by diminishing gaps (e.g. N/2, N/4 ... 1) to quickly move out-of-place items close to their final positions.
Timsort
StableTimsort is a real-world hybrid algorithm combining Insertion Sort (for small contiguous blocks called runs) and Merge Sort (to combine sorted runs). Used by Python, Java, and V8.
Complexity & Performance Tradeoffs
Side-by-side comparison of Big-O time and space complexity characteristics across all implemented sorting algorithms.
| Algorithm | Best Time | Average Time | Worst Time | Space Complexity | Stability |
|---|---|---|---|---|---|
| Bubble Sort | O(n) | O(n²) | O(n²) | O(1) | Stable |
| Selection Sort | O(n²) | O(n²) | O(n²) | O(1) | Unstable |
| Insertion Sort | O(n) | O(n²) | O(n²) | O(1) | Stable |
| Merge Sort | O(n log n) | O(n log n) | O(n log n) | O(n) | Stable |
| Quick Sort | O(n log n) | O(n log n) | O(n²) | O(log n) | Unstable |
| Heap Sort | O(n log n) | O(n log n) | O(n log n) | O(1) | Unstable |
| Counting Sort | O(n + k) | O(n + k) | O(n + k) | O(n + k) | Stable |
| Radix Sort | O(d · (n + k)) | O(d · (n + k)) | O(d · (n + k)) | O(n + k) | Stable |
| Shell Sort | O(n log n) | O(n^1.3) | O(n²) | O(1) | Unstable |
| Timsort | O(n) | O(n log n) | O(n log n) | O(n) | Stable |
Bubble and Insertion Sort achieve linear O(n) best-case time when inputs are pre-sorted by aborting early or skipping inner shifts.
All comparison-based sorting algorithms are mathematically bounded by O(n log n) operations in the average case.
Merge Sort trades O(n) auxiliary memory space for stability and guaranteed O(n log n) time across all inputs.
Deep-Dive into Sorting Theory & Classification
Master the key theoretical paradigms, complexity boundaries, and operational tradeoffs behind modern sorting routines.
Quadratic Comparison Sorts
Bubble, Selection, and Insertion Sort inspect pairs of elements via nested loops. They are intuitive and memory efficient, though inefficient on large inputs.
Divide & Conquer Strategies
Merge and Quick Sort break problems recursively into logarithmic sub-problems, bypassing the quadratic runtime barrier for large arrays.
Stability & Data Ordering
A sort is stable if items with identical keys maintain their original order. Crucial when sorting complex objects by multiple consecutive criteria.
Theoretical Lower Bounds
Decision tree modeling proves no comparison-based sort can perform better than \(\Omega(n \log n)\) comparisons in the worst-case scenario.