Interactive Algorithm Education

Visualize & Master Sorting Algorithms

Explore 10 classic & modern sorting algorithms in real-time step-by-step animation: Bubble, Selection, Insertion, Merge, Quick, Heap, Counting, Radix, Shell, and Timsort. Watch element comparisons, swaps, step counts, and Big-O efficiency metrics.

Interactive Studio

Bubble Sort

Speed 100ms
Size 20
Step Progress 0 / 0
Comparisons 0
Swaps / Shifts 0
Status Ready
Default
Comparing
Swapping
Pivot / Min
Sorted
Step Explanation

Click 'Play' or 'Step Forward' to begin visualization.

Bubble Sort • Time: O(n²) • Space: O(1)
Pseudocode Reference
          
        

Algorithm Concept & Mechanics

Theory & Analysis

Step-by-Step Execution Mechanics

Ideal Real-World Use Cases

Strengths & Advantages

Limitations & Trade-offs

Algorithm Catalog

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

Stable

Bubble 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.

Ideal Use: Best suited for small datasets, educational visual demonstrations, or arrays that are already known to be nearly sorted.
Best
O(n)
Worst
O(n²)
Space
O(1)
Implementation Difficulty
★ ☆ ☆ ☆ ☆ 1/5
Trivial
Sorted Output Preview n=8
12
18
29
33
42
64
75
91

Selection Sort

Unstable

Selection 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.

Ideal Use: Useful when memory write/swap operations are exceptionally costly, as Selection Sort performs at most O(n) swaps.
Best
O(n²)
Worst
O(n²)
Space
O(1)
Implementation Difficulty
★ ☆ ☆ ☆ ☆ 1/5
Trivial
Sorted Output Preview n=8
12
18
29
33
42
64
75
91

Insertion Sort

Stable

Insertion 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.

Ideal Use: Ideal for small arrays (n ≤ 30), online streaming data, or nearly sorted arrays. Frequently used as the base case for Timsort and Introsort.
Best
O(n)
Worst
O(n²)
Space
O(1)
Implementation Difficulty
★ ☆ ☆ ☆ ☆ 1/5
Trivial
Sorted Output Preview n=8
12
18
29
33
42
64
75
91

Merge Sort

Stable

Merge 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.

Ideal Use: When guaranteed O(n log n) worst-case time complexity and stability are required, or when sorting linked lists and external files.
Best
O(n log n)
Worst
O(n log n)
Space
O(n)
Implementation Difficulty
★ ★ ★ ☆ ☆ 3/5
Moderate
Sorted Output Preview n=8
12
18
29
33
42
64
75
91

Quick Sort

Unstable

Quick 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.

Ideal Use: Default choice for general-purpose in-memory sorting where average performance and cache locality matter most.
Best
O(n log n)
Worst
O(n²)
Space
O(log n)
Implementation Difficulty
★ ★ ★ ☆ ☆ 3/5
Moderate
Sorted Output Preview n=8
12
18
29
33
42
64
75
91

Heap Sort

Unstable

Heap Sort uses a Binary Max-Heap array structure to find and extract the maximum element repeatedly, placing it at the end of the array.

Ideal Use: When guaranteed O(n log n) time complexity and O(1) space complexity are strictly required without recursive call stack risks.
Best
O(n log n)
Worst
O(n log n)
Space
O(1)
Implementation Difficulty
★ ★ ★ ★ ☆ 4/5
Challenging
Sorted Output Preview n=8
12
18
29
33
42
64
75
91

Counting Sort

Stable

Counting 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.

Ideal Use: When key range K is small relative to array size N (e.g. sorting test scores, ages, or character frequencies).
Best
O(n + k)
Worst
O(n + k)
Space
O(n + k)
Implementation Difficulty
★ ★ ☆ ☆ ☆ 2/5
Easy
Sorted Output Preview n=8
12
18
29
33
42
64
75
91

Radix Sort

Stable

Radix 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.

Ideal Use: When sorting large lists of fixed-length integers, string keys, or network addresses.
Best
O(d · (n + k))
Worst
O(d · (n + k))
Space
O(n + k)
Implementation Difficulty
★ ★ ★ ☆ ☆ 3/5
Moderate
Sorted Output Preview n=8
12
18
29
33
42
64
75
91

Shell Sort

Unstable

Shell 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.

Ideal Use: When medium-sized arrays need fast in-place sorting without recursive stack overhead.
Best
O(n log n)
Worst
O(n²)
Space
O(1)
Implementation Difficulty
★ ★ ☆ ☆ ☆ 2/5
Easy
Sorted Output Preview n=8
12
18
29
33
42
64
75
91

Timsort

Stable

Timsort 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.

Ideal Use: General-purpose real-world sorting of heterogeneous real-world data (default algorithm in Python, Java, Rust, V8 JS).
Best
O(n)
Worst
O(n log n)
Space
O(n)
Implementation Difficulty
★ ★ ★ ★ ☆ 4/5
Challenging
Sorted Output Preview n=8
12
18
29
33
42
64
75
91
Algorithm Comparison Matrix

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
⚡ Adaptive Optimization

Bubble and Insertion Sort achieve linear O(n) best-case time when inputs are pre-sorted by aborting early or skipping inner shifts.

📐 Lower Bound Limit

All comparison-based sorting algorithms are mathematically bounded by O(n log n) operations in the average case.

💾 Space Trade-offs

Merge Sort trades O(n) auxiliary memory space for stability and guaranteed O(n log n) time across all inputs.

Theory & Concepts

Deep-Dive into Sorting Theory & Classification

Master the key theoretical paradigms, complexity boundaries, and operational tradeoffs behind modern sorting routines.

O(n²)

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.

Bubble • Selection • Insertion
O(n log n)

Divide & Conquer Strategies

Merge and Quick Sort break problems recursively into logarithmic sub-problems, bypassing the quadratic runtime barrier for large arrays.

Merge Sort • Quick Sort
⚖️

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.

Stable vs Unstable
Ω(n log n)

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.

Decision Tree Limit