Gnome Sort is a sorting algorithm really similar to Insertion sort. Gnome Sort is based on dividing the data structure in two sublists: a sorted one, and an unsorted one. For every cycle, the algorithm picks an element of the unsorted sublist and moves it with sequential swaps to the right position in the sorted sublist.
The main difference from the Insertion Sort is that the implementation doesn't require nested loops. Like the Insertion Sort, this algorithm is more efficient on small data structures almost sorted.
Average Complexity | O(n2) |
---|---|
Best Case | O(n) |
Worst Case | O(n2) |
Space Complexity | O(1) |