Gnome Sort vs Insertion Sort
Same 110 values, same shuffle, same speed. Insertion Sort finishes first and turns gold: 5,689 operations to 8,318.
The numbers
- Gnome operations
- 8,318
- Insertion operations
- 5,689
- Gnome average
- n²
- Insertion average
- n²
- Gnome worst
- n²
- Insertion worst
- n²
Gnome Sort
Gnome Sort steps forward while neighbours are in order and steps back, swapping, when they aren't. More on Gnome Sort.
Insertion Sort
Insertion Sort takes each value in turn and slides it left until it sits in the right place. More on Insertion Sort.
FAQ
Which is faster, Gnome Sort or Insertion Sort?
On this shuffle of 110 values, Insertion Sort needed 5,689 operations and Gnome Sort needed 8,318, about 1.5× as many. On average Gnome Sort is n² and Insertion Sort is n².
Which one is stable?
Both are stable.
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.