Reputation: 1342
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...)?
Upvotes: 6
Views: 7215
Reputation: 502
Bubble sort is performed in nested loop but gnome sort is performed in a single loop. Moreover, bubble sort compares adjacent elements in successive passes throughout the list whereas gnome sort compares adjacent elements back and moves the index back and forth. These are just two differences. rest are explained in the link given up.
Upvotes: 0
Reputation: 446
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 :)
Upvotes: 4
Reputation: 3346
followed the link to gnome sort... i read one thing there which was quite good, that gnome sort does sorting like human beings do. Imagine yourself doing sorting of a list, thats what gnome sort is.
Upvotes: 1
Reputation: 9796
Incredibly detailed wiki articles exist for both gnome sort as well as bubble sort.
Upvotes: 2