Sorting Lab
Compare six sorting algorithms through individual comparisons and writes.
About this tool
Choose an example or enter 1–200 finite numbers. Spaces and commas separate items; use a decimal point and optional exponent. Empty comma entries are errors. Negative and zero values appear around the zero line. Small lists show bar values; Current values exposes the exact sequence at any size. The original input, algorithm, example and raw speed setting are saved locally. Reload restores them without resuming the animation. A draft above the storage budget warns and retains the previous saved version; copy it before leaving.
Start animates; Pause and Resume keep the same generator and counters. Step advances exactly one comparison, swap or merge write. Restart returns to the original numbers. Editing numbers or changing the algorithm/example starts a new sequence. Hidden tools pause; animation does not catch up after a long suspended frame.
Speed is 1–1200 operations per second, default 8. Frames accumulate a time budget; high speeds can perform multiple operations per displayed frame. It is an animation setting, not a measured CPU speed or benchmark.
Positions are one-based. Highlighted bars identify the last operation. A comparison leaves values unchanged; a swap writes two array positions, a merge write counts one. A swap is one Step but two writes. Completion clears the highlight. For 2 1 with Bubble sort: compare (1 comparison, 0 writes), swap (1, 2), then finish.
Bubble, insertion and merge preserve the order of equal marked values; selection, Lomuto quicksort and heap do not promise stability. Bubble/selection take quadratic comparisons; insertion is linear on sorted input and quadratic in the worst case. Merge/heap are O(n log n); this unshuffled last-pivot quicksort may be quadratic. This is a teaching visualization with a 200-item limit, not a production sorting benchmark.
Princeton — Algorithms, Elementary Sorts
The controls share one toolbar above a chart that adapts to the available width and height. Changing the input or algorithm resets the sequence but does not start animation; use Start or Step. The current operation and comparison/write counts remain below the chart.
Step back reverses the most recent operation and restores the values and counters. Step and Resume replay recorded operations before continuing the same run. This works after sorting finishes, too.