Quick sort in 4 minutes

Поділитися
Вставка
  • Опубліковано 30 вер 2024

КОМЕНТАРІ • 543

  • @WhisperingWalnuts
    @WhisperingWalnuts 2 роки тому +283

    This is great video! but, I feel the algo provided in the end is not the same as the way he was explaining.. I went ahead and wrote my code for it same way he explained:
    ```
    class Solution:
    def sortArray(self, nums: List[int]) -> List[int]:
    def quicksort(nums, lo, hi):
    if lo < hi:
    partition_resting_point = partition(nums, lo, hi)
    quicksort(nums, lo, partition_resting_point - 1)
    quicksort(nums, partition_resting_point + 1, hi)
    def partition(nums, lo, hi):
    pivotIdx = random.randint(lo, hi)
    nums[pivotIdx], nums[hi] = nums[hi], nums[pivotIdx]
    pivot = nums[hi]
    l_idx = lo
    r_idx = hi-1
    while l_idx

    • @MichaelSambol
      @MichaelSambol  2 роки тому +55

      Yeah, in the early days I didn't spend enough time on pseudocode. Trying to fix that now by building out this repo: github.com/msambol/youtube/blob/master/sort/quick_sort.py. Thanks for the feedback!

    • @westsideslasha
      @westsideslasha 2 роки тому +23

      ​@@MichaelSambol I got really confused when the pseudocode didn't match the explanation. You should correct that (in the video) ASAP.

    • @MichaelSambol
      @MichaelSambol  2 роки тому +58

      @@westsideslasha I'm sorry about that! UA-cam won't let me change the video now unfortunately, but I pinned this comment.

    • @manavshah448
      @manavshah448 2 роки тому

      I am encountering an infinite loop if I change the while condition to be i < j instead of

    • @amono770
      @amono770 Рік тому +4

      i am glad that i looked at the comment section after having a hard time connecting the pesudo code to the video content.

  • @EchoVids2u
    @EchoVids2u 4 роки тому +4649

    With every new quick sort video, I watch, I get more recursively confused.

  • @jonahrivera7
    @jonahrivera7 4 роки тому +779

    Guy: "I think you understand the concept"
    Me: No I don't

    • @Evokans
      @Evokans 3 роки тому +3

      it gets halved and is recursively applied to both halves in each step

    • @sleevman
      @sleevman 3 роки тому +1

      @@Evokans um what?

    • @faith2756
      @faith2756 3 роки тому

      @@sleevman It gets repeatedly done on each new half, as after each half the pivot is in the right place, so a new pivot is used.

    • @sleevman
      @sleevman 3 роки тому

      @@faith2756 sorry wat?

    • @faith2756
      @faith2756 3 роки тому

      @@sleevman Which part exactly do you not understand?

  • @alanfender123
    @alanfender123 5 років тому +1966

    i should be working at mcdonalds

  • @SAMURAIch
    @SAMURAIch 4 роки тому +524

    I feel so dumb when i don't understand this, but then i just scroll the comment section and realise that im not alone lol

    • @liuqing1995
      @liuqing1995 3 роки тому +3

      understanding the meaning of pivot is the KEY.

    • @reguret2976
      @reguret2976 Рік тому +12

      yeah, theitemfromleft, or right wasn't even properly discussed, left of what or right of what exactly?

    • @skyness9
      @skyness9 5 місяців тому

      lol

    • @anshulsharma9424
      @anshulsharma9424 Місяць тому

      he is missing lot of steps , this video is a crime

  • @banderson924
    @banderson924 5 років тому +1277

    So we let magic handle the rest.

    • @Bridgelessalex
      @Bridgelessalex 5 років тому +43

      HAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA

    • @airex12
      @airex12 5 років тому +13

      After you swap itemFromLeft and the pivot at the end, itemFromLeft is now at the end of the array. So, use that as the *new* pivot.
      Repeat that until its sorted.

    • @kennethquilantang8080
      @kennethquilantang8080 5 років тому +1

      @@airex12 so 8 is the new pivot? How can I go through if there is no number in the array greater than 8?

    • @airex12
      @airex12 5 років тому +12

      @@kennethquilantang8080 after 7 is put in its correct position, remember that all numbers to the right of 7 are greater than 7. In this case, there is only one number - 8. A partition with just one number is already sorted, so you can ignore it and move on to sort [6,5] to the left of 7.
      For sorting [6,5] choose 5 as the pivot. itemFromLeft is therefore 6, and itemFromRight has no value because no number in the array smaller than 5. Therefore, we can stop and swap itemFromLeft and the pivot to leave [5,6].
      Yes, the video is unclear because it does not explain these cases. The point is that each time you put the pivot into it's correct position, you have "split" the array into two parts - one part has all numbers bigger than the pivot and the other part has all numbers smaller than the pivot. Parts with *just one* element are already sorted. If a part is already sorted, no itemFromLeft can be found. If a part is unsorted, you are guaranteed to find an itemFromLeft, and if the index of itemFromRight < the index of itemFromLeft *OR* itemFromRight does not exist then you can swap itemFromLeft and the pivot to put the pivot into its correct position in the whole array.

    • @kennethquilantang8080
      @kennethquilantang8080 5 років тому

      @@airex12 I get your point bro thanks but what would be the next step. Will I need to pick another pivot? How can I sort the rest?

  • @Charoula1608
    @Charoula1608 6 років тому +608

    *screams in Ross voice* PIVOT! PIVOT! PIVOT!

    • @peizhiyan2916
      @peizhiyan2916 5 років тому +4

      haha, I can't help imaging Ross's face, hahaha

    • @Daver2212
      @Daver2212 5 років тому +1

      Me in future, oh Ross's couch sort?

    • @Jiwoo15
      @Jiwoo15 5 років тому +11

      screams in Chandler voice SHUT UP! SHUT UP! SHUT UP!

    • @mahnazha
      @mahnazha 5 років тому

      Oh my GOOOOD :-))))))))))))) So truuuuueeeeeee

    • @AbdelhameedG
      @AbdelhameedG 4 роки тому +1

      This is exactly what came into my mind learning about this :))

  • @LL-rn8rn
    @LL-rn8rn 6 років тому +296

    The psudocode is not intuitively reflecting the walkthrough

    • @diabl2master
      @diabl2master 4 роки тому +3

      I've been looking at it for a few minutes now, and I can believe that this pseudocode is accurate, but I'd have to check the details of what the partition function is doing to be sure, but it seems legit. Assuming your language of choice will permit a self-referential function like that.

    • @jscholex
      @jscholex 4 роки тому +13

      @@diabl2master The recursion is fine... he's talking about how `partition` is putting the pivot on the left wall instead of the right. In the video the pivot is on the right side.

    • @diabl2master
      @diabl2master 4 роки тому

      @@jscholex That would be a failure of technically reflecting, not intuitively reflecting, the walkthrough. I'm not sure OP was referring to that, but who knows.

    • @jscholex
      @jscholex 4 роки тому

      @@diabl2master Yeah who knows... but I think we can all agree the pseudocode isn't great hah

    • @skarfie123
      @skarfie123 3 роки тому +8

      the pseudocode shows the Lomuto version but the visualisation is for the Hoare version, which is better. See Wikipedia for both.

  • @nemesis9410
    @nemesis9410 5 років тому +263

    This is the most confusing and incoherent visualization of quicksort I've ever seen

    • @thewiseowl8804
      @thewiseowl8804 5 років тому +3

      Well said 👍

    • @ChristianMay21
      @ChristianMay21 5 років тому +6

      Makes perfect sense to me

    • @thewiseowl8804
      @thewiseowl8804 4 роки тому +2

      Christian May That’s so great! 🙌👏

    • @diabl2master
      @diabl2master 4 роки тому +13

      I thought the visualisation was fine. I feel that I understand it now.

    • @cristian-bull
      @cristian-bull 4 роки тому

      This is the fist visualisation of quick-sort I've ever seen, so I know it doesn't mean much, but I agree.

  • @nabe4320
    @nabe4320 7 років тому +616

    am still confused

    • @ibu433
      @ibu433 5 років тому +31

      N Betancourt cuz the way he explains it IS confusing
      I’ve watched this a couple of times, thought I understood went to the exam and screwed up
      Now that I’ve watched other videos I understand that the way he explains it is confusing

    • @thewiseowl8804
      @thewiseowl8804 5 років тому +5

      N Betancourt He made it more confusing, for sure.

    • @diabl2master
      @diabl2master 4 роки тому +3

      He didn't explain what quick sort does in general, what it can be applied to, and left some holes in the explanation that someone with no experience would struggle to grasp. Which is a shame.

    • @omegagmysta2092
      @omegagmysta2092 4 роки тому

      Hope this helps :ua-cam.com/video/Zh37XyQLHkw/v-deo.html

    • @alvin_row
      @alvin_row 3 роки тому +1

      i hope you got it cute bird from nichijou

  • @theducksneezes4987
    @theducksneezes4987 4 роки тому +149

    How to get Confused in 4 minutes
    then again, this was the best video about it so far

    • @4TH4RV
      @4TH4RV 4 роки тому +1

      I want more videos like this where they explain stuff in less than 10 minutes

    • @omegagmysta2092
      @omegagmysta2092 4 роки тому +1

      Bet ? ua-cam.com/video/Zh37XyQLHkw/v-deo.html

    • @JoelThomas-sr6ti
      @JoelThomas-sr6ti 5 місяців тому +1

      there's a video by abdul. i think it is best

  • @yufangjuan4994
    @yufangjuan4994 3 роки тому +164

    To ones without enough background knowledge, this video omits details of execution of each step. But to ones with, this is concise and covers sufficient key points of quick sort. Thanks a lot for your video sharing.

    • @noahdirksen3623
      @noahdirksen3623 3 роки тому +45

      Thats the fanciest wording I've heard, i would use: "You get it or you dont"

    • @Seanz2088
      @Seanz2088 Рік тому +1

      Try to sort a few short sequences yourself according to the steps in the video. You may get the "background knowledge".

  • @Kleyguy7
    @Kleyguy7 3 роки тому +13

    I think I'm here for the fourth time now.

  • @sachinpathy6940
    @sachinpathy6940 3 роки тому +8

    i put this at 1.5x and now i learnt quick sort 2.6667 minutes

  • @LGNNorotic
    @LGNNorotic 4 роки тому +96

    you should put the code next to all of the visual aids and highlight each line as its being done in the visual. thanks for the help with sorting!

  • @chinmayhattewar4456
    @chinmayhattewar4456 3 роки тому +36

    Imagine newcomers watching this explanation for the first time.

    • @BethanyLowe8773
      @BethanyLowe8773 3 роки тому +1

      Thank you. I feel the same about my actual online course I'm studying. And I'm a newcomer. I feel better.

    • @krishnarajj9358
      @krishnarajj9358 3 роки тому +1

      horrible

  • @sivapradeep977
    @sivapradeep977 3 роки тому +2

    Hahahaha I still didn't get this.....😎😎

  • @catboy9377
    @catboy9377 2 роки тому +4

    The pseudocode is wrong. Not only does it not match your explanation at all, it doesn't even work when implemented.
    Please cut that part of the video out or put an end card there stating that it's wrong, it's misleading and a waste of time.

    • @MichaelSambol
      @MichaelSambol  2 роки тому +1

      Sorry about that. I didn't focus enough on pseudocode in the early days. Please look here for better code: github.com/msambol/youtube/blob/master/sort/quick_sort.py.

    • @westsideslasha
      @westsideslasha 2 роки тому

      thank you for pointing this out

  • @Crzynoob
    @Crzynoob 5 років тому +23

    Psuedo code does not match demonstrated algorithm.

  • @walteramenya5759
    @walteramenya5759 6 років тому +35

    here for the comments

  • @pebble2258
    @pebble2258 3 роки тому +3

    The comments on this video do not reflect the like/dislike ratio.

  • @arshadsameemdeen391
    @arshadsameemdeen391 5 років тому +45

    Doesn't this guy know Left and Right or what

  • @glenn8781
    @glenn8781 2 роки тому +2

    you lost me at, "we'll let recursion handle the rest".. should have shown animation of how each element moves while being sorted instead of showing the final sorted array :/

  • @DeusNudus
    @DeusNudus 4 роки тому +11

    Code is not right.
    "leftwall = leftwall + 1;" needs to happen right before "swap(array[i], array[leftwall]);" not after it.

  • @jola_mir8327
    @jola_mir8327 3 роки тому +1

    Grate video! Just one thing. @ 1:53 itemFromLeft is 0 and itemFromRight is 5. This part confused me.

  • @agata0214
    @agata0214 3 роки тому +2

    you lost me at 2:54 :(((

  • @M15onehundred
    @M15onehundred 5 років тому +8

    Nice! Glad to see magic still exists!

  • @mekabare
    @mekabare 7 місяців тому +1

    I'm seeing myself working customer service for the rest of my life

  • @SarveRadhaNaam
    @SarveRadhaNaam Рік тому +1

    don't you think at 4:04 , in Partition code. leftwall++ should be before swap(A[i], A[leftwall])

  • @atmajoburman7335
    @atmajoburman7335 Місяць тому +1

    better and much easier algo than any standard quicksort algo available in the books

  • @dannylones2159
    @dannylones2159 3 роки тому +1

    saying "move pivot" but instead swapping it with last number 🗿👍🏻

  • @thomasoehrling
    @thomasoehrling 6 років тому +53

    Needs a bit more of an indepth explaination :/

    • @thehammurabichode7994
      @thehammurabichode7994 4 роки тому +1

      Honestly the phrasing is confusing. This easier if you ignore half of it and just watch the numbers.
      Edit: ok, maybe bad advice..

    • @4TH4RV
      @4TH4RV 4 роки тому +1

      @@thehammurabichode7994 indeed bad advice

  • @CompilerStuck
    @CompilerStuck 2 роки тому +1

    I can now finally sort my life out

  • @dejanualex
    @dejanualex 2 роки тому +2

    why u didn't pick the last element as pivot ? Instead of picking the middle one and then swaping with the last one ...

  • @wendyd.1918
    @wendyd.1918 3 роки тому +46

    I study computer science, and once, I had an exam with a few sort algorithms in it. I didn't really study but about twenty minutes before the exam I watched your 2-4 minute videos on these sort algorithms and I passed the exam. Thank you for helping me.

    • @fireboywatergirl1625
      @fireboywatergirl1625 9 місяців тому +2

      thats gonna b me td lmao

    • @wendyd.1918
      @wendyd.1918 9 місяців тому

      @@fireboywatergirl1625 i am sure you are at the right place.

  • @godaimer999
    @godaimer999 2 роки тому +1

    explained it much fckin better in 4 minutes with 1.5x watchspeed than my teacher in a 90 minutes class, thank you sm

  • @J4T375
    @J4T375 3 роки тому +3

    all your videos are short and very useful.

  • @garypike
    @garypike 2 роки тому +1

    What did you teach? NOTHING!!! You assumed too much and did not make any base reference in order to ground the subject matter and build from it.

  • @Autom_te
    @Autom_te 5 років тому +17

    I can implement quicksort and this still confused me.

    • @nemesis9410
      @nemesis9410 5 років тому +6

      Right? This is the shittiest explanation I've seen

    • @chetanphoenix
      @chetanphoenix 3 роки тому +3

      What's so confusing? the pivot gets out of the way, the two halves get on two sides and pivot is swapped back. So you have two halves as you desire. The only thing missing was when there are only two items, you just set them in order without partitioning. Other than that, it's pretty easy to follow.

  • @IOSALive
    @IOSALive 5 місяців тому +1

    Michael Sambol, You're amazing! Let's be friends and have fun together!

  • @atnguyen5240
    @atnguyen5240 3 роки тому +1

    fuk i cannot understand what the video talk about

  • @yazoo0oody9
    @yazoo0oody9 2 роки тому +1

    what if i encountered an element equal to the pivot

  • @YaoWenMei
    @YaoWenMei 4 роки тому +1

    Can anybody explain the relationship between the example and the presucode?

    • @YaoWenMei
      @YaoWenMei 4 роки тому +1

      The presucode does not work for [3 5 5 0 3]

  • @milenkopizdic9217
    @milenkopizdic9217 4 роки тому +3

    The thing is, at the beginning he says you swap item from left with item to right which obviously makes item from left higher index than item from right, but he does it again and only then he swaps with pivot?! It's impossible to see a pattern when there's no pattern in this explanation.
    EDIT: "StOp wHeN InDeX oF itemFromLeft > index of itemFromRight" but the first time he swapped it was higher index too so that's what I meant

    • @chetanphoenix
      @chetanphoenix 3 роки тому

      You don't swap the indices. You just change the numbers in the indices

  • @charisenriquez9952
    @charisenriquez9952 3 роки тому +1

    What if there is no smaller number than tha pivot?

  • @Garfield_Minecraft
    @Garfield_Minecraft 11 днів тому +1

    Now this one better!

  • @salmonsmoothie
    @salmonsmoothie 3 роки тому +1

    The pseudocode is not accurate. If the parameter `high` from Quicksort(A, low, high) is inclusive, then line 4 should be Quicksort(A, low, pivot_location - 1). Running this program as it is will cause an endless recursion where `low = 0` and `high = 1`, thus never reaching the base case (low < high).

  • @nurdauletsharmetov6338
    @nurdauletsharmetov6338 Рік тому +1

    Oh, great, I didn't understand a shit

  • @АндрейАвакян-ю2о
    @АндрейАвакян-ю2о 2 роки тому +2

    There is an error in the pseudo code in the end: leftwall should be incremented before swaping

  • @rubiproto4322
    @rubiproto4322 3 роки тому +1

    um didnt understand a single thing

  • @tsheleletuka596
    @tsheleletuka596 3 роки тому +1

    what if the pivot chosen is the largest number in the array? in this case, 8

    • @winterfoxx6363
      @winterfoxx6363 2 роки тому

      I read up on this and it’s a pivot is the the max then you are going to get to the end of the array without finding a value to assign for item larger, and that means you have to choose a new pivot. I think an implementation that avoids this error will have to have multiple ways of choosing pivot including choosing first item or choosing last item or choosing a random or just iterating through the list until you find a pivot that works. Whether you have multiple options of choosing the pivot depends on whether duplicate numbers are allowed. If duplicates are not allowed then it is easier. I think random number generation is the most and efficient way of choosing a pivot so I would not include that in my implementation

  • @MewPurPur
    @MewPurPur 3 роки тому +3

    Yess I finally understood it, having a clear mind the morning before the exam helped

  • @liiliilliliilililiiilllil4978
    @liiliilliliilililiiilllil4978 4 роки тому +1

    Why the fuck did I choose CS

  • @fr5229
    @fr5229 7 років тому +71

    This is great. The simple explanation and the especially simple pseudocode towards the end makes it easy to understand the core concept of the algorithm.

  • @Christian-mn8dh
    @Christian-mn8dh 2 роки тому +1

    seems like it takes forever!

  • @snake3276120
    @snake3276120 3 роки тому +1

    LOL this is one of the best and easiest video out there on quick sort. All of you disliking it shouldn't do programming.

  • @laipham8883
    @laipham8883 3 роки тому +3

    I have to admit that the visualisation is great. It helps me understand and implement quicksort by myself clearly, but the pseudo-code is not relative to the walkthrough. Anyway, still a great video.

  • @doc_1116
    @doc_1116 3 роки тому +1

    Writting my A-Levels in computer science was probably the worst decision of my life....

  • @chaseparks1384
    @chaseparks1384 3 роки тому +1

    If you don't understand quicksort in 4 min that doesn't make you dumb or the explanation bad. Watch it again and maybe again, work it out in your head, grab a white board. These things don't come easy for everyone. If you're just starting CS get used to it and keep at it!

  • @JeffSans
    @JeffSans 5 років тому +2

    why would someone use this haha so confusing

    • @itsr4yd946
      @itsr4yd946 5 років тому

      Because it is currently the fastest sorting algorithm out there

  • @Jack-dx7qb
    @Jack-dx7qb 4 роки тому +2

    Why the pseudocode doesn't intuitively reflect the walk through?
    (Quote from Wikipedia) "The pivot selection and partitioning steps can be done in several different ways; the choice of specific implementation schemes greatly affects the algorithm's performance."
    There are two partition schemes:
    1. Lomuto partition scheme, which is the pseudocode provided in the video.
    2. Hoare partition scheme, which is the walkthrough in the video.
    Comparison (Quote from Wikipedia)
    1. "As the Lomuto partition scheme is more compact and easy to understand, it is frequently used in introductory material, although it is less efficient than Hoare's original scheme."
    2. "Hoare's scheme is more efficient than Lomuto's partition scheme because it does three times fewer swaps on average, and it creates efficient partitions even when all values are equal."
    To understand the Lomuto partition scheme more, I recommend a UA-cam video called "Quicksort: Partitioning an array" by KC Ang.

    • @ggg-tq9be
      @ggg-tq9be 3 роки тому +1

      thank you a lot!

  • @arnodunstatter
    @arnodunstatter 3 роки тому +1

    Your pseudo code does not represent the algorithm you explained in the video. Your psuedocode uses only 1 index to check the pivot against, as opposed to the 2 index method you described.

  • @dh7222
    @dh7222 8 років тому +85

    These are some clean tutorials. Thank you for making this!

  • @Woopinah
    @Woopinah 5 днів тому

    Very very good video, thank you! I really love how you never stutter over your words, and never say uhm or uhhhh. That makes this very easy to watch.

  • @barannasiri6799
    @barannasiri6799 Рік тому +1

    What

  • @prohakerofficial
    @prohakerofficial 2 місяці тому

    Very good video, I learned quick sort easily thanks to this. Although, I did have to rewatch the "median-of-three" explanation.

  • @emilgebl8644
    @emilgebl8644 4 роки тому +67

    If anyone is confused at the 1:10, basically he doesn't go through the loop.
    Instead he jumps to when item from left is higher or item from right is smaller etc. There is a left and right pointer that checks for the condition and then left++ or right-- if its not correct.
    itemsfromRight goes from 1 cuz its smaller, and then the right-- checks 7, not smaller, right--, checks 8 not smaller, right-- and then it checks the 0 and see that its smaller.

    • @christianeichmueller8637
      @christianeichmueller8637 2 роки тому

      Thanks for the explanation!

    • @jamboy1843
      @jamboy1843 2 роки тому

      what the hell are you talking about this is a church sir

    • @emilgebl8644
      @emilgebl8644 2 роки тому +3

      @@jamboy1843 I don't even remember making this comment.

  • @1996Pinocchio
    @1996Pinocchio 5 років тому +2

    Not recommended

  • @Versole
    @Versole 2 роки тому

    Out of all the sorting algrotiems this one the hard to understand but you understand it you'll understand it.

  • @MuggL
    @MuggL 4 місяці тому

    Your videos are busteling always, keep cooking!

  • @yessirski7868
    @yessirski7868 6 місяців тому +1

    people are complaining but this is gonna come in clutch for my wirtten exam tmr.

  • @hiteshsahu_
    @hiteshsahu_ 2 роки тому

    Your pseudo code at 04:05 is wrong for both functions Quicksort and partition, inside Quicksort first recursive call should be from low to (pivot_location -1) and inside Partition when A[i] is less than pivot then swap will be done on A[i] and A[leftwall + 1]. Also writing swap(pivot, A[leftwall] is wrong you should write swap(A[low],A[leftwall])

  • @pcccmn
    @pcccmn 2 роки тому

    Why is this and Computerphile's explanation so vastly different but the outcome is the same? Which is the correct "quicksort"?

  • @zebra7707
    @zebra7707 10 місяців тому

    I am a Computer Science student, have watched 100s of videos of quick sort, always skipped this for exams….. But from now on,,, Never

  • @mehdibadaoui1658
    @mehdibadaoui1658 4 роки тому +3

    when i search for something on youtube and see one of your videos in the results i genuenly get excited

  • @DorianC
    @DorianC Рік тому

    Ironic how quick sort is the longest of your sort videos...

  • @Bibbatron
    @Bibbatron 2 місяці тому

    I remember i wrote a quicksort program understood fully the concept and 6 months later i dont even remember the concept. Quicksort is such a weird algorithm

  • @cat-developer
    @cat-developer 11 місяців тому

    shouldn't it be swap(A[low], A[leftwall]) instead of swap(pivot, A[leftwall])

  • @jackys_handle
    @jackys_handle 2 роки тому

    Quick sort is really good when sorting numbers by hand pleasedontaskmehowiknow

  • @simohayha6031
    @simohayha6031 3 роки тому

    And if you get [4,3,7,5,8] and 8 is chosen as pivot then itemFromLeft is what? NULL? What then.

  • @oleksiy8105
    @oleksiy8105 Рік тому

    "I think you understand the concept so we'll let recursion handle the rest"
    NO I DONT ! Why you only used the right part of the list and not the left(2 1 0) ?

  • @zskostyak1
    @zskostyak1 4 роки тому

    The explanation was with Hoare partition scheme but the pseudo code is with Lomuto partition scheme. Those are different. Please check what you copy-paste!

  • @Alexis-ym9ph
    @Alexis-ym9ph Рік тому

    Pseudo code doesn't match to what you were explaining with itemFromLeft/itemFromRight. Where these notions are in the pseudo code?

  • @CloudStrife0896
    @CloudStrife0896 2 роки тому

    Really wonder why the hell they call this "Quick Sort" more like "The slowest, easiest to mess up, complex sort."
    I get that the average case is what we're after, but if worst case is n² anyway, might as well choose a different sort imo.

  • @SunsetsOverBatteryCity
    @SunsetsOverBatteryCity 5 місяців тому

    Him: “quick sort = pivot”
    Me: “WHILE HE HID IN RADIO WE PIVOTED TO VIDEO 🗣️💥”

  • @AaryanDhand
    @AaryanDhand 7 місяців тому +1

    thank you so insightful :)

  • @MoguMogu818
    @MoguMogu818 7 місяців тому

    I was able to write quick sort in a day when I first learned it, and now I completely forgot and feel stupid. This is my major, how tf did I forget this algorithm.

  • @Carl-Gauss
    @Carl-Gauss 6 місяців тому

    4:11 I think the more precise way to put would be not “chosen properly” but instead “we don’t get very unlucky”.

  • @TheoWasHere2
    @TheoWasHere2 4 місяці тому

    this ain't how they explained it to us... Like, how many different quicksort are there that the way it's shown are that different from each other...

  • @corben3695
    @corben3695 3 роки тому

    I don't get how people aren't understanding this explanation, the only thing I'm confused about is what "O" is

  • @BigSmoke-r9w
    @BigSmoke-r9w 2 місяці тому

    Pivot is reference. You just got to put all the values that is larger than the pivot to the right and values smaller than the pivot to the left. Thats all it is. Why are the comments overreacting??

  • @タクリス
    @タクリス 2 роки тому

    I'm confused about the left and right...the right sometimes go to the left vice versa

  • @jonathanfoss7825
    @jonathanfoss7825 3 роки тому

    You can't say you understand how the recursion works if you don't explain the base case that terminates the recursion. There is a big hole in the explanation for when you hit 1 or 2 elements in the subarray that defines how to end the recursion itself.

  • @Evoleo
    @Evoleo 4 роки тому

    Dude wtf this is so confusing you say pick an item from right to pivot but 3 is already right-most... At least mark the center position if you meant to

  • @Shay-mw1hh
    @Shay-mw1hh 29 днів тому

    I don't get it. What if the pivot has no greater than or less than itself? What numbers can it compare to?

  • @Brooklyn-nk9by
    @Brooklyn-nk9by Рік тому +2

    Love the videos!

    • @Guy19372
      @Guy19372 Рік тому

      Haha you copied me! Very funny feel like a real bogo sort right now

  • @keyser1989
    @keyser1989 11 місяців тому

    def quicksort(arr):
    if len(arr) < 2:
    return arr
    else:
    pivot = arr[0]
    less = [i for i in arr[1:] if i pivot]
    return quicksort(less) + [pivot] + quicksort(greater)

  • @TragicGFuel
    @TragicGFuel 4 місяці тому

    This algorithm fails the case for an already sorted list, like [4,5,6]

  • @asiano3385
    @asiano3385 Рік тому

    What if there is a number that is not smaller than pivot or larger than pivod? What if only one of the statements is true? (Only left or only right)

  • @lapnguyenhoang7774
    @lapnguyenhoang7774 Рік тому

    Why 8 is an item from left of 7 >>> both 5 and 8 are itemFromRight ....