Sorting Secret - Computerphile

231,047
0
Published 2016-11-18
Two different sorting algorithms are actually the same. Professor Graham Hutton explains.

Note from Professor Hutton: It's great to see all the discussions here! To clarify a point raised in some of the comments, the video shows that if you consider the essential underlying idea of selection sort and insertion sort, in terms of how they decompose the problem of sorting, then they perform the same operations but in different orders. Using the picture in the video, selection sort proceeds column at a time and insertion sort proceeds row at a time, but they both perform the same 'triangle' of operations in the end. A particular implementation of these sorting methods may optimise the process in some way, e.g. in a sequential implementation each row can stop comparing numbers once the point of insertion is found. But this is an implementation detail that is dependent on the computational model used, such as sequential versus parallel, or imperative versus functional, rather than part of the essential means by which the sorting methods work.

Slow Loris Attack:    • Slow Loris Attack - Computerphile  
Cracking Windows by Atom Bombing:    • Cracking Windows by Atom Bombing - Co...  
Quantum Computing:    • Quantum Computing 'Magic' - Computerp...  
Babbage's Analytical Engine:    • Babbage's Analytical Engine - Compute...  
Quicksort:    • Quick Sort - Computerphile  
Getting Sorted:    • Getting Sorted & Big O Notation - Com...  

www.facebook.com/computerphile
twitter.com/computer_phile

This video was filmed and edited by Sean Riley.

Computer Science at the University of Nottingham: bit.ly/nottscomputer

Computerphile is a sister project to Brady Haran's Numberphile. More at www.bradyharan.com/

All Comments (21)
  • @arirahikkala
    The missing technical term: This construction is a sorting network, just drawn in an unusual way. The basic point of the video is that sorting networks can't express the difference between insertion sort and selection sort.
  • @deepjoshi356
    I know some basic definition about all 4 algorithm named insertion sort: find correct place for the element selection sort : find correct element for the place & merge and quick sort uses divide and conquer merge sort doesn't divide it merges properly and quick sort doesn't need to merge it divide properly
  • @playingwithdata
    It's an interesting exercise that I'm sure will help people visualise these sorting algorithms and understand how they are similar. However to say they are "the same" is pushing it when you're expressly showing that one is operating 'column-wise' and one 'row-wise' in your diagram. The next step here would surely be to get students to dig into this difference and analyse the data structures and operations involved in each approach and the complexity and practical performance implications.
  • @al-du6lb
    This is a great illustration. I've always thought about how programming is almost like a stream of liquid flowing, and in this you can really visualize that concept.
  • @sabriath
    This is correct on half of a fundamental position....but not on the programming position. Selection sort specifically finds the lowest in the muck, removes it and tags it onto a list; while insertion sort picks a number from the muck and finds the place it needs to be put in the list. This means that selection sort works with any list type, while insertion sort can only effectively work on double-linked lists (otherwise you are constantly moving blocks of memory as the list expands). The other half of the fundamental position that proves that it is NOT the same is simple.....what if halfway through the sort, the program stops? Selection sort would leave some of the data sorted and a leftover muck to deal with, while insertion sort might as well look like 2 mucks. This becomes somewhat important in file systems and indexing....if the power goes out during a sort, Selection is better than Insertion for recovery of "where you left off." It's also important to note that Selection sort gets faster as the muck reduces over time....while Insertion is fastest at the beginning and gets slower over time. Absolutely none of this was mentioned in the video, nor did it seem like Hutton was even going to hint toward it (he stated he was going to write a paper on it being the same, when it obviously isn't when taking as a full context). Sidenote: Any relation to Tim J. Hutton?
  • This guy is an amazing teacher. I wish I could find his lectures online. We don't have much of that in Brazil.
  • @user-mn3iq2cs9n
    This video made my day. I was totally burnt, and now I'm in the mood to study on my whiteboard again. Thanks Professor.
  • @watchphysics
    One of the best thing I have watched after a long time related to Computer Science. Nice Perspective.
  • @byteeater7662
    The first one is really bubblesort (the simplest, unoptimized variant). See how beside picking 1 in the first column it also swaps 2 with 3. Selection sort, unlike this bubblesort and insertion sort (also unoptimized because it keeps comparing in the tail after having found the right place for an element), isn't oblivious (which means performing a sequence of comparisons at some pairs of positions depending only on the length of the input, not the results of previous comparisons) and thus cannot be expressed with a sorting network.
  • @schulmastery
    The strongest selling point of insertion sort is that it is adaptive. Once the insertion point is determined, the pass can be aborted, while selection sort must look for a min/max across the entire unsorted region. In the vid, he implements an insertion sort that is gimped in its adaptability, and then says its the same as an algorithm that is notoriously not adaptive. Really hammering this point, his machine would take n^2 time to sort a sorted list, just as selection sort would; but insertion sort implemented properly only takes n time. I cant take the engine out of a car, and then comment on how similar it is to a bicycle.
  • Your videos are excellent. You explain computer science concepts so well. Great job!
  • @iiN1GH7M4R3ii
    How did this not make the trending list??? Thank you so much this is what I needed!!!!!
  • @Waifod
    Wait, is he the one who wrote "Programming in Haskell"? Edit: I checked and he is, indeed! Great job, awesome language!
  • @KubrickFR
    I didn't care for the point he makes but I really like the "boxes in a triangle" explanation
  • @foolo1
    This video disregards the implementation. Bu the implementation is important. For example, the algorithms have different best case complexity.
  • @praf2
    i love this channel! i feel lucky i found it xD a lot of interesting stuff put in simple words and explanations.