A visualization of the following sorting algorithms: * Bubble Sort * Shell Sort (Donald Shell, 1959) * Quicksort (Tony Hoare, 1960) Music by Chris Zabriskie ( / chriszabriskie )
It's a great question, but it doesn't have an answer, at least not yet. But that's okay. Maybe 20 years from now someone uses this compound in a medical imaging device, or to aid in the treatment of raw sewerage, or as a precursor to a different compound that is useful. The thing about scientific discovery is that you don't really know beforehand if it's going to be a "useful" discovery or not. Not every scientific discovery is a "diamond in the rough", but when you do find your diamonds, it sort of justifies all of the lumps of coal you found as well.
Not really... Bubble sort has only two redeeming features, it's dead simple to implement, and it's a stable sort (won't change order of elements that are equal). And for both of those there are algorithms that strictly better. Even if just cocktail sort (bi-directional bubble sort), which is just as easy and converges on average twice as fast. But I have to admit that I have used bubble sort in the past when I haven't been able to use a ready made library algorithm for one reason or another, because unless you dataset is large (and I know it will never be large), it often makes little practical difference on modern machines whether your sort finishes in 1 microsecond or 100 microseconds. Even a set like 10 000 elements is "only" 100 million iterations and my desktop can churn a cool 300 billion operations a second. (Qsort average case is NlogN operations, or about 100 000)
I'm a high school programming student. The other day I tried to make both bubble sort and quicksort for some practice and measured their times for fun. I was blown at how much the difference actually was - Bubble took *7 minutes* while Quick took *115ms* . This video proves to me I didn't measure it wrong.
@@ericrossi7039 the point is that redix sort doesn't actually compare values and more like recreates them so you can't use redix sort for objects and those sort of things
I completely agree. Not just does it carry the same information (value and list position) but is an easy way to visualize it. You can easily see how every, at least seems to, work. I didn't think of bubble sort as the algorithm to create such a curved line but it makes sense in retrospect. This is also great at showing the difference between such things as merge and shell or bubble and cocktail shaker. Well, if you use it with bongo it's still pointless. I love my teacher's explanation. "Imagine you have a deck of cards. Shuffle the on he table. Set the house on fire and collect the cards when they fly out. If they're not sorted, try it with the neighbors house. If your cards all burn that just means there's nothing left to sort - you did it."
No it wasn't, two means 2 which is a unit of measurement, too means "as-well" such as "me too" "I am too" " you are way too edgy" or not "You two need to go home" or "me two" doesn't work because you are only one person. In order to use "two" properly in that regard, it require you to rephrase the sentence such as "That makes two of us" or "Count me as two".
He meant "we are too" and was using "We" to refer to me, you and all who share the same thought, not himself therefor. You can't refer to yourself as "we" so therefor he was refering to people like you and me, thus not being "two"...
ThePC007 You would need, on average, 1200^1200 tries to get the right answere. You would also need to check wether the sort has been succesfull. half the time, 1/2, the first two numbers do not match up costing 1 comparison, 1/4 of the sorts will have at least the first two numbers lined up costing two comparisons, 1/8 of the sorts will have the first 3 lined up, costing 3 comparsons and so on. This series converges to 2 comparisons on average. Which means that you would need around 1200^1200*2 comparisons to complete this series. This number is larger than a googleplex and if you forced every computer on this planet to perform this calculation untill the heat death of the universe and you still wouldn't be finished.
Actually, because Bogo is completely random, the time you spend could range anywhere from 0 to infinity. There is still a chance Bogo sort can complete it, albeit very miniscule. You could be lucky enough and get it on your first try. Or you could be unlucky and never get it. With probability there is no certain amount of times it would take.
The visualisation with the dots really helped me to understand how quicksort actually worked. Without the bars it just seemed to make so much more sense.
Large set bubble sort is beautiful - i suspect also there are a ton of really interesting mathematical and geometric learnings to be had from the study of that curve.
Bubble sort time scales exponentially, so any reasonably sized set will be horribly slow. It is the fastest sort for tiny sets, like less than 10 numbers, so it does have niche uses, or as the final part of some other sorts. Check out the O(n) time complexity of other sorts.
He means the ENTIRE bubblesort at the end, as in the bubblesort with 12500 numbers. The one where the creator fast-forwarded and put a fast-forward symbol in the corner of the screen.That probably would've taken like an hour without it. Probably much longer actually.
@@draconis17 Not without this visualisation. A computer can perform tens of thousands of comparisons a second. It will spit out the sorted array in seconds. It's only taking long because there is a delay set between each comparison for demonstration purposes. In real world application, the time difference between using bubble sort and quick sort on 12,500 items is inconsequential.
Am I the only one who did bubble sort manually with a set of playing cards just to see how slow it was compared to how I normally sort cards? (It took 44 min. 41.89 sec. by the way, I have no life)
From this visualization i can clearly tell what with large sets of data bubble sort is just useless, and the winner is quick sort. Not because it's "quick", but because the way it looks like. May look simple, but that algorythm clearly tell by itself: NOW! MULTITHREAD ME! DO IT! You can't run bubble or insertion or selection, but quick sort is easy to split and run in multiple threads.
+Stefan Alecu Timsort is a hybrid sort (merge sort and insertion sort). The goal is to understand the individual algorithms and their strengths and weaknesses. After that, any combination of algorithms can be combined, such in the case of Timsort. Watch for more sorting videos on my channel in the future!
cparsons2005 i am surprised that you responded. yes, i know that it's a hybrid sort. also, why don't you use sound of sorting? you can find it on panthema.com
+Stefan Alecu I'm surprised I responded, too...I'm pretty busy most of the time and generally don't have a lot of time for commenting and replying (but I'm trying to find more time, lately). The reason I point out it's a hybrid sort is that my channel is geared towards educating and informing. So, my goal is to introduce the non-hybrid sorts and attempt to show the various strengths and weaknesses of each. After that, we can work on improving them by creating hybrid sorts (such as Timsort). As far as not using the sound of sorting, I haven't heard of it, before, but I like developing and creating my own things (which is most of the fun, for me).
+ThereWasNoFreeName honestly you could easily multithread any of them by just splitting the dataset up, sorting in sections, then doing a very fast merge sort to recombine them at the end
I remember my CS Teacher showing us this video in a lesson probably in year 8 or 9 of high school. Now coming back here when I’m approaching the end of my CS A Level in year 13, having gained a much better understanding of these algorithms. Life is crazy.
I LOVE this video! Especially the segment with the larger sets of data. I've been trying to visualize quicksort for awhile now (I keep losing track of the recursion) this painted it perfectly for me!
The bubble is by far the prettiest... shame it's no so good at actual practical sorting. Still, the only sort that my CS teacher managed to explain to us all at school.
I love this because this is an excellent visual of each algorithm. I didnt even know that these existed, but I feel like I've learned something today so thank you.
Very nice visualization. And thanks for sorting the exact same datasets. But it needs to be paired with some comparison and swapping or data access statistics.
+dlwatib I agree about the additional stats. I'm working on some new videos to explain these (and other) algorithms in a better way. I'm including comparison/access stats in those videos. Hopefully I'll be able to start publishing those in the near future!
I think the creator thought he’s gonna show something interesting to people who actually care but 99% of people are just awake at 3am and have nothing better to do
i'm pretty new on programming world, but i wanted to know how do you make the computer to take it's time when sorting, i mean, normally it would do it within a second or less....
I'd love to see a Quicksort that takes a bit more time to figure out the best pivot (sampling a few random values from the array and taking the median) and then delegates to Bubble Sort when the array is shorter than a given constant. I have a feeling that would be very fast!
Sampling random value is a good way to find a pivot. But bubble sort is one of the slowest among the simple sort. In fact, there's timsort which is hybrid between mergesort(stable, no slow down from bad pivot) and insertion sort(quickest simple sort) to do the job in python programming language.
There's a mistake. You've used Comb Sort instead of Shell Sort. Comb Sort uses Bubble Sort that compares elements from far apart, while Shell Sort uses Insertion Sort for this. Both are similar, but have different optimal gap values. Comb Sort does more passes and the gap value shrinks slower, while Shell Sort takes more time for each pass, but a sub-sequences are sorted, so gap value can shrink faster.
This is hypnotizing. Algorithms are fascinating. Been obsessed with them lately as i've been trying to learn how to code from a very theoretical low-level fundamental perspective. Always wanted to learn to program as a kid and feel more in love with music but the comp sci bug is biting back again.
Ste fan Yeah. I can see some straightforward lines forming and unite. (If he uses dot graph like these) If it also has sound it might be epic to listen!
They learned it from their Computer Science 101 book and it is fairly easy to code. Comb sort would be much faster and only need an extra IF loop though. Bubble sort is slow because it only compares elements 1 apart (and small elements take a very long to get sorted to the beginning), Comb sort compares elements much farther apart, while Comb Sort starts a large distance apart (about 70% the size if the input), and steadily makes the distance smaller. For example, the Shell sort above actually appears to be a Comb Sort, as it appears to only compare pixels in two positions, while Shell sort would compare an array. Assuming the distance apart is 50, then Comb sort would compare 101 vs 151, 102 vs 152, 103 vs 153, aso. Shell sort would compare 1 vs 51 vs 101 vs 151 vs . . . ., then 2 vs 52, 102 vs 152, aso . . . Shell sort means the input data is divided into smaller arrays, and each of those arrays is in sorted order. But if programmers need a simple (and slow) sort, they could at least try cocktail shaker sort. First it does a Bubble sort to move the highest value to the end, then it does a 'bubble' array sort going from end to beginning to find the smallest item and move it to the beginning. Hope this helps.
I like this dot visualization a lot better than the bar graphs in most sorting videos, this gives more of an intuitive insight into why the algorithms are clever or in the case of bubble sort why it is so wasteful, from a spatial standpoint rather than just the abstract explanation.