Java Quick Sort

[ad_1]
Get the Code Here:

Welcome to my Java Quick Sort tutorial! In most situations the Quick Sort is the fastest sorting algorithm.

In essence, the quick sort works by partitioning arrays so that the smaller numbers are on the left and the larger are on the right. I’ll cover what partitioning is in this video.

The Quick Sort then recursively sends small parts of larger arrays to itself and partitions again. Between the code and the video you will completely get it in the end.


Posted

in

by

Tags:

Comments

41 responses to “Java Quick Sort”

  1. kadju Avatar

    Hey Derek,
    What is the meaning of the semicolon inside the while loop?

  2. Alka Nath Avatar

    What happens if you have an odd number of values that are less than your pivot and an even number of values that are greater than your pivot? Do you not switch that last one because there isn't anything to switch it with?

  3. Merga Tafa Avatar

    too fast for beginner

  4. Merga Tafa Avatar

    He is smart but too fast beginner

  5. CaptinDread Avatar

    15:50, Why do you swapValues(leftPointer, right) here? I don't understand where this is coming from.

  6. TheresaShen3397 Avatar

    Can anyone please explain why 53 is still at the left side of pivot 30? @1:13

  7. Ferch Avalos Avatar

    It's very easy to understand this algorithm, but is hard to implement it. However, good video!

  8. nishant bali Avatar

    referring to last 2 mins of video, you swapped 45 with 40 which is not true.
    can you please explain why 45 was swapped by 40. As per me it should be swapped by 39

  9. devang bharad Avatar

    very fast your english is like blablabla not properly understand

  10. Crystal Wang Avatar

    its not the speed , its just not very clear

  11. Nicolas Melia Avatar

    Hey Derek, great tutorial! Did you happen to cover merge sort? I can't seem to find it. Thanks!

  12. Parth Pandit Avatar

    Hi Derek,

    Could you please explain what is the meaning of below code line and how this pivot value from the left is being used in this code? I could not find any relation between this code line and the actual code!

    System.out.println("Value in left " + theArray[left]
    + " is made the pivot");

  13. csanchezcuba Avatar

    Great tutorial, I am currently preparing ahead for my Data Structures class, and have to say that your video helped me to understand this algorithm very well.
    I wanted to ask, whats the difference between your algorithm and other algorithms that use another method to create partitions?
    Also, I see that some implementations of Quicksort differ when it comes to selecting the pivot. Can you explain whats the best choice for pivot in general?

  14. Olive Grace Lagrosa Avatar

    Hi Derek, just wanna ask, can i simulate these codes that u gave? so i can learn it more, but i can't because i don't know the meaning of other lines..

  15. Josef Little Avatar

    Wouldn't it also be correct to call qSort as qSort(i,m);
    qSort(m+1,j); ?
    Where i = 0 and j = array.length?

  16. Guilherme Alves Silveira Avatar

    It would be cool to teach java nio and java aio! great channel and thank you!

  17. Deep Patel Avatar

    @9:27 you said how nothing changes because according to the new pivot 19, there are no changes but right under you moved the 21 and 52 (swapped them) why ?

  18. Bobby Shelley Avatar

    can you do a partitioning using the middle of three technique

  19. Clarisse Simões Ribeiro Avatar

    I like your videos a lot but this one got a little confusing.
    I can't tell how you choose the pivot and every time left and right pointers meet each other, i don't understand their positions in the next figure of the array. Can you go deeper in these?
    Thanks very much, your classes are awesome!

  20. Brian Seo Avatar

    difficult to understand how the values are swapping and how the pointers are moving in the videos. Maybe add some animations?

  21. Dat Huy Richard Le Avatar

    cannot stand your intonation when you explain. FINISH THE SENTENCES. It seems like it's a single sentence going on forever

  22. spacepod100 Avatar

    this and insertion sort KO'd me ;(

  23. tomhijkl Avatar

    Hey Derek, can you tell me why does this algorithm not work if you take the left array element as the pivot?

  24. ARJUNCEC Avatar

    I hope there is some issue with the partitioning logic. 
    I gave the input [51, 11, 12, 13, 21, 14, 50, 35, 37, 35]. The pivot value selected is 35. 
    The output array is [35, 11, 12, 13, 21, 14, 35, 50, 37, 51] which is not expected.

  25. Tamir Offen Avatar

    I think you should have explained your code more, telling us to just swap leftPointer and right with out way you did so left me more confused then when i came here. I think that this tutorial is only good for the people who want to get the overall idea but not understand most of what goes on.

  26. muhammad Ahsan Avatar

    can somebody explain this part to me. I don't understand why leftPointer is swapping with right.
    swapValues(leftPointer, right);

  27. kiran kumar Avatar

    Hi, when is try to run the code explained by you, it gives an error "Could not find or load main class". Also on the 10th line we have a warning "The public type Partitioning must be defined in its own file"…. Could you please check and help me once with this explanation.

  28. sripriya nagaraju Avatar

    sir plz provide java frameworks as struts , spring,hibernate and also another example of mvc

  29. Trollacaust Avatar

    Thank you so much for the help. hopefully il find more videos by you that are the topics of my logbook. thanks

  30. Cheaper Avatar

    Hey Derek! In my class, we are currently learning linked-list (made manually, as in no importing linked list). I've finally got that complete, however, our professor would like for us to have the linked list printed in a sorted manner. He would like for it to sort as you enter data. For example, I add the number '3', then I say to add another node. If I enter '1', the '1' node will be moved before the '3' node. How would you do this? Could you possibly make a video tutorial, or would you be able to help me via comments if I supplied my source code?

    Thank you!

  31. Mummie560 Avatar

    How are you supposed to memorize all this??

  32. kaktusztea Avatar

    @GreenCheese500:
    I think these "while" sections are stepping leftPointer or rightPointer to the next position where they can be used for swapping.
    I.e the first "while" section does nothing just make leftPointer step to the position where it's pointed value in array is less than pivot value.
    Then the "while" exists and the program goes to the next statement.

  33. __dxmole__ Avatar

    Wow. thanks. This helps those like me who are more visual learners.

  34. blizzmademegod Avatar

    Thanks for the video.

  35. Hadi hadi halim Avatar

    May you have a good life

  36. Sushil Avatar

    I didn't get the the line 19 and line 26 at time: 5:01 :
    while(leftpointer<(arraysize-1) && theArray[++leftpointer]<pivot) ;
    while(rightpointer>0) && the Array[–rightPointer]>pivot);

    you are using two While loops but both of them don't have " { } " and code in between them.
    I would like to know how they are working. Could you please explain how they are working? 
    Thanks 🙂

  37. San Shinetuts Avatar

    Why make a variable ArraySize when you can use Array.length ?

  38. adarsh atluri Avatar

    your explanation was very clear until minute 10:00 when 21 was finished as the pivot and then you used 19 as the pivit and 52 which was at the 4th position was suddenly placed at the end of the array. That really threw me for a loop. I did some reading up and figured it out. This link helped me https://ece.uwaterloo.ca/~cmoreno/ece250/quick-sort-complete-example.pdf 
    Other than that very nice tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *