Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between bubble sort and gnome sort

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...)?

like image 366
lllluuukke Avatar asked Mar 04 '12 04:03

lllluuukke


People also ask

What is the difference between sort and bubble sort?

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.

Which sort is better than bubble sort?

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.

Why is gnome sort called gnome sort?

Gnome Sort is based on the technique used by the standard Dutch Garden Gnome (Du.: tuinkabouter).

Is bubble sort and shell sort same?

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).


1 Answers

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 :)

like image 143
Hamza Tahir Avatar answered Oct 21 '22 06:10

Hamza Tahir