56
Dec 02 '19
Is this in manim? It definitely looks like it
27
u/pedrovhb Dec 02 '19
It is! Source here.
6
u/AustinYQM Dec 03 '19
How hard is that to use. I would love to animate the different tree traversals for my students.
9
40
Dec 02 '19
Thank you for this!
(I have a data structures and algorithms final in like 2 weeks send help)
38
u/pedrovhb Dec 02 '19
Glad it's useful!
I'm practicing my Manim, so I'll probably do a couple more easy sorting algorithms before moving on to trees (:
13
1
1
1
u/Kaligule Dec 03 '19
Cool, how do you like manim? I found it incredibly hard to get into because of the lack of good documentation.
2
u/unable_to_give_afuck Dec 03 '19
I have my Object Oriented Design Patterns final next week. This was helpful! I hope we get visualizations of more sorting methods.
1
u/uber1337h4xx0r Dec 03 '19
Rip, that's the class that made me want to consider suicide.
I ended up failing it once, dropping it the second time, and barely passing the final time lol.
1
Dec 03 '19
Good you passed though!
I swear, I’m only not more panicked because my teacher provided us four practice finals on his website. He’s actually such a nice dude - too bad I’m trash at his class’ subject matter lmao
1
u/uber1337h4xx0r Dec 03 '19
It's not impossible at least. If a retarded person like me can pass, then so can you. And even on your first try lol
1
1
u/Alchestbreach_ModAlt Dec 03 '19
Finals in two weeks? Jeez what university do you go to. Ive done finals the first week of december for the last 3 years. I couldn't imagine schoolin it up almost to christmas
4
Dec 03 '19
It’s my last final and it’s on the 17th. My earliest is in a week (luckily it’s for an easy class).
3
u/Alchestbreach_ModAlt Dec 03 '19
You got this. Just remember 2 things.
Array index start at zero
You can pretty much use any primative data type for switch statements too.
7
u/uber1337h4xx0r Dec 03 '19
Erm... Data structures is so much deadlier than that.
Think big O, time complexity, breadth search red black tree traversal or something like that.
3
3
u/caninerosie Dec 03 '19
Array index start at zero
Unless your preferred language is lua, in which case indexes start at 1 for some reason
→ More replies (6)2
u/unkown-shmook Dec 03 '19
My discrete math teacher is making us take our 3rd exam on the 12th and our final a week after. No in class review at all, half the class already dropped.
1
Dec 03 '19
RIP. I failed discrete math the first time I took it and passed with a C later in a community college.
2
u/unkown-shmook Dec 03 '19
I’m at a B right now only because he never imputed my first exam so he’s gonna replace it with my final. Got lucky with how bad he is
→ More replies (1)1
u/Alchestbreach_ModAlt Dec 03 '19
Was discrete structures not an option? Man thats way easier then discrete math.
1
1
2
298
u/Shaky_Balance Dec 02 '19
89
37
u/yanitrix Dec 02 '19
That was the video my teacher showed us when we were talking about sorting in java
8
2
16
u/1RedOne Dec 03 '19
I'm waiting for someone to share the ones with colored lines which make noises while sorting, and it shows tons or tons of different ones
38
u/HiImLary Dec 03 '19
Whoever reposts this in 2 hours for the 10,000th time, give me credit.
19
u/1RedOne Dec 03 '19
I love bogosort
while not isInOrder(deck): shuffle(deck)
9
4
u/Cycloneblaze Dec 03 '19
After five minutes of the crescendos of other sorts, bogosort is incredibly relaxing
4
u/not_the_world Dec 03 '19
I love that it sounds exactly like bogo sort, kinda like a dial-up modem that was dropped on its head as a baby.
6
4
u/b2a1c3d4 Dec 03 '19
Can anyone tell me wtf is going on with bitonic sort?
3
u/mccoyn Dec 03 '19
Merging a reverse-sorted array with a forward-sorted array is very slightly faster than merging two forward-sorted arrays due to cache locality. Bitonic uses n storage slots mapped to n-element array, but it doesn't care what the mapping is. Alternating from reverse to forward sorting happens to be the fastest mapping.
2
u/thirdegree Dec 03 '19
Bitonic is my favorite. No idea how it works, it's just like "ok so we're gonna make some mountains, clean it up a little, need a few valleys... And now it's sorted!"
58
Dec 02 '19 edited Dec 02 '19
Why does it do a final scan after the penultimate one where no swaps were made? Surely we know we're done at that point.
Edit: looking again, it starts with a swap. Guessing that's why.
28
u/crimson1206 Dec 02 '19
Yeah your edit is correct. It only stops when there was no swap over one full iteration.
6
u/mattsoave Dec 03 '19
But you could safely stop after a pass where only the very first pair was swapped, right?
7
u/Nathanfenner Dec 03 '19
Yes, you can adaptively remember where the last swap was on the previous iteration, and stop looking past that point on future iterations.
(insertion sort still ends up faster)
2
u/Slapbox Dec 03 '19
In this case I think yes, because it was the leading pair of numbers that was swapped and that was the only swap. Someone please correct me if I'm wrong.
70
7
u/xebecv Dec 03 '19
I love this good old visualization of various different sorts: https://youtu.be/kPRA0W1kECg
3
1
u/G_Morgan Dec 03 '19
Bogosort - If you cannot handle me at my worst you don't deserve me at my best
6
Dec 03 '19
Ugh I hate watching bubble sort, I just want to grab it by the neck and shake it
3
u/Azzk1kr Dec 03 '19
Like Cocktailsort?
1
Dec 03 '19
I think cocktail/shaker has order n2 complexity as it's worst case, which is better than bubble actually. Cocktail is an innovation of bubble, no?
Edit: I can't deny bubble looks pretty nice in code though. It's so terse!
1
3
u/redalastor Dec 03 '19
When I was a teen and I learned to code with no CS notion at all, I invented my own sort which is bubblesort-ish but not exactly.
I would scan the array. If the two numbers I compared were sorted, I would move the pointer one cell further. If they weren't I would swap, then move the pointer left. Repeat until you reach the end of the array.
Is there a name for that algo?
7
Dec 03 '19 edited Feb 18 '26
This post was mass deleted and anonymized with Redact
compare nail stupendous follow north chief cake quicksand rainstorm detail
5
Dec 03 '19
I wonder if there's research in CS/maths trying to determine if there's a limited number of different sorting algos?
1
7
u/urbanspacecowboy Dec 03 '19
Sounds like the gnome sort, which is a simpler slower variation on the insertion sort.
3
u/redalastor Dec 03 '19
It is gnome sort!
I'm surprised to know I used it before it was introduced. I thought all simple sorting algos had been published many decades ago.
3
u/bubblesort Dec 03 '19
Yes! It looks exactly like me! This is gonna be my new social media picture.
3
u/PeasantSteve Dec 03 '19
Add it to the pile.
If you're going to do a bubble sort visualisation, at least have some folk dancing involved: https://youtu.be/lyZQPjUT5B4
1
2
Dec 03 '19
I only believe in crab sort. 🦀
1
u/spacelama Dec 03 '19
I was expecting this to be the David Attenborough bubble sort visualisation: (about the 4th or 5th reply down: https://twitter.com/histoftech/status/1200585772618924032 )
2
u/WalkingTaco42 Dec 03 '19
Algorithms are becoming something people take for granted - you just use whatever framework elements are there and don't really need to understand.
Back in the day, you had to write all this crap from scratch. Often just pulling code you wrote at some point and pasting it in there.
The real reason to understand how it works is efficiency. You need to know if the input list is going to be relatively large or not and then pick a sort based on that. [Big O notation]|(https://en.wikipedia.org/wiki/Big_O_notation) is helpful for that - so in this animation, showing consideration to the size of the dataset (7 here) and the number of times our sort box loops over the list should be highlighted.
6
3
u/MrSolidSht Dec 02 '19
1
u/VredditDownloader Dec 02 '19
beep. boop. I'm a bot that provides downloadable video links!
I also work with links sent by PM
Info | Support me ❤ | Github
3
3
5
u/SJWcucksoyboy Dec 02 '19
I feel like sorting algorithm visualizations have been done to death.
25
u/RayDotGun Dec 03 '19
Show me on this doll where the algorithm hurt you. We’ll sort this out, O(k)?
1
1
u/MozzieMouss Dec 03 '19
1
u/VredditDownloader Dec 03 '19
beep. boop. I'm a bot that provides downloadable video links!
I also work with links sent by PM
Info | Support me ❤ | Github
1
1
u/adorak Dec 03 '19 edited Dec 03 '19
also slow af ... I made a python appllication once, testing various sorting algorithms and visualizing how fast they are and I remember Bubble Sort is beyond bad :)
To no ones surprise TimSort performed the best (afair) ... it was a few years ago so a) I forgot a lot b) it might be wrong by now. But Bubblesort's big O is n^2 (in the worst case) and TimSort is n*log(n) - every algorith with n^2 will fail miserably in their respective worst cases. They are however, great to visualize. There's also a dance choreography I saw once, that showed mergesort (If I remember correctly) - that was great.
edit (if you wonder): my python program had various test cases, ranging from small to large lists that were already sorted, randomized, few switches, reversed etc.. afaik I sorted each case 10k times to be somewhat statistically relevant ... but as I said is was several years ago :(
1
u/iiTheBeast Dec 03 '19
I do have a question how do you calculate asymptomatic notation, lets say for this? I thunk it was n2 tho
1
Dec 03 '19
Why do people keep using bubble sort? I mean, isn't it one of the most time consuming sort types?
1
1
u/sdexca Dec 03 '19
I remember making this swotting years back with I first started C. Ah the old memories 😊
1
u/Sunstorm777 Dec 03 '19
Sorry if I sound ignorant, but why do computer scientists need to learn the sorting methods?
1
1
1
1
u/Asl687 Dec 03 '19
Used to do this on high score table for 8bit games. Add new score to bottom of table and do a single bubble sort pass every few frames, makes the new score move up the table line by line..
1
0
1
u/TheBowtieClub Dec 03 '19
Relevant: the Crab Shell Upgrade bubble sort https://twitter.com/geekandahalf/status/1200440963753283584
1
u/spacelama Dec 03 '19
Indeed, the video of that particular bubble sort is about the 4th or 5th reply down: https://twitter.com/histoftech/status/1200585772618924032
1
1
u/Pascal-C-El-Rojo Dec 03 '19
This is perfect timing, because I just learned this today in my Java class :)
0
-2
u/Dank-memes-here Dec 02 '19
Bad animation. Should do 1 less comparison each run, and early-out once sorted
0
0
u/Sir_Hurkederp Dec 02 '19
Thank you, i had to implement this but didnt quitr understand the algorithm i was given
0
0
0
-2
Dec 02 '19 edited Dec 07 '19
Those aren't bubbles. Those are numbers.
Edit: Zero appreciation for dad jokes. :(
0
u/Saurons_Monocle Dec 03 '19
This would be pretty useful in teaching an Intro to Data Structures class!
0
0
u/Mokaran90 Dec 03 '19
Useful, I was bashing my head around this one on the past weekend, it also does it with letters! Wtf!
0
-15
Dec 02 '19 edited Dec 03 '19
Why though? Why go through the trouble of creating a video explaining one of the worst sorting algorithms ever invented. Why do we even teach this in school?
edit: I really wasn't trying to gatekeep. Bubblesort is simply a shitty algorithm that has nothing to offer to the world. Teaching bubblesort is like teaching bogosort - there is nothing useful in the knowledge.
17
u/BruhWhySoSerious Dec 02 '19 edited Dec 02 '19
I always have to laugh when some gate keeper tries to act like a smart ass. Oh you are so smart but you can't see why they teach a stupid simple algo? Jesus Christ, it's to learn the basics and what not to do.
→ More replies (5)2
u/valarauca14 Dec 02 '19 edited Dec 02 '19
Not really?
Donald Knuth actually stated in "The Art of Computer Programming" there is no practical reason to teach Bubble Sort aside from the catchy name. He recommends teaching "Insertion Sort" as the first O(n2 ) sort students are taught.
Owen Astrachan (principle investigator of the multi-year AP Computer Science courses & exams) agrees. The guy is actually on a personal crusade to stop teaching Bubble Sort totally. He's used far harsher language to describe it.
There isn't a great reason to teach Bubble Sort. It isn't gate keeping, it is just wasting the teacher's & student's time because literally every other sort is superior. Shell Sort is actually far more intuitive, and Insertion Sort is heavily used in modern hybrid sorts algorithms (some of the fastest known, as a fall back mechanism within quick sort's partitions). There's way better uses of everyone's time than teaching Bubble Sort.
What I'm trying to say is prioritizing subject matter to be impactful and make best use of everyone's time isn't gate keeping.
3
u/chucker23n Dec 02 '19 edited Dec 03 '19
Donald Knuth actually stated in “The Art of Computer Programming” there is no practical reason to teach Bubble Sort aside from the catchy name. He recommends teaching “Insertion Sort” as the first O(n2 ) sort students are taught.
Bubble sort has nothing to do with a catchy name. It is stupid simple to explain to a broad variety of people. Regardless of sorting, it’s just an excellent beginner’s example of an algorithm.
Teaching insertion sort and pointing it out as O(n2) completely misses the point.
1
u/BruhWhySoSerious Dec 02 '19
I am shocked that a professor at one of the greatest comp sci programs on the planet thinks bubble sort is not worth his 2 minutes.
There isn't a great reason to teach Bubble Sort.
It's simple.
While a comp sci class at UC or an AP class will only spend 15 minutes on this, a community college course is going to spend days on this, and have MANY students missing any real mathematical background.
I'll actually look into the reasoning behind this later but I cannot imagine a good reason for skipping a 15 minute lecture on this purely as and introduction and example on what not to do. For many, understanding the difference between insertion, bubble, and merge is a complex topic which will need reinforcement.
→ More replies (4)1
Dec 02 '19
Yup, definitely wasn't trying to gatekeep.. was actually quoting my intro to CS professor from a decade ago.. he's known in his field for developing and writing books for CS101 courses. Gave a strong speech why he refused to teach bubblesort.
724
u/IdiotCharizard Dec 02 '19
good implementations of bubblesort won't do the extra comparisons after the n-kth index (n elements, kth iteration). Also, it can be very fast to check if the list is sorted rather than possibly wasting a few useless iterations