Quicksort algorithm

Sdílet
Vložit
  • čas přidán 21. 07. 2013
  • See complete series on sorting algorithms here:
    • Sorting Algorithms
    In this lesson, we have explained Quick sort algorithm and implemented it in C++. Quick sort is a divide and conquer algorithm that has an average case time complexity of O(nlogn).
    For more such videos and updates, subscribe to our channel.
    You may also like us on facebook:
    / mycodeschool

Komentáře • 1K

  • @KarthikRaja-bq7pk
    @KarthikRaja-bq7pk Před 5 lety +1225

    Yesterday I saw all your videos on sorting. Today in interview they asked me to explain quick and bubble sort. I got selected.
    You are a good man.
    Thank you.

    • @SumitKumar-fn3gj
      @SumitKumar-fn3gj Před 5 lety +11

      Which Company Brother?

    • @chaitanyavelagapudi1164
      @chaitanyavelagapudi1164 Před 5 lety +2

      A company duit

    • @srivatsav9
      @srivatsav9 Před 4 lety +68

      He passed away in 2014. Very few people can do good even when they aren't around. This is one such guy.

    • @aakashprasad9777
      @aakashprasad9777 Před 4 lety +1

      @@srivatsav9 how could you be so sure

    • @tushargahlaut5812
      @tushargahlaut5812 Před 4 lety +2

      @@srivatsav9 I have also heard about it.
      But one thing I don't get is why are there uploads in the year 2016?

  • @SudhanshuKumar-lp1nr
    @SudhanshuKumar-lp1nr Před 3 lety +350

    7 years ago still the best explanation out there!!

  • @miguelmenindez6826
    @miguelmenindez6826 Před 8 lety +256

    Man, by freaking far the best and most simple 101 explanation of QuickSort algorithm ... what can I say, I've become a fan!

  • @marrom6808
    @marrom6808 Před 2 lety +11

    Thanks to your series, I've been able to implement selection-, bubble-, insertion-, merge- and now the quicksort algorithm in the Rust programming language, through your excellent and descriptive explanation of the core concept of the algorithms, as well as the in-depth technical details. I am very grateful for your videos, much thanks.

  • @saifulhasan2532
    @saifulhasan2532 Před 3 lety +12

    This man passed away but his voice still helps us and he is alive in our hearts.

    • @bestchannel8056
      @bestchannel8056 Před 2 lety

      how do u know that he is passed away man!

    • @saifulhasan2532
      @saifulhasan2532 Před 2 lety

      @@bestchannel8056 www.freecodecamp.org/news/mycodeschool-youtube-channel-history/

    • @chickmagnet2067
      @chickmagnet2067 Před 2 lety +3

      Actualy its his friend. Not him. He works in google since sometime.

    • @ankurchaudhary7892
      @ankurchaudhary7892 Před 2 lety

      @@saifulhasan2532 HUMBLE FOOL IS PASSED AWAY NOT HE HE WORK IN GOOGLE NOW

  • @anusuyarangasamy
    @anusuyarangasamy Před 10 lety +15

    The explanations are so crisp and clear. I always wanted someone to make videos this precise. Looking forward to more such videos in your channel.

  • @patil88ganesh
    @patil88ganesh Před 8 lety +12

    Thanks mycodeschool. One of the best part of your videos is that the writing and explanation are quick unlike other video lectures which spend most of the time in writing/erasing/repeating. One of the best teaching method I have ever seen with digital aid. Keep up the good work! Thanks a lot!

  • @mycodeschool
    @mycodeschool  Před 10 lety +35

    Hi Anthony,
    We are building a queue where we are logging all the video requests. Your video request is already in this queue. We cannot promise a timeline because video creation takes time and we only have one mentor doing it right now. We are hoping to speed up by pulling in more contribution.

  • @vibhavsharma2980
    @vibhavsharma2980 Před 6 lety +12

    Composed voice,patient visualization,clear depiction, you are a rock star of computer science..an Indian genius

  • @anjanobalesh8046
    @anjanobalesh8046 Před 2 lety +7

    Man ...I was in college 2nd year grad 4 years ago watching this on my way to college in bus... Im watching this again to change my job .. This is the best sorting series in CZcams crystal clear ☺️☺️

  • @kaiauden4195
    @kaiauden4195 Před 7 lety +5

    Man, huge respect to all of your tutorials. Always appreciate your hard works!!!

  • @turing_machine544
    @turing_machine544 Před 27 dny

    I somehow found your video in my first year of college (2020) and today i have graduated (2024), still when i have to revise algorithms i watch your tutorials.
    I know you are no more in this world, but your contribution to community will always be remembered sir.

  • @rebeccakipanga478
    @rebeccakipanga478 Před 9 lety +227

    Oh...Dear sir,ii'm almost your student on youtube!!! all time appreciate your videos....you have a great skill which is helpful to most of us....thanks.

    • @mycodeschool
      @mycodeschool  Před 9 lety +34

      You are most welcome Rebecca becky :)

    • @SonuSonu-tk5pk
      @SonuSonu-tk5pk Před 7 lety +2

      go to ur country and study..

    • @rebeccakipanga478
      @rebeccakipanga478 Před 7 lety +3

      Beleive in Jesus Christ!!
      He is the true God!!!
      Beleive in God Jesus!!Amen!!

    • @rebeccakipanga478
      @rebeccakipanga478 Před 7 lety +1

      Beleive in Jesus Christ!!
      He is the true God!!!
      Beleive in God Jesus!!Amen!!

    • @rebeccakipanga478
      @rebeccakipanga478 Před 7 lety +18

      You act as someone who never went abroad....
      Try to take a plan and travel out of India, you gonna meet nice people even your behavior gonna change!
      Globalisation means ;having an open mind and stop thinking in a traditional way!!
      We all need each other in today life!
      You should first seek upon Jesus Christ !!
      God Jesus loves you!

  • @mycodeschool
    @mycodeschool  Před 11 lety +64

    You're most welcome :)

    • @sainthentai7763
      @sainthentai7763 Před 4 lety

      Hello, I just watched your video, it didn't explain many things to me, but most of them are still not clear to me. And I have one question. Why Q(A, 1, 1) ? Why not Q(A, 2, 1) ? Time: 12:54

    • @ganapatibiswas5858
      @ganapatibiswas5858 Před 4 lety +1

      @@sainthentai7763 Because pindex was 0,and end index was 1,
      so Quicksort(A,pindex+1,end)=Quicksort(A,1,1)

  • @sophies2103
    @sophies2103 Před 4 lety +2

    Finally somebody who actually fully explains how this algorithm works and does not skip any details. Thank you so so much! 🙏🏻

  • @indrasishbanerjee5115
    @indrasishbanerjee5115 Před 8 lety

    This channel needs to get more recognition. Without this I wouldn't have sound knowledge on different sorting techniques. Thank you!

  • @AlexanderMcNulty92
    @AlexanderMcNulty92 Před 7 lety +50

    *that moment when he shows the code at the end*

  • @dance2die
    @dance2die Před 7 lety +45

    I've learned more about Quick Sort here than 3 books I've read on it.
    Great job @mycodeschool!

    • @erikrusso9808
      @erikrusso9808 Před 4 lety +20

      What books did you read? Twilight?

    • @SkillUpMobileGaming
      @SkillUpMobileGaming Před 4 lety

      Why would you read three books on Quicksort? Quicksort is not even applicable to the real world.

    • @Onomandah
      @Onomandah Před 4 lety +1

      @@SkillUpMobileGaming It is, that's why we learn it, silly.

    • @RAHULTMNT100
      @RAHULTMNT100 Před 4 lety +1

      @@SkillUpMobileGaming wtf are you talking about

    • @rayaanhussain7279
      @rayaanhussain7279 Před 4 lety +5

      @@SkillUpMobileGaming It is literally the algorithm that is implemented in most sort functions in many language libraries

  • @pauliewalnuts6734
    @pauliewalnuts6734 Před 7 lety +1

    finished first year 2 years ago but i find myself back here to brush up on some basics before a final exam. This man will forever be relevant mycodeschool keep up the good work

  • @CaptainSlowbeard
    @CaptainSlowbeard Před 7 lety +1

    Thank you so much for this video - this is the only one I've found that was really clear on both the concept and, more importantly, the implementation of the algorithm.
    You have real talent as an educator, and I'm sure there are many people who appreciate your tutorials - hope to see more in the future, if you have time!

  • @rishijain7171
    @rishijain7171 Před 7 lety +38

    love u man!!!! seriously.... the world needs more teachers like u!!

    • @paragrane5676
      @paragrane5676 Před 5 lety

      @BeautifulDrugs Lover how do u know ?

    • @nikhilraghute6560
      @nikhilraghute6560 Před 5 lety

      @@paragrane5676 you can go through this answer, even his mother has commented there. qr.ae/TUnAzM

    • @udaykadam5455
      @udaykadam5455 Před 5 lety

      @@paragrane5676 because he is humblefool.
      Well known personality in Indian coding community.

  • @newbiedevtons
    @newbiedevtons Před 4 lety +3

    i really love this guy, he's the very good at making something really complicate understandable

  • @karantiwari9328
    @karantiwari9328 Před 3 lety

    Wow! I couldn't find a single video that explains quicksort better. Thank you so much for such a thorough and easy to understand tutorial!

  • @nipunb20
    @nipunb20 Před 5 lety

    Been going over all your videos over the past several weeks - the content and presentation is amazing. I've learned so much and now I have much better intuition of all these algorithms.

  • @sethigoldy
    @sethigoldy Před 10 lety +48

    Less than 18 hours from my exam its good to watch this video

  • @ultimatehuzefa
    @ultimatehuzefa Před 8 lety +28

    U made indians proud sir!
    Awesome explanation

  • @Tyler1986
    @Tyler1986 Před 6 lety +1

    I've been trying to get quick sort down for 3 days, read tons of posts on it, this is the 4th or 5th video I've watched. This was better than any of the short ones I watched and goes in depth and actually works well. Thanks!

  • @jenna4523
    @jenna4523 Před 3 lety +2

    Explaining the tracing of the algorithm helps sooo much especially with recursion. So helpful!

  • @chayarenathomas1847
    @chayarenathomas1847 Před 7 lety +3

    Thank you so much for this video! I was stuck on understanding the implementation and your video helped me understand the logic we use when writing the code. Thank you!!!!

  • @coltwilson3271
    @coltwilson3271 Před 9 lety +102

    Just wondering, do you write your own Subtitles/Closed Captions? Because they seem to be unusually spot on.

    • @mycodeschool
      @mycodeschool  Před 9 lety +137

      Colt Wilson We get help from some volunteers.

  • @umarusman2
    @umarusman2 Před 2 lety +1

    There can not be a better explanation for quick sort than this one, hands down!

  • @danish_m_m
    @danish_m_m Před rokem

    I have not come across a single video on quick sort which explains the working as well as the pseudo code so much clearly, thank you!

  • @nikolaichichulin
    @nikolaichichulin Před 9 lety +4

    You do great job, thank you!
    This particular way of choosing the end point as pivot has an interesting side effect to learn for beginners. If you try to sort some already sorted array like {1,2,3,...,100000}, you get the stack overflow error. It's almost obvious, because pIndex will be 99999, 99998, 99997 and so on. So after some recursions the program crashes.

  • @mycodeschool
    @mycodeschool  Před 10 lety +18

    You're welcome Luisa :)

  • @gabrielahernandez4236
    @gabrielahernandez4236 Před 2 lety

    THIS MAKES SO MUCH SENSE THANK GOD. i spent a whole two hours trying to figure out things with another video that was way more confusing than this. thank you!!! you sir, have saved me from like two more hours of stress. much appreciated.

  • @bob_factory
    @bob_factory Před 6 lety +1

    Simply, great buddy, I have been looking around for a simple explanation as this for a very long time now and yours is the only one that matches. keep it up bro.

  • @kingstonmocktail7744
    @kingstonmocktail7744 Před 5 lety +6

    "Think about it and you will get it" - well said my friend, well said.

  • @Paul-yw4yr
    @Paul-yw4yr Před 10 lety +22

    Wow, great explanation! I thought I would need more time to get this. Thank you =))

  • @alanespinet8423
    @alanespinet8423 Před rokem

    Best explanation of Quick Sort I've ever seen in my life. Thanks, man!! This video deserves way more likes

  • @cafafans
    @cafafans Před 4 lety +2

    As a Profesional Full Stack Software Developer; I always come back to mycodeschool just to listen to your voice again. Thank you master; your reward is in haven...

    • @bhuvanesharasu
      @bhuvanesharasu Před 4 lety

      He really did pass away in 2014 in a accident.

  • @amarputsala4090
    @amarputsala4090 Před 9 lety +10

    Nice video .., Explaining in-detail. this is best video to understand quick sort algorithm.

  • @hovhadovah
    @hovhadovah Před 6 lety +6

    Absolutely wonderful tutorial, thank you very much! I couldn't find any video that explained this as clearly as you did. Your annotations and colors are great.

  • @balaganesh3440
    @balaganesh3440 Před měsícem

    I just came back to hear your voice again. People don’t understand that unlike today, the computer science in the 2010s hit a different feel.

  • @rutwikhiwalkar9583
    @rutwikhiwalkar9583 Před 4 lety

    After watching like 100 different videos I finally understand this, implemented in both python and java works as expected. Good job dude!

  • @Abhi-eo6jy
    @Abhi-eo6jy Před 2 lety +3

    almost 9 years ago still the best explanation out there!!

  • @venkarri8534
    @venkarri8534 Před 10 lety +5

    Excellent tutorial. Combining code with visualization is incredibly great. Keep up the good work. Could you please post a video on building a heap data structure, with all its operations (insert, delete etc.) including heap sort ?

  • @monishkumar2780
    @monishkumar2780 Před rokem +2

    Thanks for saving the day, legit one of the best and simplest explanation. This is sort of the best sudo code one is looking for with complete understanding.

  • @krishnachamarti1256
    @krishnachamarti1256 Před 7 lety +1

    Thank you, this was incredibly helpful! Good breakdown from the basic idea to the implementation. Every other video I tried did a shoddy job of explaining what quicksort actually is - they just jumped into doing it and meaninglessly telling you what to do.

  • @tyli8698
    @tyli8698 Před 8 lety +3

    sir, seriously, u r awesome. thank you so much for the playlists!

  • @arpityadav2268
    @arpityadav2268 Před 2 lety +3

    I Wish you were my professor of my CS department. I would top my classes after taking classes from you. So neatly explained! Loved it! 🥰😎😍

  • @sandeepreddy8859
    @sandeepreddy8859 Před 4 lety

    By far the best and most simplest explanation of quick sort algo and code.

  • @XanderWood
    @XanderWood Před 8 lety

    What an excellent tutorial! I didn't have a clue how quicksort worked until watching this. Thanks for the video :D

  • @johann-san
    @johann-san Před 9 lety +17

    I believe there is a condition that can be added to the logic to avoid unnecessary swaps. For instance, if we have the following array 7 2 1 6 4 5 3 8 where the pivot is the last and highest element 8, we would be calling the swap function unnecessarily because all the elements are less than the pivot (probably the necessary logic in this case would be just to increment the pIndex because the element is less than the pivot and is correct to be placed on the left side, hence increment the pIndex ). Adding a check to swap only if the pIndex != than i would help. Something like:
    for( i

    • @smbehindyou
      @smbehindyou Před 7 lety

      yes - you are absolutely correct

    • @varshar5856
      @varshar5856 Před 6 lety

      I'm sorry, I cant get the last condition. Whats right? Is it end-1? And do you mean (Pindex!=end)?

    • @sanketughade6986
      @sanketughade6986 Před 6 lety

      thanks brother...you saved me...i was going wrong with the pseudo code explained a lot !!...thanks a lottt !!!

    • @pvpaparaokancharapu3219
      @pvpaparaokancharapu3219 Před 6 lety

      if(pindex != i )
      {
      swap(A[pindex],A[end])
      return pindex
      }
      else return end

    • @willamsurya6901
      @willamsurya6901 Před 6 lety +1

      I think it is better to have a single unnecessary swap than to have a longer code as a longer code will require more time to process, won't it?

  • @wenigmehl
    @wenigmehl Před 9 lety +1125

    indian tutorials are the best xD

    • @lincolnchafee9602
      @lincolnchafee9602 Před 8 lety +86

      +wenigmehl i know lol! the depth of their knowledge and ability to explain things simply is so awesome :P

    • @vidhursavyasachin7797
      @vidhursavyasachin7797 Před 8 lety +15

      +wenigmehl sarcastic

    • @lincolnchafee9602
      @lincolnchafee9602 Před 8 lety +33

      oh lol that went over my head. once i get past the different accent i have actually learned a lot from them XD

    • @SonuSonu-tk5pk
      @SonuSonu-tk5pk Před 7 lety +1

      go to ur country...

    • @adilismail3593
      @adilismail3593 Před 7 lety +34

      thank u brother..
      its due to the simple english followed by us

  • @dhrubo619
    @dhrubo619 Před 7 lety

    I was trying to look up for the quick sort codes in Java, and I stumbled upon your tutorial and by following the whole tutorial I was able to write the quick sort in Java myself. Thank you very much

  • @mycodeschool
    @mycodeschool  Před 11 lety +1

    Hi Soumyajit,
    In randomized quick sort, instead of choosing pivot as last index, choose any random index (using a library function to generate random number) and first swap the number at this random index with element at last index. Rest remains the same. Try and let me know if you are not able to do it on your own.

  • @doctorlazarus8854
    @doctorlazarus8854 Před 5 lety +3

    Nice video as always.
    But may I know which softwares do you use for writing and recording? Also do you use a stylus for writing?

  • @mostinho7
    @mostinho7 Před 3 lety +3

    Done thanks
    Todo take notes
    The partition function starts off with the pivot at the midpoint but ends up returning an index for the pivot AFTER all the smaller elements have been moved left of the pivot and all the larger elements right of the pivot
    15:00 logic for moving elements before the pivot

  • @kennylee6972
    @kennylee6972 Před 6 lety

    Well done, you made it so easy to visualise what is happening on the surface as well as when you dive into the code. Not many people can pull that off

  • @bit_FLIP
    @bit_FLIP Před 8 lety

    I must have watched at least 10 videos today, but this was the one that helped me to understand it the best. Thank you so much for this explanation

  • @LamiAtZenith
    @LamiAtZenith Před 8 lety +14

    Best tutorials out there! Better than my lectures man thank you!

  • @rayhane6497
    @rayhane6497 Před 8 lety +6

    I finnaly understood this sort :D .. Thank you so much

  • @ruanlehanie5851
    @ruanlehanie5851 Před 6 lety

    Best tutorial you'll find on quick sort, explains EVERYTHING you need to know clearly and correctly.
    Wrote my data structures and algorithms exam and I got 0 for using this method, specifically refering to the graph showing how the numbers are sorted as that is what was asked.
    This is probably due to that fact that my text book handles the quick sort algorithm differently, for instance the pivot in my text book is found through ( first element + last element ) / 2

  • @crazystuff6760
    @crazystuff6760 Před 4 lety

    The BEST explanation of Quick Sort Ever!!!
    Thanks for this wonderful video.

  • @phantuanngoc
    @phantuanngoc Před 6 lety +6

    Thanks mycodeschool.very nice video

  • @sushiwalker232
    @sushiwalker232 Před 8 lety +4

    "Just think about it and you should be able to get it. " towards the end hahaha

  • @joshuaopata6433
    @joshuaopata6433 Před 2 lety

    the only guy who has been able to make me understand quicksort this easy

  • @ArjunPatel-hi5eq
    @ArjunPatel-hi5eq Před 9 lety

    I love how you really explain and show the base case in action

  • @nikitacollier4065
    @nikitacollier4065 Před 7 lety +5

    Good explanation! Very helpful! now i just need to implement this in assembly....not so easy lol

  • @pranavkotteswaran4093
    @pranavkotteswaran4093 Před 8 lety +5

    Excellent lectures.....love ur teaching methodology....can u post the video on Shell sorting technique...?

  • @Rajeshkumar-rj5my
    @Rajeshkumar-rj5my Před 6 lety

    You have done a fantastic Job! my friend. Your tutorial is so good and a complete one. I have gone through so many articles, but nothing was like this one. Explanations were crystal clear and precise as well, straight to the point, really feels good when we go through your tutorial video playlist. Well done!

  • @highmem
    @highmem Před 2 lety +1

    Best digital explanation of quick sort. Your videos are very rich and make use of technology amazingly to make sure that viewers understand the algorithm perfectly. Thanks a lot for creating and sharing these videos.

  • @folcotandiono6736
    @folcotandiono6736 Před 8 lety +11

    how about if a[0] is smaller than pivot, the a[0] and a[index] (that start with zero) will change place while i++ and index++ it will swap the same index

    • @ericnawnaw
      @ericnawnaw Před 5 lety +2

      I got confused at first too. But it's just extra operation and doesn't affect the correctness of Algorithm.

    • @tarunkumarreddy5020
      @tarunkumarreddy5020 Před 3 lety

      @@dasgoood2811 nothing happens even if u r swapping(i , pIndex) even they are in the same position only it is considered as an extra step that's it....

  • @ninetynin
    @ninetynin Před rokem +3

    wishing the legened is still alive
    rip humblefool

  • @qazizaahirah4168
    @qazizaahirah4168 Před 6 lety

    Can we take a moment to appreciate your explaining skills. Great Job!

  • @laurenp2701
    @laurenp2701 Před 9 lety

    This video really clarifies the concept of quicksort for me. Thank you for the explanation!

  • @srikantjenakumar
    @srikantjenakumar Před 4 lety +3

    Really great tutorial.
    I have one question, why do we need the last swap(..) method before the return statement?. If we can run the loop till the pivot element, then the pivot element will automatically come to its position after the swap. Please let me know if I am wrong.

  • @lravikiran88
    @lravikiran88 Před 8 lety +39

    THIS SORTING WILL TAKE SOME TIME TO UNDERSTAND

  • @poompataipuntidpong3700

    This is really great!! I just learn programming and your video get me to understand the concept , and then I can figure the function out myself!! This is a great way of learning. Your video really deserves more views!!

  • @aashishgoyal1436
    @aashishgoyal1436 Před 5 lety

    This is the best and easiest partition function i ve seen in quick sort implementation. simply too good

  • @HeyltsKenzi
    @HeyltsKenzi Před 5 lety +7

    Im going to win a medal at IOI 2020 in your memory Lord Harsh.R.I.P

    • @rohithdsouza8
      @rohithdsouza8 Před 4 lety +1

      The guy explaining the video is not Harsha but it's Animesh and he's still alive.

  • @ahmedsafwat85
    @ahmedsafwat85 Před 9 lety +3

    Very cool! The best video explaining Qucik Sort.

  • @nothingpersonal21
    @nothingpersonal21 Před 7 lety

    Man I've watched this video (and the mergesort video from this channel) before every exam, technical interview, etc for the last four years through university and whilst applying for jobs. Really excellent presentation. Thanks so much.

  • @onaspnet
    @onaspnet Před 4 lety

    This is the best tutorial I have seen for QuickSort

  • @shaikpspk
    @shaikpspk Před 3 lety +3

    We really miss you sir 😢😔💔 #rip #humblefool

  • @MrStarTraveler
    @MrStarTraveler Před 7 lety +11

    Very nice and descriptive video keep up the good work.
    But this case I have some criticism I feel is necessary since I implemented the algorithm and it doesn't work. The code presented in this video is for demonstration purposes only. The code as presented in the video works in the given case only and probably in some others but not in the general case.
    I just tried it and it doesn't work. The problem is in the partition function. For example: suppose under index 0 there is number less than four then there would be swapping of index 0 with itself since both 'i' and 'pIndex' are 0 at this point. And that swapping of the elements with themselves will continue until a bigger number is met, since both i and pIndex are incremented synchronously. The main problem however is that the algorithm can only "push" rightwards only one number. Suppose for example that at index 1 there was number 8 the first swap would change the positions of 7 and 8 and 8 would remain at index 0... And that would continue as long as the algorithm is busy pushing 7 rightwards, any other element bigger than 4 would remain in its previous place relative to the other elements. A number of passes is needed to push all numbers bigger than 4 right of the pivot.
    P.S. I only mean this as a constructive criticism, sorry If my comment sounds rude or something.
    There is a complete and working implementation of the algorithm: (look at the first answer not the question)codereview.stackexchange.com/questions/77782/quick-sort-implementation

    • @ravipapisetti1
      @ravipapisetti1 Před 6 lety

      I agree, with your analysis.

    • @syedsouban9870
      @syedsouban9870 Před 6 lety

      I implemented the algorithm in C and it does seem to work correctly:
      Have a look at my code in C (for a better version of code gist.github.com/syedsouban/230ad57f79b81a90812f9ba4d275d8da )
      #include
      void swap(int* x,int* y)
      {
      int t;
      t=*x;
      *x=*y;
      *y=t;
      }
      int partition(int* a,int start,int end)
      {
      int pivot=a[end];
      int pIndex=start,i,t;
      for(i=start;i

    • @ramrai2642
      @ramrai2642 Před 5 lety +1

      MrStarTraveler, you say, " Suppose for example that at index 1 there was number 8 the first swap would change the positions of 7 and 8 and 8 would remain at index 0". That is not possible since the partition index would be advanced. The whole point is to push *only* elements less than the pivot to left and then *protect* those smaller values by advancing the pivot index, cannot see how this can be broken. cheers

    • @kaipulla77
      @kaipulla77 Před 5 lety

      Can you give me an array input for which this doesn't work, please? I tried with duplicates and it works. Just curious.

    • @atulmalakar
      @atulmalakar Před 5 lety

      @@kaipulla77 5 4 3 2 1

  • @sekhardeka498
    @sekhardeka498 Před 4 lety +1

    I am watching this tutorial ....just 4 hours before my exam ( I am a Btech student and today is my practical exam on Data Structure and Algorithms).... Thank you so much sir....

  • @mgeasley
    @mgeasley Před 4 lety

    omg...finally..... the best quick sort explanation on the internet. THANK YOU

  • @alizafar4399
    @alizafar4399 Před 7 lety +4

    what does "O" and "n" in "O(nlogn) " refers to?

    • @Ramgautam12345
      @Ramgautam12345 Před 7 lety +4

      Ali Zafar it is known as the big Oh notation, to calculate the complexity and efficiency of the program. read about it.

    • @divelikejunk8557
      @divelikejunk8557 Před 7 lety +7

      O refers to the worst-case scenario, and n would be just a specific variable, depending on what action you're performing.
      For example, traversing an array would be O(n). n in this case would be the number of items in the array. O(n) indicates the amount of time, basically how many steps, it would take in the worst-case to traverse through that array. O(n) means that it would take n steps to traverse the array. So in this case the scalability of the method is linear. if you have 6 items in the array it would take 6 steps, if you have 12 items it would take 12 steps.
      In the case of O(nlogn), if you have 6 items in the list it would take 6*log(6) steps to implement that method. Specific numbers are not necessary for big O notation, what matters is the shape of the curve, so nlog(n) would have a logarithmic looking curve. What you're interested in is how much your function would scale depending on the input.

  • @subbuch89
    @subbuch89 Před 8 lety +3

    Did you consider negative scenario where all the elements on the left of the pivot are less than the pivot in the decreasing order ?

    • @KARTHIKPANCH97
      @KARTHIKPANCH97 Před 4 lety

      it doesn not matter . we just want that elemnts on left of the pivot are less than the elements on its right . WE DONT CARE ABOUT THE ORDER OF ELEMENTS. THATS WHAT WE DO IN FURTHER CALLS OF QUICKSORT AND PARTITION METHODS. Finally the array gets sorted.
      This may get reflected while calculating the time complexity

  • @adelineshen5515
    @adelineshen5515 Před 6 lety

    This is great! so much better than my professor, I understood the stuff that i've been struggling for a week!

  • @anuragghosh9710
    @anuragghosh9710 Před 7 lety +5

    sir could you provide the code link?

    • @muhammadzainzaheer2072
      @muhammadzainzaheer2072 Před 7 lety +1

      //QUICKSORT
      #include
      #include
      void QuickSort(int A[],int start,int end);
      int Partition(int A[],int start,int end);
      int main()
      {
      int A[50],n,i;
      printf("Enter the number of elements: ");
      scanf("%d",&n);
      printf("
      Enter the elements: ");
      for(i=0;i

    • @anuragghosh9710
      @anuragghosh9710 Před 7 lety

      thank u Muhammad Zain Zaheer

  • @AkshayKumar-dz5ts
    @AkshayKumar-dz5ts Před 7 lety +59

    //QUICKSORT
    #include
    #include
    void QuickSort(int A[],int start,int end);
    int Partition(int A[],int start,int end);
    int main()
    {
    int A[50],n,i;
    printf("Enter the number of elements: ");
    scanf("%d",&n);
    printf("
    Enter the elements: ");
    for(i=0;i

    • @sagardafle
      @sagardafle Před 7 lety

      Thanks man !

    • @Lollipop69420
      @Lollipop69420 Před 6 lety

      thnx bro and btw why dont u keep c programme for all the sorting explanation as some of them dont no c++ and it ll be useful to everyone too pls take it as a request

    • @vivektodmal1
      @vivektodmal1 Před 6 lety

      Why u need 2 temp variables you can use the same one for both the purposes in partition function

    • @farooqansari
      @farooqansari Před 6 lety +1

      Not all heroes wear capes.

    • @purplebeard806
      @purplebeard806 Před 6 lety +1

      Program takes inputs but does not sort :(

  • @vigneshk8139
    @vigneshk8139 Před 4 lety

    I'm watching this in Feb 2020. The best explanation on quick sort algorithm.

  • @wesinec
    @wesinec Před 4 lety

    This is the first video that I saw in your channel and I liked so much. I've already become subscribed.

  • @ManikantaRaju
    @ManikantaRaju Před 10 lety +3

    when you are doing swap(A[i],A[partitionIndex]); does the swapping happen since you are just passing variables and not the memory locations. so swapping will happen in the swa function and when you come out the original status of both the variables is returned!

    • @mycodeschool
      @mycodeschool  Před 9 lety +4

      Manikanta Raju Good catch.. the swap function can have a signature like void swap(int &a, int &b); Now , here we are taking a and b as reference variables. Reference variable concept is available in C++ (not in C). Its different from pointer. Now, here instead of local variables, actual arguments will be swapped. BTW, in the pseudo-code, the intent was just to say that, we should swap. In Pseudo-code, we ignore compilation and other errors.

    • @ManikantaRaju
      @ManikantaRaju Před 9 lety +1

      mycodeschool Thanks for the reply! yeah, so its reference variable in c++. I am new to c++ , thanks for the info! By the way you are simply awesome man, making algos look simple and straight! Also can you please do a video on converting a prefix string to infix string, not computing the string, but want the infix string from prefix!

  • @AbhishekSingh-ky2dn
    @AbhishekSingh-ky2dn Před 5 měsíci +17

    Who is still in 2024 ?hit like

  • @rahulkumar0249
    @rahulkumar0249 Před 4 lety +1

    Beat place for beginners.. I started watching this channel from my 2nd sems and still watching if I need revision of DSA

  • @alive4metal731
    @alive4metal731 Před rokem +1

    best quicksort explanation I've seen. thank you

  • @sainaths3655
    @sainaths3655 Před 10 lety +3

    Is there any link to learn Heap sort which is explained by you ?

    • @mycodeschool
      @mycodeschool  Před 9 lety +7

      SAINATH D'LEH Not yet,, we need to create one.

    • @FarhanArRafi
      @FarhanArRafi Před 9 lety +1

      mycodeschool yeah, bro make some heap sort video ASAP. thanks again.

    • @akhilsuresh2560
      @akhilsuresh2560 Před 8 lety

      +mycodeschool IT will be very helpful ..btw gr8 work!!!

    • @ZuestTV
      @ZuestTV Před 8 lety

      +mycodeschool no heap yet ):

    • @mycodeschool
      @mycodeschool  Před 8 lety +5

      +Hiimgosu My name is Animesh and I am the one who you listen to in most of these videos. Harsha who was my co-founder passed away in an unfortunate accident. But Harsha was mostly into other aspects of MyCodeSchool. I am the one who created (and still wish to create more) videos. The only problem is that I was doing mycodeschool full time earlier, but now I have taken a job and it's getting difficult to find time. But I want to get back. Hopefully, I will upload some videos soon. :)