Every Sorting Algorithm Explained in 120 minutes (full series)

Sdílet
Vložit
  • čas přidán 4. 06. 2024
  • This is a compilation video of the 4 existing sorting videos on my channel.
    Visualizations: • Visualizing 70 Sorting...
    • Explaining EVERY Sorti...
    • Every Sorting Algorith...
    • Explaining EVERY Sorti...
    • The Perfect Sorting Al...
    Corrections / clarifications: none so far
    Resources I mentioned in section 4:
    itbe.hanyang.ac.kr/ak/papers/t...
    en.wikipedia.org/wiki/Block_sort
    github.com/BonzaiThePenguin/W...
    github.com/HolyGrailSortProje...
    habr-com.translate.goog/en/ar...
    Chapters:
    0:00 Intro
    1:34 Selection
    2:04 Double Selection
    2:30 Insertion
    3:07 Binary Insertion
    3:56 Bubble
    4:28 Shaker
    4:46 Asymptotic Notation
    7:40 Finding Time Complexity
    9:48 Quick
    11:51 Merge
    13:10 Stability
    14:11 Space Complexity
    15:57 Heap
    18:46 Comb
    20:05 Shell
    21:28 Radix LSD
    25:28 Radix MSD
    26:11 Bucket
    28:58 Counting
    30:26 Spaghetti
    31:03 Gravity
    32:33 Pancake
    33:45 Bogo
    34:53 Section 2 Intro
    35:16 Cycle
    35:55 Patience
    37:04 Exchange
    37:49 Odd-Even
    38:12 Circle
    39:13 Merge-Insertion
    40:13 Tournament
    41:00 Tree
    42:09 Gnome
    42:41 Library
    43:28 Strand
    44:20 Topological Sorting
    45:18 Sorting Networks
    46:57 Bitonic
    48:43 Odd-Even Network
    49:07 Pairwise Network
    49:42 Why Hybrid Algorithms?
    52:34 Quick LL
    52:59 Dual Pivot Quick
    53:53 Proportion Extend
    54:40 Intro
    55:21 Pattern Defeating Quick
    57:06 Tim
    58:54 Iterative Merge
    1:00:20 In Place Merge
    1:01:10 Weave
    1:01:42 Rotate Merge
    1:02:59 Quad
    1:04:37 Block Sort Preview
    1:05:08 Weak Heap
    1:08:19 Smooth
    1:11:23 Poplar
    1:11:52 Ternary Heap
    1:12:26 In Place Radix MSD
    1:13:45 Binary Quick
    1:14:09 In Place Radix LSD
    1:14:53 American Flag
    1:15:57 Burst
    1:16:21 Spread
    1:17:19 Sample
    1:18:05 Proxmap
    1:18:24 Cartesian Tree
    1:18:56 Section 4 Intro
    1:23:05 Outline
    1:25:29 Sqrt
    1:30:05 Block
    1:36:39 Wiki
    1:41:57 Grail
    1:50:07 Stooge
    1:51:06 Slow
    1:52:08 Quantum Bogo
    1:52:33 Stalin
    1:53:36 Sleep
    1:53:56 Miracle
    1:54:20 Bogobogo
    1:55:24 Power
    1:56:09 Outro
    #math #sorting #algorithms #explained #math #computerscience
  • Věda a technologie

Komentáře • 146

  • @Kuvina
    @Kuvina  Před 28 dny +44

    Visualizations: czcams.com/video/Uq6URzo9q6g/video.html
    I hope you enjoyed learning about algorithms! And for returning viewers, I hope you enjoy the trip down memory lane!

    • @Johnny_Franco-12_Scratch
      @Johnny_Franco-12_Scratch Před 21 dnem +1

      こんにちは、クヴィナ・サイダキ!

    • @CaptainDangeax
      @CaptainDangeax Před 19 dny +1

      Great vidéo. I'm gonna play with my C128 ASM just for the fun of it, trying to implement some of them and programming the VDP

  • @Patricia_Taxxon
    @Patricia_Taxxon Před 28 dny +191

    kuvina i am rooting for you

    • @jan_Eten
      @jan_Eten Před 28 dny +14

      mood
      also omg is ðat patricia taxxon ( 'o')
      i loved your love rap explanation in rhythm heaven iceberg megamix ( ^u^)b

    • @MarkusIfquil
      @MarkusIfquil Před 28 dny +6

      patricia ily

    • @RadioactiveBluePlatypus
      @RadioactiveBluePlatypus Před 27 dny +5

      Omg hii you're my favorite autistic furry youtuber yippee! /genuine
      Helped me realize I'm autistic myself

    • @temmie1662
      @temmie1662 Před 27 dny +1

      @@RadioactiveBluePlatypusoh oh hi /gen

    • @paper2222
      @paper2222 Před 26 dny +2

      our favorite enby buddy

  • @Patricia_Taxxon
    @Patricia_Taxxon Před 27 dny +134

    genuinely love the way you've adapted this into a worlthwhile viewing experience rather than just a compilation, the little titles are so cute, and the new bits of voiceover make this feel like it was always supposed to be one huge video.

    • @M113sAldrich
      @M113sAldrich Před 6 dny

      I was going to make that Adam Sandler joke but I understand why you are here

  • @maadneet
    @maadneet Před 28 dny +77

    Have I watched each of the individual videos before? Yes. Will I watch this compilation? Absolutely.

    • @wyattstevens8574
      @wyattstevens8574 Před 27 dny +2

      There's also a visualization-only companion!

    • @maadneet
      @maadneet Před 27 dny +1

      @@wyattstevens8574 Watched that too!

  • @MonitorLizardGaming
    @MonitorLizardGaming Před 28 dny +30

    Two hours of high quality and well-thought-out content? Am I dreaming??

  • @samanther511
    @samanther511 Před 27 dny +21

    The idea of sorting networks is really reminding me of how factorio balancers work

    • @robertmauck4975
      @robertmauck4975 Před 18 dny +1

      That was my first thought too

    • @octopodes_nuts
      @octopodes_nuts Před 3 dny

      I would not be surprised if there's Factorio builds that contain otherwise-unknown algorithms that beat any documented method, whether sorting or some other interesting task

  • @yellowmarkers
    @yellowmarkers Před 28 dny +51

    There goes my plan to make a sorting algorithm explanation. I can just redirect people here now.

    • @EntergeticalakaBot
      @EntergeticalakaBot Před 28 dny +1

      There goes the ideas, being used by others

    • @realmless4193
      @realmless4193 Před 27 dny

      Just checked out your channel because of this comment. Did subscribe.

  • @FinnPlanetballs
    @FinnPlanetballs Před 28 dny +35

    20:38 there is an among us hidden in the purple bar

  • @ultra824
    @ultra824 Před 24 dny +31

    Here's a favorite joke algorithm of mine: Intelligent Design sort.
    It works like this: First, observe that the probability of the array being in the exact order that it's in by chance is 1/(n!), this is so unlikely that we must conclude that the array was put in that order by an intelligent Sorter, who must have sorted the elements by some metric beyond our mortal comprehension. This means that any change we might make to the array would actually make it _less_ sorted, which would be against the Sorter's plan. Therefore, the algorithm is complete. This has O(1) Time Complexity.

  • @mrtopper930
    @mrtopper930 Před 19 dny +4

    I’m learning math and science for college majors at 10:30pm. I fell proud.

  • @mistymysticsailboat
    @mistymysticsailboat Před 23 dny +22

    does anyone else ever get annoyed at Quick Sort being called Quick Sort, like that just feels unfair to the rest of the sorts. why isnt it called like "Partition Sort" or something

    • @mistymysticsailboat
      @mistymysticsailboat Před 23 dny +7

      and like it Clearly has weaknesses. it is horrible on an already sorted list.

    • @Kettwiesel25
      @Kettwiesel25 Před 20 dny +8

      Pivot sort is more descriptive I think

  • @ManicVolcanic
    @ManicVolcanic Před 20 dny +3

    Very nice video. Regarding the bonus section at the end -- you'll no doubt be pleased to hear that the latest SIGBOVIK conference introduced bogoceptionsort! Bogosort may accidentally sort very small lists correctly in only a few iterations. To prevent this, bogoceptionsort first shuffles the *order of the lines of code* that make up the bogosort implementation, then attempts to run it, then checks to see if the list is sorted. This effectively pads the number of elements in the list, making it perform extremely poorly for even lists of size, like, five.

  • @evanzieg
    @evanzieg Před 28 dny +13

    I'm a huge fan of all of the icons! They are all very clean and well designed!
    Great work on all the visuals and research in the series!!

  • @mithrilbookofmystery
    @mithrilbookofmystery Před 17 dny +3

    genuinely I love this so much. I do not know enough math to keep up with your descriptions 100% of the way, but what I can parse is genuinely very interesting. I love sorting algorithms, and I love learning more about how they work, even if I can never fully understand it. Thank you so much for this video! I was enraptured all the way through.

    • @mithrilbookofmystery
      @mithrilbookofmystery Před 17 dny +1

      Ahhh I lied I was actually still watching - near the beginning - when I wrote this but by god I am still enraptured. I'm going to start commenting on the little things I'm enjoying as I go along, because there are many, and I couldn't stop myself at just the one comment. First of all: I love your explanation of the use cases for these algorithms. Or, well, I'm currently just in merge sort, I'm unsure if you keep doing it down the line, but still! it's cool to know the pros and cons of each sort, and why one algorithm would be used over another, as in your city name sorting example.

    • @mithrilbookofmystery
      @mithrilbookofmystery Před 17 dny +1

      20:38 >:0!!!!!

  • @colly6022
    @colly6022 Před 28 dny +13

    bubble sort and shaker sort are definitely the most intuitive for me, as i've unknowingly been doing smth very similar my whole life for real-world situations!

    • @HesterClapp
      @HesterClapp Před 27 dny +1

      I think insertion sort is more intuitive than bubble sort. Bubble is easier to code, but it's harder to convince yourself that it works

    • @not_estains
      @not_estains Před 14 dny +1

      i use radix lsd base 2 sort irl

  • @epikoof
    @epikoof Před 27 dny +5

    gotta admit, 80% of block sort flew over my head after sqrt, but i loved this entire video anyway, thank you so much

  • @lerq0ux
    @lerq0ux Před 24 dny +5

    I came looking for one of those “every __ explained” videos but i got something much better

  • @ishu4227
    @ishu4227 Před 8 dny +2

    49:56 this feels so much like a meme template and i love it

  • @Musicombo
    @Musicombo Před 21 dnem +3

    Hey, just to letcha know: you are more than welcome to join The Studio so you can stay updated on Holy Grailsort's progress (once we come out of hiatus, which is hopefully soon)! ❤❤

  • @krabman6297
    @krabman6297 Před 23 dny +4

    Someone should make a paranoid sort algorithm, like bubble sort, but it swaps items a random amount of times just to make sure it's actually swapped, and should have a save function it spams just in case it crashes. You can also make it randomly mess up or starts over completely, maybe even go through twice and compare the two finished sorts to see if it got the same outcome before determining if it's sorted or not

  • @SysFan808
    @SysFan808 Před 24 dny +2

    sorting algorithm i made (and probably many others too)
    so, i started with bogo, but then tweaked the randomiser function.
    it was originally picking 2 random values and swapping them
    i changed that "swapping" to "comparing" them.
    i don't know what to call it, but it does work quite well as a sorting algorithm.

    • @antoninduda9078
      @antoninduda9078 Před 21 dnem +1

      I think it's called either bubble bogo sort or exchange bogo sort

  • @ceremyjlarkson9475
    @ceremyjlarkson9475 Před 28 dny +9

    20:38
    Quite suspicious indeed

  • @wiktorszymczak4760
    @wiktorszymczak4760 Před 19 dny +3

    Forever proud of actually using bogosort back in uni and getting it accepted

  • @joelicandi2586
    @joelicandi2586 Před 23 dny +4

    Fantastic Work !!
    very impressive

  • @Skyb0rg
    @Skyb0rg Před 27 dny +4

    1:52:30 Quantum bogosort is actually implementable, but would be O(2^n) in all cases, since you need to spend time creating those 2^n “worlds” to destruct.
    There is another interesting sorting algorithm, which is the “differentiable sorting” algorithm. It takes in a list and returns the permutation required to make it sorted, but the entire algorithm can be differentiated (needed in ML and for incremental computation).

  • @migueltorrinhapereira7473

    This series of videos inspired me to create a sorting algorithms visualization that runs on my CASIO graphical calculator, I implemented 16 different algorithms and it was really fun. Thank you.
    Great video, very helpful and interesting.

  • @Musicombo
    @Musicombo Před 27 dny +2

    Once again, your explanation for Grailsort makes me smile ❤

  • @CombineCubing
    @CombineCubing Před 27 dny +5

    How much sorting algorithm do you want?
    Me: *_Yes_*

  • @josephgaming3357
    @josephgaming3357 Před 28 dny +10

    I kinda want to know what all the algorithms would look like if you started with a reverse order list instead of a shuffled list. is there somewhere I can see that?

  • @skittlez0496
    @skittlez0496 Před 18 dny +3

    A variation on quantum bogo sort (without the universe destruction):
    Step 1) go through the entire list to see if it’s sorted, also counting what n is in the process
    Step 2) with n! parallel processors and n! auxiliary arrays, distribute each element evenly into each open spot in each array, which guarantees that each array is distinct*
    Step 3) because each auxiliary array is necessarily distinct, and we have n! number of them, exactly one must be sorted. Simply use all our parallel processors to comb through them simultaneously to find the sorted list.
    Boom, the fasted on average sorting algorithm possible (time complexity of n) The only issue would be the space and processing it requires…

    • @skittlez0496
      @skittlez0496 Před 18 dny +1

      *if the list doesn’t contain strictly distinct values, there will be multiple auxiliary arrays which are sorted, but still only one that is sorted stably
      We can make this algorithm stable by taking the first auxiliary array (which is necessarily just a copy of the original list) and use it as a “stable” memory storage to help find the one true stably sorted list

  • @jursamaj
    @jursamaj Před 27 dny +2

    22:10 I may have mentioned this in the original video, but radix sort *can* be used on strings (as long as characters have a fixed-size representation). It's most efficient with fixed-size strings, but can even be used on variable length strings.

  • @epikoof
    @epikoof Před 27 dny +7

    kuvina, patricia taxxon and jan misali should all collaborate sometime

  • @kaderen8461
    @kaderen8461 Před 22 dny +3

    i will not need this information. but it begs to be watched

  • @fwuz_
    @fwuz_ Před 36 minutami +1

    pairwise bogo sorting network: given a list X of size n, generate a new list P containing all ascending pairs of integers from 0 to n-1. shuffle P and use it to compare every pair of numbers in X, swapping them if necessary. if X isn't sorted throw your computer in the ocean or something idk

  • @augie279
    @augie279 Před 21 dnem +3

    I don’t understand any of how block sort works but I’m glad computers do

  • @RT777
    @RT777 Před 6 dny +2

    Stumbled across this awesome video and liked it 5 minutes in. It’s great, but I would suggest adding a touch more emotion in to it. Great video!

  • @etaosin
    @etaosin Před 6 dny +2

    Great work, congratulation. Certainly watch one time is not enough. But understanding level again increased in my situation.

  • @12times12_
    @12times12_ Před 24 dny +4

    bitonic sort visualizes the swaps that are needed to make a belt balancer in the video game Factorio lol

  • @arcainchaos
    @arcainchaos Před 25 dny +3

    I am less than a minute into the video and I need you to know that I love you

  • @thumbgoblin4716
    @thumbgoblin4716 Před 28 dny +6

    ive already seen all 4 videos, is there anything new in this one?

    • @Kuvina
      @Kuvina  Před 28 dny +6

      not really I just redid some audio and visuals to make it easier to watch, and added segues between the sections

  • @tobyconner5827
    @tobyconner5827 Před 26 dny +2

    you should do a longer video about joke algorithms (especially more obscure ones like hanoi sort), theyre very fun

  • @DavidvanDeijk
    @DavidvanDeijk Před 25 dny +2

    very enjoyable, thank you. shell sort is indeed a favorite.

  • @ryanbartlett672
    @ryanbartlett672 Před 25 dny +3

    Great work. Thanks

  • @ERRORRubiksZeraBrand
    @ERRORRubiksZeraBrand Před 20 dny +2

    i am trying to make a sorting visualizer in python by using your terminal and using pygame for the sounds. i didn't understand many sorting algorithms but this helped me understand some of the algorithms. i also included one of your sorting algorithms (baiai sort) inside. thank you for the explanation and peace.

  • @mommyuki
    @mommyuki Před 28 dny +2

    new Kuvina video! I already love it

  • @TheBalthassar
    @TheBalthassar Před 27 dny +2

    I'm pretty sure I said this on the original video, but when we got to the sorting networks and bitonic, my mind goes to Factorio belt management theory.

  • @fuschia-draws
    @fuschia-draws Před 17 dny +2

    each algorithm has a little icon !? very cute i love it

  • @namethathasntbeentakenyetm3682

    Now I can understand the things

  • @mitchellbailey5522
    @mitchellbailey5522 Před 10 dny +2

    Honestly quite incredible

  • @RT777
    @RT777 Před 6 dny +2

    Minor typo - 1:05:15 says O(nlgon) instead of O(nlogn) in the magenta rectangle

  • @CompilerHack
    @CompilerHack Před 28 dny +3

    you make the best videos!

  • @ShowMe7.
    @ShowMe7. Před 28 dny +10

    yay new kuvina video :3

  • @circuitcraft2399
    @circuitcraft2399 Před 27 dny +1

    1. Quicksort can include smarter pivot-selection techniques to guarantee O(n*log(n)) time in the worst case.
    2. Shellsort can be O(n*log(n)^2) if you choose the sequence of gaps more carefully.
    Additional details in replies.

    • @circuitcraft2399
      @circuitcraft2399 Před 26 dny

      Explanation for 1: there is an algorithm called "median of medians." It is an O(n) algorithm that finds some value in the list that is greater than (or equal to) at least 30% of the others in the list, and also less than (or equal to) another 30% of them. By using it to choose pivots, we will always shrink the list by a constant factor on each step, guaranteeing logarithmically-many recursive steps.

    • @circuitcraft2399
      @circuitcraft2399 Před 26 dny +1

      Explanation for 2: if we choose the sequence of 3-smooth numbers, we never swap an element more than once on a given iteration. Since there are O(log(n)^2) 3-smooth numbers less than n, we perform that many linear-time iterations.

  • @HesterClapp
    @HesterClapp Před 27 dny +1

    I think I saw somewhere that the time complexity of Shell sort is O(n (log n)^2), which is roughly n^1.2, but I couldn't tell you why that's the time complexity

    • @Kettwiesel25
      @Kettwiesel25 Před 20 dny

      O(n log^2 n) is a smaller time complexity than n^1.2 or even n^1.00001

  • @LeoStaley
    @LeoStaley Před 28 dny +3

    Are there different considerations based on properties of the data, like numerous peices of data with the same values? In such a data set is there anything of note happening when a secondary sort method is used? (Like sorting files by album title, and secondarily by name, or track number?
    What about if the data is already partly sorted instead of random?

    • @Kuvina
      @Kuvina  Před 28 dny +2

      That's where adaptive algorithms come in, which are covered in part 3 !

    • @NXTangl
      @NXTangl Před 28 dny +3

      For "A-then-B" you can just sort by A but break ties by B, or you can sort by B, then stable sort by A, or you can use a recursive procedure more like MSD radix sort.

    • @LeoStaley
      @LeoStaley Před 28 dny

      @@NXTangl does anybody know how windows explorer does it?

    • @NXTangl
      @NXTangl Před 26 dny

      @@LeoStaley Probably stable sort.

  • @ashes6816
    @ashes6816 Před 28 dny +2

    this is so good

  • @rhnirsilva652
    @rhnirsilva652 Před 15 hodinami +1

    this is fucking cinema

  • @stefanbergung5514
    @stefanbergung5514 Před 23 dny +1

    Wasn't there an algorithm that can solve any NP-problem in its minimal time complexity by random generating algorithms and checking if there answer is correct?
    It's just generliced bogo-sort, but would have been worth a mention.

  • @Vaaaaadim
    @Vaaaaadim Před 27 dny +1

    I'm only at the start of the video right now, but I just want to note that ska sort doesn't seem to be included.

  • @AshLikes2analyse
    @AshLikes2analyse Před 27 dny +2

    You're the best

  • @mathguy37
    @mathguy37 Před 25 dny +2

    cool now i can watch this when binging it the 581st time

  • @vincehomoki1612
    @vincehomoki1612 Před 24 dny +1

    1:05:13 Typo! "and building it is O(nlgon)"

    • @Kuvina
      @Kuvina  Před 24 dny

      I'm impressed by how many people have noticed that. But I guess it shows people are really paying attention to the video!

  • @not_estains
    @not_estains Před 24 dny +1

    radix sort is so cool

  • @andriypredmyrskyy7791
    @andriypredmyrskyy7791 Před 27 dny +2

    Fun fact, Bill Gates published a really neat paper on pancake sort! I wish I was smart enough to understand it. I'd watch a video of someone explaining that paper online.

  • @taureon_
    @taureon_ Před 26 dny +1

    identity crisis sort should randomly start off with quick or merge

  • @MessyMasyn
    @MessyMasyn Před 24 dny +1

    Can't wait to get hired at Google/Facebook/Papa Johns

  • @BoBoN4Uto
    @BoBoN4Uto Před 24 dny

    marvel moieverse been real quiet since this dropped

  • @not_estains
    @not_estains Před 14 dny +1

    now explain every shuffling algorithm

  • @eskaigarcia
    @eskaigarcia Před 3 dny +1

    Wow, just wow

  • @meem2Greene-ju3cs
    @meem2Greene-ju3cs Před 26 dny

    Fireship ahh video lawful evil ending

  • @surters
    @surters Před 24 dny +1

    OMGZ block sort!!!

  • @WendidIask
    @WendidIask Před 24 dny +1

    Top sort is not obscure :(. It is used in every DAG problem basically.

  • @BFUS_official
    @BFUS_official Před 26 dny +1

    I keep hearing login

  • @kvanctok9234
    @kvanctok9234 Před 26 dny +1

    1:05:14 O(nlgon)

  • @SysFan808
    @SysFan808 Před 24 dny +1

    1:05:16 nlgon

  • @hamzamotara4304
    @hamzamotara4304 Před 19 dny

    Grade 12 math was not enough for this video XD

  • @GermanZindro
    @GermanZindro Před 5 dny +1

    Already a major mistake at only two and a half minutes.
    And the runtime complexity of selection sort isn’t even difficult to calculate.

  • @RileyMyers-zz3je
    @RileyMyers-zz3je Před 27 dny +1

    woohoo!

  • @lilyyy411
    @lilyyy411 Před 27 dny +1

    among

  • @VladVideos0
    @VladVideos0 Před 22 dny +1

    Its 117.55 minutes long

  • @thermitty_qxr5276
    @thermitty_qxr5276 Před 15 dny +1

    Hey great video you put effort into, but I got some small problems about your intro jingle
    It doesn't sound pleasant since there is too much tension which isn't resolved nicely meaning it sounds like it's not done and unsatisfaction.
    (I assume the first note is the home note or the note that sounds at rest).
    I may be wrong, and that is supposed to be like that because of the message you're supposed to show.
    But if not, I can help make a better one because I understand some music theory and I'm a newbie. Thanks for reading

  • @rodrigoqteixeira
    @rodrigoqteixeira Před 28 dny +1

    Yooooooooo.

  • @zoeymccann124
    @zoeymccann124 Před 24 dny +1

    Didn't even mention worstsort 0/10

  • @YEWCHENGYINMoe
    @YEWCHENGYINMoe Před 28 dny +2

    11h ago

  • @jan_Eten
    @jan_Eten Před 28 dny +2

    1:05:14 nlgon xD
    mi jan lukin nanpa san ale san mute san

  • @gamergoogol2048
    @gamergoogol2048 Před 28 dny +2

    45th view

  • @temmie1662
    @temmie1662 Před 28 dny +3

    Helloooo :3

  • @Spherius
    @Spherius Před 21 dnem +1

    Sigma algorithm:
    It will say erm what the sigma and then and checks if the array is sorted, if not, it repeats

  • @vladmarianciuc7574
    @vladmarianciuc7574 Před 28 dny +3

    first :D

    • @Lev3759Mc
      @Lev3759Mc Před 22 dny

      Confirmed with newest first comments

  • @qu765
    @qu765 Před 28 dny +1

    gnome sort is my favorite