Bubble Sort vs Selection Sort
Same 110 values, same shuffle, same speed. Selection Sort finishes first and turns gold: 6,097 operations to 8,678.
The numbers
- Bubble operations
- 8,678
- Selection operations
- 6,097
- Bubble average
- n²
- Selection average
- n²
- Bubble worst
- n²
- Selection worst
- n²
Bubble Sort
Bubble Sort walks through the list swapping neighbours that are out of order, until a pass makes no swaps. More on Bubble Sort.
Selection Sort
Selection Sort finds the smallest remaining value and swaps it to the front, again and again. More on Selection Sort.
FAQ
Which is faster, Bubble Sort or Selection Sort?
On this shuffle of 110 values, Selection Sort needed 6,097 operations and Bubble Sort needed 8,678, about 1.4× as many. On average Bubble Sort is n² and Selection Sort is n².
Which one is stable?
Bubble Sort is stable; Selection Sort is not.
How is the race fair?
Both algorithms start from the same shuffle and run the same number of operations per frame. Every comparison, swap and write counts as one operation, so the one that needs fewer operations finishes first.