Sorting race
Sorting race is an interactive experiment in Algorithms Visualised, a free simulation from StudyFi Lab that runs right in your browser.
All four algorithms sort the same input, and in every lane one step is one comparison or one move. The O(n²) algorithms (bubble and insertion) grow much faster with the array size than the O(n log n) ones (merge and quick). The order also depends on the input: on a nearly sorted array insertion sort often wins.
Try this: Run the race on a random array of 40 elements, then switch to nearly sorted. Does the winner change?
Frequently asked questions
What does the “Sorting race” experiment show?
All four algorithms sort the same input, and in every lane one step is one comparison or one move. The O(n²) algorithms (bubble and insertion) grow much faster with the array size than the O(n log n) ones (merge and quick). The order also depends on the input: on a nearly sorted array insertion sort often wins.
How do I try “Sorting race”?
Run the race on a random array of 40 elements, then switch to nearly sorted. Does the winner change?
Studying for a test?
Upload your notes and StudyFi turns them into flashcards, tests and podcasts.