"you'd have to be quite a good programmer to work out how to do something that runs that badly..." Fantastic quote!
@ShootMyMonkey
11 жыл бұрын
An interesting consideration is the mechanism of storage. At one defense contractor I worked at, we had machines with no real RAM to speak of, and even transient data would be stored on tape media. Because of that, a ping-pong bubble sort was always the fastest method in practice because it dealt with adjacent elements (didn't have to deal with the seek times). Because of the linear seek times, it saved time by actually doing work as the tape wound one way or the other.
@Computerphile
11 жыл бұрын
Really glad you are liking it - there are PLENTY more to come! PS: Tell your mates about us! >Brady
@tapiok
10 жыл бұрын
Nice that you included bogo sort!
@tobywong2657
8 жыл бұрын
To this day,he is still random sorting...
@jayvkman
4 жыл бұрын
Good video, but I'd like to challenge Alex's theory at 4:50 that smaller lists are "nearly sorted and therefore BubbleSort is faster" when he's using uniform random. The data rather suggests a tipping point between bubble and merge somewhere 20~40 elements, that's around when you'd run out of Level 1 CPU cache (64 bytes). That most likely explains why bubble sort is initially much faster, because doing 1000 swaps on 32 elements in L1 cache is less CPU work than a handful recursive method calls in the JVM each allocating 2 arrays and copying data. It should remind everyone that Big-O is just theory ignoring how computers really work. These days cache misses dominate performance, unlike in the 90's when multiplications were slow and memory was fast. I'd also like to point out that his approach to micro-benchmarking Java code is prone to incorrect data. For small input sizes he is running in interpreted mode (JIT requires 10k iterations) also you don't want to call `nanoTime()` in a tight loop, it's an expensive call and thus will dominate cost for smaller input sizes. Look into JMH next time you want to benchmark in Java.
@Mike10131994
11 жыл бұрын
Quick sort does this: 1) Choose a random pivot, the pivot is used to compare the numbers of the list 2)Create 2 lists, "greater" and "less" 3)Go through each number (except the pivot) in the list. If its greater than the pivot, add it to "greater". If it's less than or equal, add it to "lesser" 4)Recursion! Basically, repeat 1-3 for each and every "greater", append the pivot, then append the "less" list after you apply steps 1-3. It's hard to explain, but relatively easy to code
@Computerphile
11 жыл бұрын
Indeed it was not me... Most of the computerphile videos are made by Sean Riley (we always say who made the film in the full video description if you want to double check) I'll still be making a few myself and come along for the odd interview (just because I like being involved!) - but Sean is the main man and you can usually assume he is the an behind the camera/edit! >Brady
@JPlatGaming
11 жыл бұрын
So far I've liked all the Computerphile videos, but I think this is one of the better ones. I'm a 16 year old self taught programmer and I think this channel is a great way of introducing new people to computing. Great job Brady!
@Skeluz
11 жыл бұрын
I can't wait for more on sorting. I know it very well but it is very nice to hear someone explain it so well in just 10 minutes.
@Computerphile
11 жыл бұрын
Thanks... Sean, unlike me, knows how to use After Effects... >Brady
@thresholdofdave
11 жыл бұрын
That paper they write on takes me back to my primary school days. Nice touch. Well done
@Computerphile
11 жыл бұрын
It will be covered soon! >Sean
@phyyl
11 жыл бұрын
we could compute the time to compute for each method, take the best one before sorting!! what an awesome sorting algorithm!
@DFYX
11 жыл бұрын
Btw: thumbs up for including BogoSort. There's probably only one sorting algorithm that's even crazier: Intelligent Design Sort. It says something like "Look at your data. Some higher being has decided that this is the order you need. Therefore consider it sorted" Intelligent Design Sort uses O(1) time (constant time) in all cases.
@Uejji
11 жыл бұрын
Bubble sort will always be relevant, because it's easy to remember, easy to write and relatively quick on extremely small datasets, along with having extremely low overhead.
@MySchari
11 жыл бұрын
Thank you for making this video. This shows that the audience is really important to you guys.
@Garrison86
2 жыл бұрын
Wow! Great demonstration illustrating Big O notation
@severynkozak9131
11 жыл бұрын
Buublesort doesn't rely on a list's last element being the largest. Every time you parse the list (pass over every element), the largest element within the unsorted portion (the left) is moved into the sorted portion (the right). Thus, the series is sorted by ordering values in descending order of magnitude (backwards).
@rageagainstthebath
11 жыл бұрын
Gnome sort, as far as I can recall, is about making one step back after the switch, and it seems to make more sense than starting from the beginning.
@orbital1337
11 жыл бұрын
Just a few months ago we were doing sorting algorithms in my CS course and I was bored enough to implement 20 different sorting algorithms and benchmark them. Here's my top 8 algorithms for 1 mil elements: 1. Bit-adaptive radix sort (can do 200 mil numbers in 2 seconds on my PC) 2. Flashsort 3. Introsort 4. Mergesort 5. Quicksort 6. Shellsort (very simple to implement) 7. Heapsort 8. Smoothsort (look it up, it's really cool).
@CanOzmaden
11 жыл бұрын
I would like to see more on programming languages, their history, pros and cons, basic abilities of each, thank you!
@MrAskolein
11 жыл бұрын
The best sorting algorithm is using recursivity. The video was excellent. Your channel is getting great
@MasterHigure
11 жыл бұрын
Bubble sort is the simplest one to implement, and a good introduction to algorithms in general. Also, it serves as an excellent example of how different algorithms which at a first glance might both seem more or less efficient to untrained eyes actually perform very differently.
@iabervon
11 жыл бұрын
I want to see radix sort, and a discussion of how you can beat the theoretical limits if you're willing to break the rules. (If you have a limited number of values, you can sort really fast by putting the cards in piles by number and never comparing them with each other.) A lot of the biggest improvements in CS come from solving the problem you actually have to solve, rather than the general case.
@MalliMania
11 жыл бұрын
Sorting Algorithms are a thing of beauty!
@MrShysterme
11 жыл бұрын
People don't watch these videos to learn sorting algorithms or serious computer science. Please look at the general flow of the channel. Perhaps they want to show the most intuitive, yet rather slow, algorithm and then compare it to others. It is so intuitive, it is the one I reinvented when I first started programming as a kid and needed to sort a list, but no one had told me yet that you could reuse the code of others.
@gellarieb88
11 жыл бұрын
algorithms and data structures exam next friday. those sorting videos are pretty good for understanding. thanks, brady :)
@crazedvidmaker
11 жыл бұрын
i think its important to note that in mergesort, the lists arent split in the way that he split them. the first half is sorted before the second half moves at all.
@Artificial-Insanity
11 жыл бұрын
Wow, this is exactly what I thought you should do next.
@xtieburn
11 жыл бұрын
For those wanting a lovely visual way of seeing sorting algorithms the appropriately named sorting-algorithms site has them all for comparison. Its problem sizes cant get too large but its one of the best references for various cases I know of.
@meanbark1976
11 жыл бұрын
It would be awesome if someone come up with English subtitles for these videos (just like numberphile!). Because English is not my mother tongue and you all got funny accents. Thanks for the channel!!
@MrWazzup987
11 жыл бұрын
i'M new to programing so looking at the end code with knowledge of purpose and process is very helpful
@mcvoid1
11 жыл бұрын
It's good to see some actual computer science in computerphile. Also, quicksort rules merge sort drools!
@Tastiestbeaner
11 жыл бұрын
Brady! This channel is really turning into something great. Being an IT guy, its really apparent how little people understand fundamental computer concepts that can really be a benefit in any vocation. I am really excited to see the networking video :D.
@Niosus
11 жыл бұрын
You can look it up yourself if you want. The idea behind the algorithm is what matters, the actual implementation in code is basically turning what he said in code. An algorithm shouldn't be seen as a piece of code, but as a general strategy to solve a problem.
@iabervon
11 жыл бұрын
In fact, "Timsort", which is the built-in library sort in a bunch of languages, is a combination of merge sort and insertion sort (which is kind of a better-organized bubble sort, which does the same number of comparisons, but only O(n) swaps). It's particular worthwhile to have great performance for lists that are either already in order or nearly in order.
@AngusPearson
11 жыл бұрын
I was just about to comment about it being called bogo sort, but he got it in! I'm happy now.
@bidule22222
11 жыл бұрын
The kraft paper has been replaced by the classic and very appropriate dot-matrix printing paper. Excellent!
@Friedeggonheadchan
11 жыл бұрын
Excellent video! Please continue on this route here.
@alcesmir
11 жыл бұрын
Recursive thinking doesn't always require recursive functions. Mergesort for example can easily be rewritten using loops, even though the algorithm uses recursive concepts (as in reducing a problem to simpler subproblems).
@pupper775
11 жыл бұрын
This is the best video yet!
@DFYX
11 жыл бұрын
That could take a while. They use a lot of different techniques combined and a lot of them need a quite solid understanding of how data structures, parallel computing and networks work. Have a look at lectures like "Advanced Data Structures" and "Parallel Algorithms" if you're still interested.
@kenkku
11 жыл бұрын
So to answer your question, in terms of how algorithms are usually compared, no. Algorithms are analyzed with a slightly simplified way to calculate the number of actions to take - an algorithm that does 2*n actions and an algorithm that does 20*n actions are considered to have the same running time (n operations). The other one is 10 times slower, but it is ALWAYS 10 times slower - unlike in the case of bubble sort and merge sort, where bubble sort just gets worse and worse.
@papalevies
11 жыл бұрын
Nicely explained video. Computing science concepts like Big O notation and sorting are really interesting.
@yannickbernaerts2325
11 жыл бұрын
Indeed, one extra statement isn't going to effect the performance in a negative manner. There're btw a lot of little tweaks you could use to speed up bubblesort (in some occasions). You could go from left to right and then switch and sort from right to left and back from left to right and so on.
@Computerphile
11 жыл бұрын
Quicksort will be covered soon! >Sean
@hedanit0
11 жыл бұрын
The last sorting algorithm is the fastest sorting algorithm on quantum computers. They can test every combination at the same time, and return the right one.
@ZackNagaich
11 жыл бұрын
You are correct, it is generally implemented with recursion.
@IstasPumaNevada
11 жыл бұрын
That is correct, because it will always do the same number of steps for the same sized list (illustrated by the best and worst case scenarios both being n x logn).
@championkoppie
11 жыл бұрын
There is also parallel sorting Shuffle the stack at random. Then look if the stack is sorted. If it isn't sorted, you go to a Parallel Universe where it is sorted.
@gulllars
11 жыл бұрын
A bit later on after other videos, a video on the for loop and it's OO sibling foreach, and how it leads to spatial and temporal locality in memory, and how it can be unwound to be executed in parallel depending on branching with speculative execution could be interesting. There's easily 5 minutes there, and if you take your time to cover it in some depth with simple explanation you could get 15 minutes that would be interesting ;)
@SeabasR
11 жыл бұрын
Computerphile, I subscribed before this video finished loading.
@Turcian
11 жыл бұрын
Actually the best running times in "real life" are obtained by algorithms that combine two(or possibly more) sorting algorithms like quick-sort and heap-sort(the combination is called intro-sort), or merge-sort and insertion sort(that's called Tim sort).
@Vulcapyro
11 жыл бұрын
There are many many algorithms that have steps that seem spread like a tree. If an algorithm runs in some sort of logarithmic time, guessing it uses a divide-and-conquer approach somewhere is probably accurate.
@ashwith
11 жыл бұрын
Amazing work with the animations! Makes merge sort so much easier to understand!
@PJSimply
11 жыл бұрын
If you want to try a fast and easy to implement sorting algorithm, take a look at comb sort. It is a bad-known algortihm, basicly BubbleSort but with a decreasing gap beetween numbers, with same complexity as quick sort !
@AbhishekSingh-dt6br
3 жыл бұрын
I appreciate the effort you are putting to explain this.
@AlexanderTrefz
11 жыл бұрын
That you still have to query with incredible speed. even with indices you need multiple systems in place to make that search fast, search is still one of the hardest problems in the industry because it all revolves around cache invalidation, which is super hard.
@helenwhogirl
11 жыл бұрын
We looked at bubble sorting in the decision maths unit in A level Maths. The different sorting methods are quite interesting :-)
@SkyeWintrest
11 жыл бұрын
I call Radix sort above the sorting algorithms brought up in this video. It works for pretty much all numbers that a computer can use, and also would work for characters (since those can be cast as integers). Of course, it won't work when you can only use a method that compares two objects at once since it doesn't work in that way, but still.
@IceMetalPunk
11 жыл бұрын
"n" is the number of items in the list. The overall efficiency is the function of "n" that tells you the total number of steps in the algorithm. For Bubble Sort, worst-case it has to swap every pair of items on every pass. Whenever it does, it needs to do another pass. So that's n passes and n swaps each--n^2. Merge sort splits the list in half each time, so the total number of splits is log-base-2 of n. Then it compares each element together for each pair, so that's n comparisons. So n x log n.
@godwinikape8888
2 жыл бұрын
Thank you so much for this video. It really helped me understand the concepts of these algorithms.
@Rubberbandman1991
11 жыл бұрын
Yes, its easy enough to tell on its own but you can make an algorithm that lets you determine when to use bubble or merge sorting, then place the list in the correct one.
@MorRobots
11 жыл бұрын
You should talk about linked list sorting using bidirectional lists. its a supper supper fast sort for large sets of data. you push your values to the right of left of existing values by using link swapping and you keep track of both ends of the list and the half and quarter way marks depending on how big the lists gets, using those points you can quickly reduce the number of comparisons.
@terrahyde217
9 жыл бұрын
Sorting algorithms are tough to make O(n!), but there are algorithms for other tasks that are worse than O(n!) by a long shot. Things like O(n^n) have come up in my own mathematical research (case generation and resolution for a problem).
@TASDeign
11 жыл бұрын
That's entirely up to the implementation details. If you implement it with a DFS, then you're right. But you could just as easily implement a BFS that would sort in the manner he described.
@DudokX
11 жыл бұрын
Best video on this channel so far! Great job!
@smmoom1212
8 жыл бұрын
:D so so glad you posted the code. this got me back into some programming after a long hiatus for work! i managed to incorporate a simple pre-load system so you don't have to reprogram the app each time you want to change the range of your test XP simple enough but was still super fun :D
@AndreiMuntean0
11 жыл бұрын
This was awesome! Do one on quick sort too! Also do one where you answer the question "How does Google return search results from billions and billions of websites almost instantly?"
@fredrs05
11 жыл бұрын
I haven't been a huge fan of this channel Brady, even though I was really looking forward to it being launched. That being said, I really enjoyed this video! This is excatly the kind of stuff I would like to see! Thumbs up from me!
@ChitrankDixit
10 жыл бұрын
nice video and explanation for those who are new to Algorithm Analysis
@XxJ4R7xX
11 жыл бұрын
I believe he said something along the lines of wanting to convey news without the traditional style seen on every news show worldwide that has been forced on us, when someone said something similar
@BeornBorg
11 жыл бұрын
Programming Pearls has an interesting story about a constrained sorting problem (i.e. telephone numbers) in the first chapter you might like.
@MultiFaqqq
11 жыл бұрын
It's so fast for a smaller set that it doesn't matter what algorithm you use. To check what algorithm you want to use everytime would probably cost more time than you saved over a long period.
@LittlePeng9
11 жыл бұрын
6:20 "As I said earlier" I can't remember him saying that!
@amak1131
11 жыл бұрын
Ohhh a networking video! Now I'm really excited.
@Computerphile
11 жыл бұрын
Thanks! >Sean
@corsairrus
11 жыл бұрын
Actually, there is a slightly better version of bubble sort : you have to stop a loop as soon as you reach a position where you did the last swap from the previous loop. Still, algorithms like heap sort and quicksort are better (both goes in O(n*log(n))); But in the worst case (rare) quicksort is in O(n^2). BTW the last algorithm (with random permutation of objects) is actually called "shotgun sort". Are you also going to talk about insertion sort, enumeration sort and gnome sort?
@MrShysterme
11 жыл бұрын
I think you are underestimating people. I'd think most 10 years old could understand bubble sort in 5 minutes if you showed them how to do it with some playing cards and explain that flipping through the cards is like a loop and what if/then statements are analogous to in the brain.
@PixelOutlaw
9 жыл бұрын
I don't understand why merge sort is always given an initial recursive decomposition step. You can form the initial base lists by simply collecting the elements 2 at a time with the last pair as a single item should the number of elements be odd.
@Patman128
11 жыл бұрын
You should look at Timsort, the best general sorting algorithm and the default one in Python and Java.
@Mike10131994
11 жыл бұрын
But programming is one of the greatest and most significant portion of the study, so it very well should be something about it. Not necessarily tutorials, but maybe how compilers/assemblers work to translate what we say to what the computer understands.
@crazedvidmaker
11 жыл бұрын
I learned what DFS and BFS are today! thx
@gameking008
11 жыл бұрын
can't wait for networking video
@javiiivillalpandoo
11 жыл бұрын
If you check other Brady's channels (Numberphile, Sixty Symbols...) they are not tutorials about math or sciences, but a different approach to different themes, I like Brady's team videos, I wouldn't like them to teach me how to declare variables in C... I would like a different view.. a general idea on algorithms for example, I find this video very instructive and with no line of code...
@ProfJonatan
11 жыл бұрын
No, because if you sum all the cases weighed by their probabilities, you will end up with an expression where the dominant term is N squared. Being O(N^2) doesn't mean that it takes exactly N^2 steps to run, it means that the number of steps for an input with size N grows similarly to N^2. Another way to think about this is that the average between N and N^2 is N^2/2+N/2. Since N^2 dominates the expression, the average case is O(N^2).
@antiHUMANDesigns
11 жыл бұрын
Yes, that's the true, Z-sorting can be important. I tend to stay away from Z-sorting to save power, and do blending for billboards using a different way. Not sure which kind of culling you're refering to. I've done frustum culling and normal back face culling, which is automatic anyways. And as for shadows, I don't see why you'd need to sort anything for that. I've used shadow maps and stencil shadows, and never needed sorting. I'm sure I would know if I'm sorting things.
@XiremaXesirin
11 жыл бұрын
It's not precisely the same thing, but there is an algorithm called Timsort which optimizes the algorithm to search for "runs" of the list that are semi-sorted, and cuts down on the number of steps in performing the sorting. In best case, it runs at O(n) time and in average case, it gets very close to O(n), but is still slightly slower at O(nlogn). It's worth noting that Information Theory has proven that no comparison-based sorting algorithm can run faster than O(nlogn) in average case.
@TaiFerret
11 жыл бұрын
I came up with mergesort independently when I wanted to write a sorting program. I figured it would work best with powers of 2.
@tabaks
11 жыл бұрын
Brady, many viewers watch your videos on iOS devices. It would really be a good idea to include your additional links in description, not just as an overlay on video. That way we'd be happier and you'd have more views on your ideos. Win-win!
@Fluxikator
11 жыл бұрын
I never approached sorting from a Physical point of view. I evend used a bubblesort so sort a hand of (virtual) cards without having ever heard of it. But yes i can understand how other sorts are easier to understand when youre coming from a physical point of view. but from a Progammatically point of view a bubble sort is very easy. Just run through the array and swap until you dont swap anymore.
@JamWard
11 жыл бұрын
I'm loving these videos guys! Keep up the great work :D
@joopie99aa
11 жыл бұрын
Writing an algorithm that scales with N factorial is very easy. For example, implementing a bogo sort is a piece of cake. Moreover, there are many problems for which no algorithm is known which solves the problem in polynomial time, only in exponential or factorial time. In fact, usually the most straight-forward way to try and solve a problem is to simply try all the possible solutions, which scales with n! very often.
@Viniter
11 жыл бұрын
Actually from a complexity standpoint it doesn't really matter whether you write an algorithm in recursive or iterative form. You can have Merge Sort in recursive form and it will still have complexity O(n*log n). Iterative implementation usually performs better, but the difference doesn't scale.
@johnchapman5646
11 жыл бұрын
Can't wait for more sorting!
@awirstam
8 жыл бұрын
How does a computer "know" that 3 is a lower number than 4?
@anavailableusernam3
11 жыл бұрын
We want heap sort! And don't forget the linear time quantum version of bogosort :)
@ianfoote
11 жыл бұрын
That general idea can be a good strategy, though I don't know if that specific combination is used. I know that a combination of mergesort for large n, and insertion sort for small n is used by some programming languages (e.g. python) along with some other optimisations. Look up timsort if you're interested in the details.
@seahood_
11 жыл бұрын
Bubble sort is easy to remember, and a brilliant sort to start people out thinking about algorithms. That might not be too obvious to your clearly massive brain.
Пікірлер: 541