PublicSoftTools
Tools6 min read

Sorting Algorithm Visualizer — Bubble, Quick, Merge Sort Explained

Sorting algorithms are the gateway to understanding algorithmic thinking. Watching comparisons and swaps animate in real time makes abstract concepts like O(n²) versus O(n log n) immediately visible. The free sorting algorithm visualizer on PublicSoftTools animates five algorithms with colour-coded steps.

Algorithm Comparison

AlgorithmBestAverageWorstSpaceStable
Bubble SortO(n)O(n²)O(n²)O(1)Yes
Selection SortO(n²)O(n²)O(n²)O(1)No
Insertion SortO(n)O(n²)O(n²)O(1)Yes
Merge SortO(n log n)O(n log n)O(n log n)O(n)Yes
Quick SortO(n log n)O(n log n)O(n²)O(log n)No

How to Use the Visualizer

  1. Open the sorting algorithm visualizer.
  2. Select an algorithm from the dropdown.
  3. Set the array size (8–50 bars) and speed (Slow / Medium / Fast).
  4. Click Randomize to generate a new random array, then Sort to animate.
  5. Watch the colour-coded steps: blue = comparing, orange = swapping, red = pivot, green = sorted.

Algorithm Breakdowns

Bubble Sort — the comparison baseline

Bubble Sort repeatedly compares adjacent elements and swaps them if they are out of order. After each pass, the largest unsorted element "bubbles" to its final position. It is O(n²) and rarely used in production, but it is the clearest algorithm to watch animate — every swap is immediately visible.

Selection Sort — minimum selection

Selection Sort scans the unsorted portion to find the minimum element, then swaps it into position. It always makes exactly n−1 swaps regardless of input order, making it predictable. The blue pivot indicator shows the current scan minimum.

Insertion Sort — the card-hand analogy

Insertion Sort builds a sorted portion from left to right, inserting each new element into its correct position like sorting a hand of playing cards. It is O(n) on nearly-sorted data, which makes it the best algorithm for small or almost-sorted arrays — and why many production sorts use it for final passes.

Merge Sort — divide and conquer

Merge Sort recursively divides the array in half, sorts each half, then merges the halves together. It is always O(n log n) and stable. The merge step is the core — two sorted subarrays are combined by repeatedly taking the smaller front element. Watch how the number of active comparisons decreases as subarrays merge.

Quick Sort — the practical champion

Quick Sort selects a pivot (shown in red), partitions all smaller elements to the left and larger to the right, then recurses on both sides. Its average case is O(n log n) and it is cache-friendly, which is why it is the default algorithm in most standard libraries despite its O(n²) worst case.

Using the Visualizer to Study

Compare step counts directly

Set array size to 30 and run Bubble Sort, then Quick Sort on the same randomized array. The step counter shows the difference in operations — typically 5-10× fewer steps for Quick Sort. This makes O(n log n) vs O(n²) tangible rather than theoretical.

Watch Insertion Sort on small arrays

Set size to 8 and compare Insertion Sort against Merge Sort. On small inputs, Insertion Sort often completes in fewer steps because it has lower overhead despite the same asymptotic complexity.

Visualize Sorting Algorithms

Animate Bubble, Selection, Insertion, Merge, and Quick Sort with colour-coded steps and step counters.

Open Sorting Algorithm Visualizer