Sorting Algorithms Simulator — Bubble, Insertion & Selection Sort Visualized

Interactive sorting simulator — run bubble, insertion or selection sort on eight tagged values from mixed, sorted or reversed input, and compare comparisons, swaps and remaining inversions.

← Computer Science Labs
About this tool — how it works & FAQOpen ▾Close ▴

About the Sorting Algorithms Simulator

This simulator sorts eight tagged values one step at a time, highlighting each comparison and moving swapped values along separate arcs so their identities stay visible. You pick the algorithm and the starting order and compare the work each does.

What the simulator shows

• A 3D scene with tagged value columns, comparison brackets, operation counters and an order and inversion indicator. • An Algorithm selector (bubble, insertion, selection) and an Initial order selector (mixed, sorted, reverse). • Readouts for comparisons, swaps, progress (algorithm-specific confirmed prefix or suffix length), array length and remaining inversions. • Restart demonstration and Advance event buttons, and experiments for sorted input, selection on reversed input and insertion on reversed input.

Three strategies, three cost profiles

An inversion is a pair in the wrong order; a sorted array has zero inversions. Bubble sort compares adjacent pairs so the largest values settle to the right and it stops early when a pass makes no swaps: on sorted input it needs seven comparisons and zero swaps. Insertion sort moves the next value into a sorted prefix, and on reversed input needs twenty-eight comparisons and swaps. Selection sort finds the smallest remaining value and swaps it into place, and needs twenty-eight comparisons regardless of initial order. Watching the counters across the three orders shows how input shape matters.

What the model is and is not

The array has eight deterministic values. Insertion sort uses adjacent swaps for visualization rather than a shift-optimized implementation, and bubble sort includes early termination. Timing is event playback, not benchmark performance, and the progress marker is an algorithm-specific count rather than a universal percentage.

Frequently asked questions

Does fewer animation frames prove faster real execution?

No. Real performance also depends on data size, memory behavior and implementation. The lab counts comparisons and swaps, not time.

What is the inversion count of a sorted array?

Zero. No later value is smaller than an earlier one, which is the condition the remaining-inversions readout reaches at the end of every run.

Why does selection sort do the same comparisons on any input?

Because it always scans the whole remaining region to find the minimum, regardless of whether the data is already in order — twenty-eight comparisons for eight values.

Why is bubble sort fast on sorted input here?

It includes early termination: a full pass with no swaps means the array is sorted, so it finishes after seven comparisons and zero swaps.

Related tools & guides