0

# Name of a sorting algorithm

Down below in the link, there is a sorting algorithm. Please can anyone go through the codes and tell me if there is any similar algorithm like it in the current world, if yes then what is it's name? https://code.sololearn.com/cA13a3a10A42/?ref=app

8 Answers

+ 3

Nice one!
It's an interesting one for sure but I think in essence this is a variation on bubblesort. We can see that small elements are bubbling to the front of the list, but you also do this thing where you swap elements that are apart by 2 so occasionally one element stops bubbling and another one takes over.
The best way to see what is happening is to have it sort a reversed list, the algo generally moves numbers towards the front one at a time just like bubblesort would.
It's likely O(nÂ²) like regular bubblesort aswell, but maybe a bit more efficient because you are partially sorting as you are bubbling. It's really neat to watch the algorithm work! You should do one of these videos where you let it sort 200 random numbers but visualized as a bar chart.

+ 1

Ananiya Jemberu as far as I know, Python uses Tim Sort, but I wasn't talking about that; I asked whether the code matches with any of the sorting algorithms or not.

+ 1

Oh ok Faheem I hope some one will help u out :P

+ 1

Faheem That looks interesting. Great job writing your own sorting algorythm. To get an answer to something like this, youâ€™ll probably have to post it on stackoverflow or other website for more advanced users. Maybe someone here will know. But either way, great job coming up with your algorythm on your own.

+ 1

Jerry Hobby Thanks!

0

Heres the official sort library https://docs.python.org/3/howto/sorting.html if you are interested on you can go through it

0

Schindlabua Thanks!

0

Thanks to Coder Kitten for giving it the name, Crane Sort.
If visualized, then this algorithm will look like Insertion Sort. Though key concepts are slidely different, but algorithmitically there is a lot of similarities between it & Gnome Sort.
It is much slower than Insertion Sort; think like this, suppose a crane is moving throughout the array and sorting it. Now at index i if it gets an unsorted element, then it'll have to move back to find the place where the element will fit. After putting the element in the correct place, the crane will have to come all the way back to i again. Since it has no magical power, that it will disappear and again appear at i+1th index, so it'll unnecessarily keep checking the sorted part of the array upto i.
This is the key difference between the Insertion Sort and the Crane Sort.
Now you might ask, why don't we give it the magical power? The answer is simple. This is also an algorithmic idea, probably in this algorithm it is degrading the runtime, but who knows, oneday t

Hot today

Python â€” File Handling

0 Votes

Help me solve this (using loop)

3 Votes

What is wrong? Error on test.

1 Votes

Help me wiht python

1 Votes

Question is write a c program to print prime numbers up to n and print the largest number in array.

1 Votes

Help me

0 Votes