Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which sorting algorithm is this?

I need to know which sorting algorithm sorts like this:

[4 1 7 6 3 11]

[4 1 7 3 6 11]

[4 1 3 7 6 11]

[1 4 3 7 6 11]

[1 4 3 6 7 11]

[1 3 4 6 7 11]

Tomorrow is exam, and I'm confused. It shall be a simple algorithm, but it can't be insertion sort / selection sort, i even looked at heapsort (absolutely) and merge sort - last option.

I would say it's mergesort, but with the addition it should be easy, I'm unsure. Or i heavily misunderstood how the algorithms work. :(

Thanks for reading, at least! :)

like image 312
Martin Košťál Avatar asked Jul 14 '26 21:07

Martin Košťál


1 Answers

As you can see, the algorithm works by comparing two adjacent values, which makes it a Bubble Sort, however the interesting thing to note here is that instead of the sorting being done in left to right passes, it seems to be doing them in passes from right to left; which in turn makes this a Reversed Bubble Sort.

like image 52
Rivasa Avatar answered Jul 16 '26 11:07

Rivasa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!