Hacker News new | ask | show | jobs
by Arainach 15 days ago
It's not, but it's conceptually very similar at first glance.

One important thing to note is that bubble sort places one element in the correct position each pass and then *stops looking at that position ever again*.

This algorithm looks at all N elements every pass.

Others have shared a bunch of great videos and writeups. Without reading them, my initial assumption is that this builds things bottom up (such that after the first pass, the element in position 0 is guaranteed to be the lowest element) and that despite it being compared again and again, it's essentially placing one element each pass, but I could be wrong.

1 comments

Technically the first pass will ensure that the smallest element ends up at position 0 even if it's looked at more times.

Bubblesort really is a family of "this is something I figured out myself that runs by looping in O(N^2) by moving things to the front/back"

> Technically the first pass will ensure that the smallest element ends up at position 0 even if it's looked at more times

Read it again; First pass ensures that the largest element ends up in position 0. Yet it somehow manages to sort ascending by the end.

It's not very intuitive and it's probably the least efficient sorting algorithm I've seen besides sleepsort[1]

[1]: https://www.reddit.com/r/programminghorror/comments/lgsd18/i...

Ah missed the part about the "swapped" equality, well since I will go ahead of J later on it's all good! :P