Hacker News new | ask | show | jobs
by smusamashah 1453 days ago
Here is how it looks. https://xosh.org/VisualizingSorts/sorting.html#IYZwngdgxgBAZ...

If you compare it with both Insertion and Bubble sort. You can see it looks more like insertion sort than bubble sort.

4 comments

I guess it can be thought of as an unoptimized insertion or bubble sort.

I think it is very possible to write this algorithm by mistake in intro compsci classes when you try to code a bubble sort by heart. I would think TAs may have many such instances in their students' homework.

There's a surprisingly large class of "sorts people accidentally write while intending to write a bubble sort".

This one is kind of special, though, since it's somehow more offensive to intuition than bubble sort itself.

Bubble sort is offensive to intuition? I would have said it was the most intuitive, because each step is very simple and you only have to remember one numeric variable in your core loop.
Bubble sort's inner loop is so hilariously pessimal that it's incredibly easy to accidentally write an insertion sort because you intuition tells you it can't possibly be intended to be that bad.
I am guilty. I wrote this sort for a gnu screen session menu years ago and even named my function bubsort.
The video from the article (https://www.youtube.com/watch?app=desktop&v=bydMm4cJDeU) is much better because it highlights the index of the outer loop, which is unclear from the cascading visualization there. By seeing the indexes it becomes clear that (1) in the area before the outer index, every value gets swapped in and out of the outer loop location to put them in order, and (2) at the end of the first outer loop iteration, the largest element will be at the location of the outer loop index, and so everything to the right is unchanged in each iteration.
This is nice. I had a way to highlight indexes at one point in this tool. Got rid of it when I was trying to add a way to visualize any custom algo. I should add it back. It adds more value/info to the visualization.
And here's a version I wrote that visualizes it on your terminal https://github.com/radiantly/simplest-sort
Is the visualization supposed to animate? I can’t figure out how to make it start.
There is a "start" button at the end of the list of sorts.
If you click it multiple times it's wonderfully chaotic.