← Back to Gallery

Gnome Sort

Comparisons:0
Swaps:0
Array Accesses:0
Gnome Position:0
Max Reached:0
Status:Ready

Gnome Sort

Also called "stupid sort." A single pointer (the gnome) walks forward if the current pair is in order, or swaps and walks backward if not. Like insertion sort but without a nested loop.

Worst:   O(n²)
Average: O(n²)
Best:    O(n) (already sorted)
Space:   O(1)

Watch the gnome bounce back and forth! Equivalent to insertion sort without nested loops. Conceptually the simplest sorting algorithm.