Quicksort: Partitioning an array

Поделиться
HTML-код
  • Опубликовано: 23 ноя 2024

Комментарии • 1,3 тыс.

  • @whoopdeedoodude
    @whoopdeedoodude 5 лет назад +136

    All the fancy power points and drawing tablets and still the best explanation is a homie with paper cups.
    Thank you, sir!

  • @diegod.8518
    @diegod.8518 3 года назад +202

    I think it's funny how you don't use anything fancy to explain this, and yet your explanation is still one of the best.

    • @mtophir
      @mtophir  3 года назад +26

      Thank you. Glad you liked it :)

    • @nadavsam
      @nadavsam 3 года назад +4

      Not sure.. have you seen the Hungarian dancers?

    • @hernancedillo6144
      @hernancedillo6144 3 года назад

      Thank you for the thorough explanation!!

    • @bipdopbop1878
      @bipdopbop1878 2 года назад

      Its called being a good teacher

  • @srishtiavalakki751
    @srishtiavalakki751 4 года назад +41

    One of the most understanding videos i have seen so far about QuckSort. Thank you sir, extremely understanding

    • @mtophir
      @mtophir  4 года назад +4

      Glad you liked it

    • @zingg7203
      @zingg7203 3 года назад

      Understandable*

  • @conea6891
    @conea6891 3 года назад +29

    This is the best video on Quicksort.
    However, at 4:05, we could just swap "Pivit" and the "i+1".

    • @crazguykwan8955
      @crazguykwan8955 3 года назад

      Yo I'm glad you said that. I was about to make a loop to shift them all (which would increase the time complexity). But your suggestion gives the same result (numbers to the right are larger than pivot) at a shorter time complexity

  • @justdanaus
    @justdanaus 3 года назад +14

    I watched your instruction twice, not because it's hard to understand but so enjoyable to watch. Thank you

  • @shikha125
    @shikha125 2 года назад +30

    I've never seen such an amazing teaching method, thank you! This is gold

    • @mtophir
      @mtophir  2 года назад +7

      Thank you for the compliment!

  • @fodecissokho9918
    @fodecissokho9918 2 года назад +13

    Usually I don't comment on video but I have to make an exception for this one because EVERYTHING WAS JUST PERFECTLY EXPLAINED....
    It changes from the videos where the guy takes more than 10mn to explain it in a way that will confuse more
    KEEP IT UPP 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥

    • @mtophir
      @mtophir  2 года назад +2

      Thank you for the compliment. Glad you like the video.

  • @21void5
    @21void5 5 лет назад +21

    this explains a lot why "i" started at index -1. Thanks.

  • @adilbaig7022
    @adilbaig7022 3 года назад +4

    Only after watching this video did I understand that the `i` only increments when a swap happens, in effect keeping track of where the pivot should finally rest. The best explanation I've seen on quicksort partitioning!

  • @karimp59
    @karimp59 2 года назад +12

    Thank you prof KC Ang. After so many days of confusion I finally got clear explanation from your video. Thank you for virtually sharing your knowledges!!

    • @mtophir
      @mtophir  2 года назад +3

      Glad it was helpful!

  • @zoriiginalx7544
    @zoriiginalx7544 2 года назад +10

    This is amazing! Great explanation. I could not understand quicksort until you masterfully and elegantly demonstrated how the algorithm works.

    • @mtophir
      @mtophir  2 года назад +1

      Thanks for the very kind words. Happy to help!

  • @angelamunyao7877
    @angelamunyao7877 5 лет назад +29

    This is the best explanation i've come across!

  • @namanaggarwal5417
    @namanaggarwal5417 Год назад +8

    not gonna lie, its the best video available for quicksort.

    • @mtophir
      @mtophir  Год назад

      Oh wow, that's the best compliment! Thank you for watching.

  • @fcsie
    @fcsie 2 года назад +4

    this is by far the best explanation of quicksort so far after pouring through countless videos.

  • @mapmappampam8758
    @mapmappampam8758 7 лет назад +34

    you are very good at explaining this complex algorithm!
    with your calmness it was very easy to follow you step by step.
    you are the only one that actually helped me to understand :)
    Great job! Thank you!

    • @ranggasob
      @ranggasob 7 лет назад

      This should be the 'go to' video for quicksort explanation

  • @peterbalogh5622
    @peterbalogh5622 2 года назад +27

    This is a clear explanation, but I'd avoid shifting the array at 4:07 and just swap the 4 and the 8 (that is, the element at the pivot position with the element at i+1) since it's much less work and it will also result in guaranteeing what we need: everything to the left of i + 1 is smaller than the pivot, everything to the right of i+1 is greater than the pivot, and the pivot is at i.

    • @jimmyfl0
      @jimmyfl0 2 года назад +4

      I thought the same, was surprised when he moved all the cups lol. Great video though! Super clear

    • @mtophir
      @mtophir  2 года назад

      Thanks both. This point has been discussed at length in the past. You may wish to read the video description. Thanks for watching!

  • @nightfox6738
    @nightfox6738 Год назад +4

    I find it really interesting how Quicksort as a sorting algorithm itself is intuitively quite simple but I've seen so many different methods for partitioning the array.

  • @andrewkaram6733
    @andrewkaram6733 3 года назад +3

    I struggled fully grasping this concept of why this works, you explained it very well and made the click that when I look back I don't understand where my confusion came through. Thank you so much.

    • @mtophir
      @mtophir  3 года назад +2

      You're most welcome. Good to know that this video had helped you overcome your struggles.

  • @sankalparora9374
    @sankalparora9374 3 года назад +8

    possibly best video on RUclips to understand Quicksort.
    Everyone just dry runs the algorithm - without clearly showing what's being done and why.
    You won 'em all!

    • @mtophir
      @mtophir  2 года назад

      Thanks~ I'm glad it helped.

  • @BrandNewByxor
    @BrandNewByxor 8 лет назад +1

    It's amazing how much better this tutorial is than the other ones out there. Especially from a non-native English speaker. I applaud you.

  • @estefaniac8260
    @estefaniac8260 5 лет назад +58

    Amazing explanation! Thank you, Thank you, Thank you :) Very clearly explained and the visual aids were amazingly helpful.

    • @mtophir
      @mtophir  5 лет назад +9

      You're welcome. Glad the video is of use to you.

  • @Mr.SuperMan
    @Mr.SuperMan 8 лет назад +2

    The loveliest explanation of partitioning ever made.
    Hats off to you man!

  • @aaryaveerrajput8031
    @aaryaveerrajput8031 3 года назад +6

    This Legend is replying to comments even after 6 years.❤

    • @mtophir
      @mtophir  3 года назад +5

      I'm no "legend" - I'm just an ordinary academic at a university. Thanks for your message, though.

  • @ChrisLeeX
    @ChrisLeeX 8 лет назад +1

    Incredibly helpful. Textbooks and online articles handwaved over partitioning. Thank you for explaining this so well.

  • @Bestcuriosity_1
    @Bestcuriosity_1 3 года назад +4

    This is the correct way every human being can get crystal clear understanding of hardest topic easily
    Respect to great teacher like you sir
    love & Respect from India

    • @mtophir
      @mtophir  3 года назад

      Thank you and glad that you found the video useful. :)

  • @kylefang8254
    @kylefang8254 4 года назад +1

    Thank you so much! This is the only explaination I can understand. No those fancy graphic animation and music, no confusing complex definition and pesudo code, just a straight forward visual explanation. After I watched this, the pesudo code suddenly makes sense now.

    • @mtophir
      @mtophir  4 года назад

      You're welcome and thank you for the kind words.

  • @rew23able
    @rew23able 7 лет назад +19

    Best explanation ever.
    Very clear and crisp explanation and the representation helps to literally visualize the problem.
    Thank you !

  • @JasonJason210
    @JasonJason210 3 года назад +3

    I wish our college lecture had explained it this clearly. College is where we go to get grades; RUclips is where we come to learn. Thanks KC Ang.

  • @prashantgupta808
    @prashantgupta808 4 года назад +13

    probably the best explanation of quick sort in so less time,one thing to say to understand this better you first go throuhh the video explain by mycodeschool channel and then watch this and you will see clearly how things are working here.
    Hats off you sir!
    Great job.....

    • @mtophir
      @mtophir  4 года назад

      Thanks for your kind words

  • @sakumas1183
    @sakumas1183 Год назад +5

    thank you for this video!! i love how you used the cups, it's so much easier seeing this happen in real life instead of a digital diagram/images on screen.

    • @mtophir
      @mtophir  Год назад

      Glad it was helpful!

  • @chtr33
    @chtr33 3 года назад +3

    I've been searching like a hour for a clear explanation. Thank you! You are a life saver.

  • @JaBoss397
    @JaBoss397 3 года назад +2

    you make so much sense, the hardest part of quick sort is understanding the first passing of the partitioning function. Thank you

    • @mtophir
      @mtophir  3 года назад +1

      Hope the visualisation in this video has made "the hardest part" a bit easier to understand.

  • @-kindredeternalhunter9907
    @-kindredeternalhunter9907 4 года назад +7

    You are honestly good . Ur way is the best way to explain this, dunno why people keep explain this by code, all viewer want to know is the idea to do q sort ans you did it well

    • @mtophir
      @mtophir  4 года назад +1

      Glad you liked it. Thank you so much 😀

  • @DataStructures
    @DataStructures 2 года назад +29

    Amazing, short, easy explanation

    • @mtophir
      @mtophir  2 года назад +9

      Happy to note you find the explanation easy to understand

  • @hidroklorotiazid
    @hidroklorotiazid 2 года назад +8

    This is the most clear explanation I have ever seen of the algorithm. Thank you so much.

    • @mtophir
      @mtophir  2 года назад +5

      Glad it was helpful!

  • @kentnixon1651
    @kentnixon1651 4 года назад

    Was having a lot of trouble understanding this algorithm until I stopped here and watched your video - now it totally makes sense! Thank you for taking the time to not only make the video, but to actually demonstrate the algorithm in physical form. It really helped me to learn much more concretely than any of the code snippets other tutorials were relying on.

  • @igorf243
    @igorf243 2 года назад +20

    It looks like this guy knows how to teach, awesome vid.

    • @mtophir
      @mtophir  2 года назад +4

      Thanks :) I try my best ...

  • @sudheerkaneti203
    @sudheerkaneti203 7 лет назад +1

    thank u sir....this is the most clear explanation than most of other explanations of quick sort in the youtube.

  • @JaBoss397
    @JaBoss397 3 года назад +9

    thank you again, I have spent my day trying to learn quick sort and this video actually gave a clear understanding to a point I can implement code with no problem. Thank you !!!!

    • @mtophir
      @mtophir  3 года назад +1

      Thank you for watching this video and leaving a comment!

  • @bilalkhanthedreamer
    @bilalkhanthedreamer 7 лет назад

    You're great sir. I was trying to understand quick sort from many days, but you made me understand the working of quick sort partition in less than 5 minutes. Thank you so much.

  • @Rliu1992
    @Rliu1992 7 лет назад +4

    Great explanation! One thing to mention is, instead of shifting everything from i+1 to the right, you can just do a swap of A[i+1] and pivot, (4 and 8 in this case) which is probably more efficient.

  • @marcelcohen4844
    @marcelcohen4844 7 лет назад

    I've been watching about 20 videos of quicksort, this is only one that explains the concept clearly

  • @Honest_Reply900
    @Honest_Reply900 6 месяцев назад +10

    One of the best explanations, you nailed it

    • @mtophir
      @mtophir  6 месяцев назад +2

      Thanks for the compliments!

  • @prashasthapaduri4425
    @prashasthapaduri4425 2 года назад +4

    Wow...the way you used the cups for explaning the concept is so creative

  • @billbez7465
    @billbez7465 4 года назад +3

    Agreed with previous person. The most clear description of Quicksort I've seen. Well done and thank you.

  • @nebula1100
    @nebula1100 3 года назад +2

    This is single handedly the best visualization of quicksort I've ever seen. Thanks for this!

    • @mtophir
      @mtophir  2 года назад +1

      That's a very nice compliment. Thank you!

  • @01binaryboy
    @01binaryboy 2 года назад +5

    I went though so many videos. This is where I have understood the logic behind this algorithm very well. Thank you so much Master.

    • @mtophir
      @mtophir  2 года назад +3

      Thanks for the positive comment!

  • @katrinejensrud537
    @katrinejensrud537 4 года назад +10

    this was the best explanation of Quicksort in youtube

    • @mtophir
      @mtophir  4 года назад +3

      Thank you. Glad you liked it.

  • @samuelvalentine7846
    @samuelvalentine7846 Год назад +6

    Please, can someone give all the humans, animals and plants as subscribers to this legend

    • @mtophir
      @mtophir  Год назад +1

      Very flattered by your comment! Thanks for watching.

  • @emeryli2331
    @emeryli2331 4 года назад +3

    he explains complex stuff in a very plain way. What an illustration!

  • @AlexRyaguz
    @AlexRyaguz 3 года назад +4

    The best explanation of partitioning I have ever seen.

    • @mtophir
      @mtophir  3 года назад

      Glad you think so. Thanks!

  • @courses-lectures
    @courses-lectures 3 года назад +2

    You are an amazing instructor ... its is considered the best tutorial in quick sort algorithm

    • @mtophir
      @mtophir  3 года назад

      Thank you for watching and for acknowledging the effort!

  • @spioboy1
    @spioboy1 4 года назад +4

    This is the best explanation of Partitioning on RUclips. Thank you!

    • @mtophir
      @mtophir  4 года назад

      Thank you~ glad you liked it.

  • @excelsior759
    @excelsior759 7 лет назад +1

    I believ i see your video everytime i need to refresh about quick sort. Thank you. I may have seen it more than 15 times !

  • @qaipak1
    @qaipak1 8 лет назад +7

    Teacher took 40 mins. Book took 1 hour. This guy taught me in 10 mins.

  • @曹小虎-k4n
    @曹小虎-k4n 7 лет назад

    The video describes the basic unit of computation in the processing of quick sort algorithm. Very clear and beautiful!

  • @Moch117
    @Moch117 Год назад +5

    Watched so many quicksort videos but this one is the best. Thank you good sir !

    • @mtophir
      @mtophir  Год назад

      Glad you liked it!

  • @indubitablewordsmith9138
    @indubitablewordsmith9138 5 лет назад +1

    He explained in 5 minutes what other videos didn’t in 10-15 minutes. Best quicksort video I’ve seen

    • @mtophir
      @mtophir  5 лет назад +1

      Thank you for your vote of confidence.

  • @ibotah
    @ibotah 4 года назад +11

    This is most certainly the easiest video to understand about partition. I literally am mad it's this easy haha!! Thank you so much!!! I definitely did NOT study this the day before my test :P

    • @mtophir
      @mtophir  4 года назад +7

      Thank you. I'm glad you find it useful.

  • @pastafarian8410
    @pastafarian8410 5 лет назад

    This is the best explanation of Quicksort I 've come across anywhere. Cheers

  • @i2Chinese
    @i2Chinese 7 лет назад +12

    At 4:06 (when the partitioning is finished) there was a shift in the array which is very expensive, for the purpose of the quicksort I believe it'd be a more beneficial if you instead swapped the pivot with (i + 1)

  • @MrChazmond
    @MrChazmond 4 года назад +1

    So simple and elegant, straight to the point. Much better than those overdone graphics you see in other channels.

    • @mtophir
      @mtophir  4 года назад

      Thank you for the kind words!

  • @anujagulhane8543
    @anujagulhane8543 3 года назад +3

    The kind of teachers we students crave for!!....Thanks Sir

  • @georgesmith9178
    @georgesmith9178 4 года назад

    The best part was that you actually pointed me to the fact the (i) pointer is initially at (low -1) and that it will not be out of bound because it will be incremented just before the first swap. Special thanks for that.

  • @eucliwoodhellscythe4324
    @eucliwoodhellscythe4324 4 года назад +7

    the best explanation of quick sort thank you

    • @mtophir
      @mtophir  4 года назад +1

      Glad you liked it!

    • @eucliwoodhellscythe4324
      @eucliwoodhellscythe4324 4 года назад +1

      @@mtophir wish me luck bro, im going to face interview in this week 🙏

    • @mtophir
      @mtophir  4 года назад +2

      @@eucliwoodhellscythe4324 Good luck! All the best!

  • @stealthslayer90
    @stealthslayer90 7 лет назад +1

    very clear! having i j and r and pivot on top of the cups really helped compared to other videos...

  • @jogofwar99
    @jogofwar99 8 лет назад +5

    Very smart implementation Mr. Ang!

  • @sohamchoudhury6767
    @sohamchoudhury6767 3 года назад +2

    7 years on and still this is the best

  • @Jack_X075
    @Jack_X075 8 лет назад +4

    Some more information for those coming here.
    This particular method, of taking the pivot as the last element, is known as the Lomuto Partition scheme. There are other partition schemes, that slightly alter the flow and complexity of the quick sort algorithm.
    Also, the process shown in the video has one problem, if the first element is less than the pivot the algorithm fails.
    This is easily solvable, just make the few changes below:
    1. I and J in the beginning point to the same element.
    2. If an element is less than pivot, I and J interchange, and then I is incremented, which if it happens in the first instance, means the first element is replaced by the first itself. No change.
    3. J increments normally.
    And finally, just swap the elements of the pivot and the final value of I, no shifting. This saves time.
    Just swap 7 and 2 in the beginning, or add any number itself to the array, less than 4, and try it out.

  • @h.cazador
    @h.cazador 5 лет назад

    Best demonstration I have seen for quick sorts. I'm a visual learner and using real world objects really helped, not to mention the great instruction and organized narration.

  • @giovannicarovanello62
    @giovannicarovanello62 7 лет назад +5

    I finally understood QuickSort(A[],first,last). Thank you very much. You video was very illuminating!

  • @memeingthroughenglish7221
    @memeingthroughenglish7221 6 месяцев назад +2

    clever way of sorting the array and demonstrating how the i and j move through the loop together and make the pivot! Thank you so much for your efforts!!

  • @blackmamba9950
    @blackmamba9950 Год назад +3

    The best example I have seen on the internet. Thank you Sir

    • @mtophir
      @mtophir  Год назад

      That's a great compliment! Thank you.

  • @jorricktv9550
    @jorricktv9550 Год назад +2

    This video makes the topic really easy to refresh if you don't remeber the step by step opertions on the array

  • @zoltanbiro6388
    @zoltanbiro6388 3 года назад +8

    Best explanation ever of quicksort

    • @mtophir
      @mtophir  3 года назад

      Thank you, and thanks for watching.

  • @kk-ol7nw
    @kk-ol7nw 6 лет назад

    I surprised that so many people in RUclips do not understand how the quicksort works even if they post the video about it. Except for him. great video.

  • @sonofage
    @sonofage 3 года назад +5

    OMG, your explanation makes a lot of sense compared to other videos i've seen, NOW I GET IT>>>>>>>>>>>>>>>> THANKS

    • @mtophir
      @mtophir  3 года назад

      You're welcome!

  • @shivanshoe
    @shivanshoe 5 лет назад

    He is probably the simplest man on internet! Thanks man! appreciate it.

  • @kevinvira
    @kevinvira 7 лет назад +14

    Finally I know how QuickSort works. Thank you.

  • @VijayBhangur-b7e
    @VijayBhangur-b7e Год назад +1

    After going through so many contents and RUclips videos I finally found someone explaining the Quicksort in a very clear manner. Brilliant job KC...!👌

    • @mtophir
      @mtophir  Год назад +1

      Glad it helped!

  • @akhilsanker2681
    @akhilsanker2681 3 года назад +3

    Just Awesome !!!! Crystal Clear !! Tried a few lectures!
    This is GOLD!
    👍❤️

  • @buraiden917ify
    @buraiden917ify 9 лет назад +2

    Thank you very much. This video was very helpful in understanding the PARTITION algorithm.

  • @mukul98s
    @mukul98s Год назад +5

    This is the best video on quick sort I have watched . Thanks man for making this amazing video.

    • @mtophir
      @mtophir  Год назад +2

      Thank you. Glad you liked it!

  • @yolamontalvan9502
    @yolamontalvan9502 Год назад +2

    WOW, I MEAN WOW. This is the best explanation of the QuickSort I have seen. Not even AI help could have shown that. Thank you.

  • @sulaymonolimov7798
    @sulaymonolimov7798 Год назад +21

    Amazing explanation!

    • @mtophir
      @mtophir  Год назад +1

      Glad you think so!

  • @GHB775
    @GHB775 7 лет назад +1

    definitely the best explanation to be found on youtube. Thank you!

  • @crepkey
    @crepkey 5 лет назад +3

    This is the first explanation that I understand immediately after I've watched it! Thank you so much! Greetings from Hungary :)

  • @amadousallah6634
    @amadousallah6634 7 лет назад +2

    Wow! What a great instructor. This is brilliant. Thank you so much for the amazing explanation.

  • @n00byscrazycorner43
    @n00byscrazycorner43 3 года назад +3

    Great video, thank you so much. The book and examples made no sense, but this is a lot better than the examples online.

  • @ThePr0Br0
    @ThePr0Br0 5 лет назад

    I'm crying, you have successfully beaten my top ranked uni professors. Perfect explanation

  • @leahwilson5471
    @leahwilson5471 7 лет назад +4

    Best video I've seen yet... keep up the good work!

  • @dewittli7570
    @dewittli7570 4 года назад +2

    best explanation of the algorithm, cleared my confusion in minutes. thank you!!

  • @Asiful_seu
    @Asiful_seu 6 месяцев назад +3

    very very impressive way to teach quick sort , thank you so much .

  • @steven3394
    @steven3394 3 года назад

    Whoever came up with this sorting is a genius

  • @amrsaber5457
    @amrsaber5457 9 лет назад +27

    at the last step you should swap not shift ... shifting means moving all the next objects and that would be with no purpose ... but swapping does the work simply with no extra efforts

  • @danielwang4904
    @danielwang4904 5 лет назад

    You just did an explanation that is better than any of my professors. THANK YOU!!

  • @ayanbiswas6849
    @ayanbiswas6849 4 года назад +3

    This is the best video on Quicksort

    • @mtophir
      @mtophir  4 года назад

      Thank you. Glad you enjoyed it.

  • @Karthik-yy6up
    @Karthik-yy6up 8 лет назад +2

    Such a calm explanation.

  • @m16averick
    @m16averick 4 года назад +5

    Very clear explanation! Wish all of my proffessors had this impact

    • @mtophir
      @mtophir  4 года назад +2

      Thank you for your kind words

  • @SaurabhKr
    @SaurabhKr 7 лет назад +2

    One of the best simulations of the partition procedure, thanks for making this video :)
    I hope to see more of your video.
    Thanks