Skip to content
All apps

Sorting Race

About this app

Bubble, Insertion and Selection Sort in a race: three lanes sort the same list at the same tick, one tick being one comparison. Bars glide past each other when they swap, counters show comparisons and swaps. With 5, 2, 9, 1, 7, 3 Insertion is done after 11 comparisons, Bubble and Selection after 15; sorted, Insertion needs 5. Single view with the pseudocode and Python of the slides, predictions, and doubling up to n = 102400 next to the times from the slide.

With explain mode: an AI tutor walks you through the app, points out what matters in the scene and answers your questions.

Three simple sorting algorithms

Bubble Sort compares neighbours and swaps them if they are the wrong way round; in each pass the largest element of the unsorted part thus moves to the back. Insertion Sort moves the next element to the left in the sorted beginning until it fits. Selection Sort finds the smallest element in the rest and swaps it to the front. Bubble and Selection always need n(n−1)/2 comparisons, 15 for six values. Insertion needs between n−1 and n(n−1)/2, depending on how sorted the input is.

What the app shows

Three lanes sort the same list at the same tick; one tick is one comparison. Bars show the values, the two compared ones light up and glide past each other when they swap. Pointers i, j and min, the sorted part, counters for comparisons and swaps and a progress bar make the effort visible. In the single view the pseudocode and Python code of the slides run alongside, with the current line marked. All numbers match real Python 3.13.

Try it yourself

Start the race with 5, 2, 9, 1, 7, 3: Insertion is done after 11 comparisons, Bubble and Selection after 15. With the sorted list Insertion needs only 5; reversed, all three arrive together. Own or random lists of up to 16 values are possible, and in the single view the app asks before each comparison whether there will be a swap. In the Doubling panel n grows from 100 to 102400, next to the times from the slide.

Frequently asked questions

How many comparisons does Bubble Sort need?
The simple version compares all neighbours of the unsorted part in every pass, n(n−1)/2 times in total, whatever the input. For 6 values that is 15 comparisons, for 100 values 4950. Without an early exit it keeps going even when the list is already sorted.
Why is Insertion Sort fast on presorted lists?
Insertion Sort compares each new value with its left neighbour and stops as soon as that neighbour is not larger. On a sorted list every value costs exactly one comparison, n−1 in total. On a reversed list every value has to move all the way to the front, which takes n(n−1)/2.
Why does double the length mean four times the work?
With n(n−1)/2 comparisons the effort grows quadratically: twice as many values are each compared with twice as many others. 4950 comparisons for n = 100 become 19900 for n = 200 and 79800 for n = 400, about four times as many each time.
What does the Sorting Race app show?
Bubble, Insertion and Selection Sort run against each other on the same list at the same tick, with counters for comparisons and swaps, the pseudocode and Python code of the slides, prediction questions and a doubling table next to measured running times.

Subject: Computer science

More from Computer science

A VisuApp by heyprof: interactive, free in your browser, no sign-up. What is a VisuApp? · All apps