Bubble sort and gnome sort, they have the same complexity on worst, best, and average cases. What is the difference between bubble sort and gnome sort (not their names...)?
In bubble sort, two adjacent elements are compared. If the adjacent elements are not at the correct position, swapping would be performed. In selection sort, the minimum element is selected from the array and swap with an element which is at the beginning of the unsorted sub array.
Best case complexity is of O(N) while the array is already sorted. Number of swaps reduced than bubble sort. For smaller values of N, insertion sort performs efficiently like other quadratic sorting algorithms.
Gnome Sort is based on the technique used by the standard Dutch Garden Gnome (Du.: tuinkabouter).
Shellsort, also known as Shell sort or Shell's method, is an in-place comparison sort. It can be seen as either a generalization of sorting by exchange (bubble sort) or sorting by insertion (insertion sort).
Okay i'm revising this post, as I didnt have much time for the last one but i realize that perhaps I should have explained more.
So basically. gnome sort is a variation of the insertion sort. While insertion sort goes through , say, an ENTIRE array of integers and places each element in its proper position, gnome sort tries to be more efficient and does the same thing but adds to this by looping back when a swap occurs, saving an iteration.
If that didnt make any sense, again, these articles would really help if you give them a glance.
For the insertion sort algorithm: http://codingmash.com/2012/07/the-insertion-sort-algorithm/
For the gnome sort : http://codingmash.com/2012/07/gnome-sort-a-variant-of-insertion-sort/
Hope it helped :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With