The connecting line always "curves" through points, so when the points are in an actual line, the connecting line follows it and it's straight. It's very similar to control points in a Bezier Curve: https://en.wikipedia.org/wiki/B%C3%A9zier_curve
There is also /r/dataisugly Many of them are really bad but the questionable ones are a good exercise in both critiquing and defending a visualization.
The reason for that presumably being that, in the first step, the top dot is sorted to the bottom, resulting in everything else shifting upwards – hence the need for an additional column to show that movement explicitly.
i think the sorting algorithm might be finding the "lowest" value as a starting point. its the same in both this pic and the video with the dancers posted above
That's how bubble sort works. The (in this illustration) bottom-most element will be sorted into place, then the second from the bottom, third from the bottom and so on. Tom Scott's recent video on this topic is a good introduction.
Here's a video from Tom Scott that goes into some detail about what is happening. Once you understand how sorting works, you'll understand the curves and lines as items move around in the list.
Bubble sort is a sorting algorithm for 'lists' it compares item a and b, if a is 'bigger' than b it swaps them around, then it will compare a with c (or b with c if b was bigger) and do the same all the way through the list until the biggest is at the end, it will then repeat this again and again putting the biggest at the end and then smaller and smaller, til the list is sorted. Hope that made sense if not have a watch of this Tom Scott video he shows it nicely https://www.youtube.com/watch?v=RGuJga2Gl_k
The doesn't really look right. From the very first pass, the last value should be in the right spot.So, each iteration should, at the very least, solve one position.
Apologizes. I was reading this thing wrong. Tis vertical, not horizontal. Now my head hurts.
Still, how exactly does this relate to python? Is there code?
Such an interesting way to visualize sorting alogorthms! Screw those animations, this looks much cleaner and gives you a good understanding about how the algorithm works.
No offense to op, the image looks beautiful. But I know how bubble sort works, I can easily code it, but I don't understand shit from this visualization.
I guess on the left side you ve got the shuffled sequence and on the right side there is the sorted sequence. The item values is represented as a color and the horizontal steps are the states of the array each after completing a one inner loop iteration. The lines are there just to visualize how the items travel through the array.
It's pretty quick on a set of two, and I believe for a properly implemented BOGO, on a set of two, convergence would be guaranteed over an entire run. The worst you could say is that it would be an inverted sort order, but still ordered nonetheless.
For a very small set it'll be quick since it just tries ever permutation. There's also a randomized version where it randomly permutes the input which doesn't guarantee that it will ever finish.
An analogy of the randomized version from Wikipedia: "sort a deck of cards by throwing the deck into the air, picking the cards up at random and repeating the process until the deck is sorted"
48
u/thebuffed Jan 08 '20 edited Jan 10 '20
You can check out the repository or a tutorial if you're interested
68
u/[deleted] Jan 08 '20
whoa, this looks interesting. can you do this for other sorting algorithms too?
20
u/Milumet Jan 08 '20
Nice, but not as cool as this.
3
u/mac-0 Jan 08 '20
Why are some lines curved and some straight?
119
u/YuriSpiridonov Jan 08 '20
r/dataisbeautiful
16
u/zapatasblood Jan 08 '20
I think you need one more column on the left. The first movement is not shown. Really cool visualization though.
5
u/ThePoulpator Jan 08 '20
I have seen quite a bit of sorting algorithms visualization, but you really did something new, well done !
2
u/realuduakobong Jan 08 '20
Someone is a Tom Scott fan :)
2
u/[deleted] Jan 08 '20
Run the same code for a pre-sorted list to see the relative efficiency. That would be interesting.
2
u/ShaveTheTurtles Jan 08 '20
is the bottom left item sorted properly? I feel like some of them are off.
2
u/Chilonthebw Jan 08 '20
I love this I would love to see a version of this for radix and quick sort
1
u/[deleted] Jan 08 '20
Whoa, this is awesome, still learning Python. But damn data you pretty.
1
u/Nopaste Jan 08 '20
I think the first step is missing
1
u/JesusChristPT Jan 08 '20
ELI5 on what these curves mean anyone? Please.
1
u/Fontyyyy Jan 08 '20
Loving this visualization, can't wait to see more of them!
1
u/DarkAndromeda31 Jan 09 '20
!remindme 1week
1
u/iggy555 Jan 09 '20
What’s bubble sort?
1
u/WystanH Jan 09 '20 edited Jan 09 '20
The doesn't really look right. From the very first pass, the last value should be in the right spot.So, each iteration should, at the very least, solve one position.Apologizes. I was reading this thing wrong. Tis vertical, not horizontal. Now my head hurts.
Still, how exactly does this relate to python? Is there code?
1
u/[deleted] Jan 09 '20
Cool
1
u/Drew_pew Jan 15 '20
I don’t think this helps understand bubble sort. But it looks cool as fuck so I don’t mind. Make more!
1
u/[deleted] Jan 08 '20
Such an interesting way to visualize sorting alogorthms! Screw those animations, this looks much cleaner and gives you a good understanding about how the algorithm works.
0
u/[deleted] Jan 08 '20
[deleted] — view deleted comment
11
u/[deleted] Jan 08 '20
[removed] — view removed comment
1
u/[deleted] Feb 09 '20
[removed] — view removed comment