Sorting Algorithm Race Screensaver
The Sorting Algorithm Race screensaver runs four real classic sorting algorithms live side by side on the same shuffled data, with real comparison and swap counts. It is free, runs in your browser, and ESC exits.
How the Sorting Algorithm Race screensaver works
The saver runs real, correct implementations of bubble sort, insertion sort, selection sort and quicksort, each on its own identical copy of a shuffled array.
Every algorithm advances one real step per frame, so you watch their true relative speed and behavior side by side.
Real running counters track each algorithm's comparisons and swaps as it works.
Once every algorithm finishes, the data reshuffles and a fresh race begins.
Why sorting algorithms differ so much
Sorting is one of the oldest problems in computer science, and the same task can be done in very different ways. Bubble sort, insertion sort and selection sort all take roughly quadratic time on random data: doubling the list length multiplies the work by about four. They are easy to write and worth knowing, which is why they are taught first.
Quicksort, developed by Tony Hoare in 1959 and published in 1961, uses divide and conquer. It picks a pivot, partitions the data into smaller and larger items and then repeats on each side, which gives an average of roughly n log n comparisons (about 1.39 n log₂ n). The difference matters more as lists grow, since a few hundred elements are hardly distinguishable but millions are enormously so.
Notice that the counts of comparisons and swaps behave differently. Selection sort makes few swaps but many comparisons, while insertion sort does well when the data is already nearly ordered. Big-O notation describes growth, not a stopwatch result, so on tiny arrays the simple methods can look competitive.
A worked example
Quicksort typically finishes first with far fewer real comparisons than bubble sort, exactly illustrating the real algorithmic complexity difference between them.
Settings & tips
- Accent recolours the active comparison bars.
- All four algorithms are real, correct, unmodified implementations.
- A fresh shuffle starts automatically once every race finishes.
Frequently asked questions
- Are these real sorting algorithms?
- Yes — real, correct implementations of bubble, insertion, selection sort and quicksort.
- Is a key needed?
- No — it is a pure local computation.
- Is it free?
- Yes — free, no download, in your browser.
- Why does quicksort usually win?
- Its real average-case complexity is faster than the simpler algorithms it races against.
- Which algorithm is best on nearly sorted data?
- Insertion sort. Each item only has to move a short distance, so its running time approaches linear on data that is almost in order.
- Does quicksort ever do badly?
- Yes. If partitioning is badly unbalanced at every step, for example by always choosing the first element as pivot on already sorted data, it degrades to quadratic time. Choosing the pivot at random or from the middle avoids that case.