A few viewers have pointed out an issue where a value would be out of order in some situations. A couple of commenters, Wilson Barbosa and Yebo Qin, identified what the issue was and implemented fixes and noted them in comments below. I've included Wilson's fix in the linked code, so now it should all be working properly. Let me know if anyone notices anything else though. Thanks so much to everyone who saw this and proposed fixes! This community is clearly awesome. Also, this is why code reviews are a great idea!
Prepping for a coding interview in Java and I’ve gotta say, your videos are the best and easiest to follow that I’ve come across. Keep up the good work
Just watched two of your videos … have taught gifted grade 12 CS for years … now switching from C/C++ to Java …have just watched a couple of your videos … your communication is exemplary…so clear …
Honestly the best tutorial on quicksort out there! I'd like to add: You don't have to use a number from the array as a pivot. You can calculate the median of the array and use that as the pivot, to queeze out even a little more performance.
@@TuanBuianonymous Count how many numbers you have. If you have an odd number, divide by 2 and round up to get the position of the median number. If you have an even number, divide by 2. Go to the number in that position and average it with the number in the next higher position to get the median.
@@quitchiboo in an unsorted array, the median could be any number, such as the highest or lowest number, so it does not make the algorithm that much better
as i found about this channel, when i search for programming related content, i pray that John made a video for that topic, and when he did, I got very happy.
Seeing you explain this with the visuals made this so much more understandable than watching my professor do it on a chalkboard! Thank you for this explanation and the sample code. Another great video John.
Thank you, it is helpful that you show how it is done on a text file and you are moving the numbers in the text boxes. it is good visualization of the process.
Thank you very much, John! I tried to find out working quicksort algorythm for Java, but the only one I found out has big bug. But thanks to you I won't be dropped out of my university))
I tried it myself and without leftPointer < rightPointer in the second loop you find that the array values are flipped, so the first one becomes the last and so on.
Dude, You are so good at explaining these things! Thank you for making these more complicated parts of coding easier to understand for a novice like me!
Thank you John, you have just taught me quick sort algorithm in a way that is clear and understandable. I enjoyed watching and learning from your videos.
thank you so much John! I was getting really frustrated with myself because I've watched 3 quicksort tutorials, and the last video the comments were like "if you dont get it, you dont get it." felt really defeated but now I think I understand!! im currently a software engineer in test but I'd like to prepare for my future possibly as a swe. one of the videos I watched was choosing a pivot randomly in the array which had me like 🥴but this makes a lot more sense to me! kind of reminds me of binary search.
great stuff! i really like your videos and the way you explain stuff!, i still had to rewatch this a second time to understand the code behind it, thank you!
I was having difficulty to understand the logic behind the implementation and your explanation it’s really great. There is just one thing that I do not fully understand that is why choose a random pivot it’s better than always take the last or first element.
As usual, easy way to understand. I just got out of the class and our professor said it better to use the median for choosing the pivot. while choosing the pivot would it better time complexity if we do (left+right /2).
This is great thanks! I've 4 years working experience but I'm studying for job interviews and I always find myself having to go back and learn DS&A stuff haha
When I watched this video for the first time, I was a bit hesitant to implement it this way. It was because of the nested "while" loops. It took some careful observation to understand that although there are inner while loops, we only go through the array once : O(n) Thanks for this clear explanation. 🙏🏽
Very well done video on quicksort with Java. I'm impressed with John as an instructor from this first video of his I watched. John explains things in a way that is easy to digest and comprehend. I came upon this one after a demo of quicksort in a Learn Haskell video. This review helped me better understand some of that foreign syntax in Haskell. I do have to say that Haskell does the quicksort in far fewer lines than Java.
Big thank you for sharing and teaching. I wish you much success with your channel and hope you continue producing more content. I look forward to your videos!
Excellent video and explanation. I just add that when facing a StackOverflowError in Java, you can adjust the -Xss parameter to the JVM when booting up, to a larger value. By default I think it's 1024KB but can be set to whatever value necessary.. Thank you for your content..
Your videos are educative and really fun to watch. Thanks for all the effort you put into the content!!! P.S. on 8:16 the rightPointer should point to the pivot element. However, your implementation was perfectly correct so this is not a big deal.
Thanks for that, I was implementing and had written the logic as int right = end -1; but in the John's implementation I saw it being as int right = end; // was a little confused here.
Thank you so much John, your videos are really a blessing to us. Its so easy to understand bcz of the visualization you make while explaining. thanks for your effort.
This explanation of the quicksort algo is the best i've seen so far on YT. Maybe i try to implement it in Cobol on our mainframe next week, just for fun :- )
Damn John. Im loving your videos man. You really clarify stuff which other tutors just ignore, that creates a lot of trouble. I actually would ask you if you could clarify the concept of returning. Plays a crucial role in coding and I miss the point of returning ometimes: "Does return close a program?" What is the point of returning is the return is void? " "Why do we have to return?" Thank for the great videos!
Damn. Your presentation is too smart. I really fall in love on your teaching approch. I knew how the quicksort works. But, couldn't able to make understand others properly how this sorting algorithm works. You demostrated these things nicely.
Wow that is so advanced and i understod, liked it. Thank you so much, hopfully one day would be able to create something like this after finishing my Study soon in 2 monthes
try median bucket sort, first find median, then split to two buckets O(n) for each pass, total sub-passes like a stable quick sort, always O(n log n) operations complexity
Great video, one of the best explanations of quicksort I've come across! It could've been better if at the end you compared quicksort with other sorting algorithms just to see the difference in the time it takes to sort arrays as they grow larger. Maybe you could do that in another video :)
Thank you great explanation as always. we can add a condition before swap of left and right in case they are the same to prevent additional operation if (left != right) swap (numbers, left, right). also 21:34, line 30 n 31 the swap should happen before the assignment of pivot variable. rn your pivot variable is alrdy assign to random pivotIndex, the swapping doesn't do any good.
Bro we need a lesson on selection sort, And another on comparision between selection and insertion sort, And lastly overall comparison between all other sorting algorithm (insertion, selection, bubble, quick, merge, heap) in terms of time, space complexity and when to use. Thanks bro
Awesome! The amount of memory Java allocates to the stack definitely matters, and with a lot of stack memory you can sort crazy amounts of numbers. The modest laptop that I use when recording probably doesn't give Java a ton to work with.
@@CodingWithJohn That's just what a modern gaming PC can do to help any CS student watching this channel. I tried implementing this in C++ however, and even though your implementation runs, "stack memory" gets corrupted. I also tried an implementation on an app that I downloaded ("Code Recipes Pro", available for iOS devices. The implementations for Java and Python work AWESOME on the latest versions of both languages.), and the allocator memory was corrupted. If you know of a channel that could possibly help, could you please reply with the UA-cam link for the corresponding video/channel? Thanks!
Revisiting my engineering days at the university. Felt nostalgic after hearing the terms Pivot, Left pointer, Right Pointer, and the easy-peasy Swap method and of course the Quick sort, the fastest sorting algorithm, while its poor siblings like Bubble sort, Merge sort, Heap Sort, and so on suck big time with their efficiency. Great job John. Keep up the good work and keep inspiring the needy.
*Excellent explanation.* Far better than my 7 books on Data Structures & Algorithms (yes, 7! I was a game programmer) including Sedgewick & Cormen’s. One thing though, _please_ consider using PasteBin or a link to a file as a source. That particular site is really finicky & picky with what it allows with what browser & doesn’t like mobile much at all.
Thank you so much for this (and all of your other vids). You truly have an extraordinary ability to explain difficult things in an understandable and nicely communicated way. I simply love your vids! Keep up the good work!
excellent. can you also give couple of minutes to discuss Time and Space complexity of such Algo problems in terms of big O please. I find your videos very useful and well explained along the way. Thank you.
A few viewers have pointed out an issue where a value would be out of order in some situations. A couple of commenters, Wilson Barbosa and Yebo Qin, identified what the issue was and implemented fixes and noted them in comments below.
I've included Wilson's fix in the linked code, so now it should all be working properly. Let me know if anyone notices anything else though.
Thanks so much to everyone who saw this and proposed fixes! This community is clearly awesome. Also, this is why code reviews are a great idea!
You're welcome, John! And keep up the good work!
no probs, you ve done a great job !
@@一颗星ykx which case is it? please give me example
@@TuanBuianonymous 15:49, line 43. There's an edge case. It's not absolutely the pivot will smaller than the left pointer.
@@duytuannguyen8323 thank you so much!
Prepping for a coding interview in Java and I’ve gotta say, your videos are the best and easiest to follow that I’ve come across. Keep up the good work
Hey, how was interview?
I hope you got a job
I agree!
Did you get the job?
I only knew quicksort is the fastest. Now I know how it works and how to code it. I also practiced recursion. Thank you very much.
It worths to mention that quicksort algoritm has in avarage O(nlog (n)) time complexity
Just watched two of your videos … have taught gifted grade 12 CS for years … now switching from C/C++ to Java …have just watched a couple of your videos … your communication is exemplary…so clear …
Well explained with the array visualization and the actual code creation process. Highly appreciate your time and efforts, John! Thank you so much!
Honestly the best tutorial on quicksort out there! I'd like to add: You don't have to use a number from the array as a pivot. You can calculate the median of the array and use that as the pivot, to queeze out even a little more performance.
how to calculate the median of the array?
@@TuanBuianonymous Count how many numbers you have. If you have an odd number, divide by 2 and round up to get the position of the median number. If you have an even number, divide by 2. Go to the number in that position and average it with the number in the next higher position to get the median.
@@quitchiboo in an unsorted array, the median could be any number, such as the highest or lowest number, so it does not make the algorithm that much better
as i found about this channel, when i search for programming related content, i pray that John made a video for that topic, and when he did, I got very happy.
Instant sub, no one breaks down theses concepts quite like you John. Glad a found this channel
I dont know how i can thank u.. It took me yrs and never understood quicksort .. With ur tutorials i understood everything clearly. Thanks man 🥰
Seeing you explain this with the visuals made this so much more understandable than watching my professor do it on a chalkboard! Thank you for this explanation and the sample code. Another great video John.
Thank you, it is helpful that you show how it is done on a text file and you are moving the numbers in the text boxes. it is good visualization of the process.
thank you, man. this is my fourth quick sort video and none of them are doing coding part. thank you, really.
The explaination using the numbers was amazing bro I literally understoop every single word.
BEST tutor about quicksort in universe!!!
Definitely the best there is. Talking about your content obviously. You’ve helped me so much I couldn’t possibly thank you enough Sir!
This is the best QuickSort Algo I have seen in UA-cam
This video will only 30k+ views explains the concept clearer than all other more popular videos, this guys deserves more subs!
This tutorials tips like over loading and eclipse method maker gave me so much joy
Hi John,
Your explanation was crystal clear + the last tweaks - the best quick sort tutorial on youtube right now.
Thank you very much, John! I tried to find out working quicksort algorythm for Java, but the only one I found out has big bug. But thanks to you I won't be dropped out of my university))
WOW, you have the talent of teacher. Thank you for making these videos.
thanks for all, btw in jdk library when it comes to sorting, it uses DualPivotQuicksort sorting algorithm
Thank you John, good job! in the second while loop, not need leftPointer < rightPointer, because the first while loop already have same code.
I tried it myself and without leftPointer < rightPointer in the second loop you find that the array values are flipped, so the first one becomes the last and so on.
I wasn't this clear of quick sort before watching this one.. It helped a lot. thank you!
Dude, You are so good at explaining these things! Thank you for making these more complicated parts of coding easier to understand for a novice like me!
Thank you John, you have just taught me quick sort algorithm in a way that is clear and understandable. I enjoyed watching and learning from your videos.
thank you so much John! I was getting really frustrated with myself because I've watched 3 quicksort tutorials, and the last video the comments were like "if you dont get it, you dont get it." felt really defeated but now I think I understand!! im currently a software engineer in test but I'd like to prepare for my future possibly as a swe. one of the videos I watched was choosing a pivot randomly in the array which had me like 🥴but this makes a lot more sense to me! kind of reminds me of binary search.
First time i actually understood this algorithm. thank you
Thank you for these videos, they're the clearest I've found so far! Hope you keep making more 😄👍
great stuff! i really like your videos and the way you explain stuff!, i still had to rewatch this a second time to understand the code behind it, thank you!
I was having difficulty to understand the logic behind the implementation and your explanation it’s really great. There is just one thing that I do not fully understand that is why choose a random pivot it’s better than always take the last or first element.
As usual, easy way to understand. I just got out of the class and our professor said it better to use the median for choosing the pivot. while choosing the pivot would it better time complexity if we do (left+right /2).
Thanks so much, John! I loved the way you explained QuickSort. 😍
This is great thanks! I've 4 years working experience but I'm studying for job interviews and I always find myself having to go back and learn DS&A stuff haha
This is honestly the best explanation on entire UA-cam!
Thanks John.
For me, added the following line
int pivotIndex = new Random().nextInt(highIndex - lowIndex) + lowIndex;
makes it less efficient.
When I watched this video for the first time, I was a bit hesitant to implement it this way. It was because of the nested "while" loops.
It took some careful observation to understand that although there are inner while loops, we only go through the array once : O(n)
Thanks for this clear explanation. 🙏🏽
You are a really good master, thanks i think this could took me weeks to understand it well, but you made it so easy !
Very well done video on quicksort with Java. I'm impressed with John as an instructor from this first video of his I watched. John explains things in a way that is easy to digest and comprehend. I came upon this one after a demo of quicksort in a Learn Haskell video. This review helped me better understand some of that foreign syntax in Haskell. I do have to say that Haskell does the quicksort in far fewer lines than Java.
Thank you sir, finally I could understand completely after watching 10 times 😂❤️
Thank you so much for this video! You've really helped me get a grapsp on the QuickSort algorithm other than my professors over here...
Big thank you for sharing and teaching. I wish you much success with your channel and hope you continue producing more content. I look forward to your videos!
Your teaching is brilliant John, thank you for sharing!
Excellent video and explanation. I just add that when facing a StackOverflowError in Java, you can adjust the -Xss parameter to the JVM when booting up, to a larger value. By default I think it's 1024KB but can be set to whatever value necessary.. Thank you for your content..
You have helped me get through University. I appreciate you so much! :)
pointing the pointers points a pointing image in my head :D thanks for the explanation, very useful.
Your videos are educative and really fun to watch. Thanks for all the effort you put into the content!!!
P.S. on 8:16 the rightPointer should point to the pivot element. However, your implementation was perfectly correct so this is not a big deal.
Thanks! And you're right, I suppose that is off by one between the implementation and the demo there. The end result should be the same either way.
Thanks for that, I was implementing and had written the logic as
int right = end -1;
but in the John's implementation I saw it being as
int right = end; // was a little confused here.
Thank you so much John, your videos are really a blessing to us. Its so easy to understand bcz of the visualization you make while explaining. thanks for your effort.
This explanation of the quicksort algo is the best i've seen so far on YT. Maybe i try to implement it in Cobol on our mainframe next week, just for fun :- )
You're literally the best, thank you! Eagerly looking forward for new videos from you🤓
Thank you for making us learn Java clearly and understand deeply😊
I really needed this for my Pokemon practice code project
I watched it last night, and I did it on my own this morning. I feel so powerful xD Although I know I could never come out with the solution on my own
Awesome!
Thank you for this explanation. thanks to you I understood brilliantly
The explanation was amazing. Thank you John
Another quality content on UA-cam. Thanks a lot.❤❤❤
Damn John. Im loving your videos man. You really clarify stuff which other tutors just ignore, that creates a lot of trouble. I actually would ask you if you could clarify the concept of returning. Plays a crucial role in coding and I miss the point of returning ometimes: "Does return close a program?" What is the point of returning is the return is void? " "Why do we have to return?" Thank for the great videos!
Damn. Your presentation is too smart. I really fall in love on your teaching approch. I knew how the quicksort works. But, couldn't able to make understand others properly how this sorting algorithm works. You demostrated these things nicely.
Wow that is so advanced and i understod, liked it. Thank you so much, hopfully one day would be able to create something like this after finishing my Study soon in 2 monthes
Yeah, that's a tutorial I was looking for!
Clear and understandable way!
Smooth and smart!
Thank you so much John. Best explanation I've ever seen.
try median bucket sort, first find median, then split to two buckets O(n) for each pass, total sub-passes like a stable quick sort, always O(n log n) operations complexity
I guess i found the best teacher for Java
Great video, one of the best explanations of quicksort I've come across!
It could've been better if at the end you compared quicksort with other sorting algorithms just to see the difference in the time it takes to sort arrays as they grow larger. Maybe you could do that in another video :)
Thank you great explanation as always. we can add a condition before swap of left and right in case they are the same to prevent additional operation
if (left != right) swap (numbers, left, right).
also 21:34, line 30 n 31 the swap should happen before the assignment of pivot variable. rn your pivot variable is alrdy assign to random pivotIndex, the swapping doesn't do any good.
Thank you john, I just need more clarification on time complexity
Needs a few re-watching lol Thanks John!
Wow, just amazing!! Thank you so much.
Bro we need a lesson on selection sort,
And another on comparision between selection and insertion sort,
And lastly overall comparison between all other sorting algorithm (insertion, selection, bubble, quick, merge, heap) in terms of time, space complexity and when to use.
Thanks bro
@Coding with John, You did a great job on this tutorial. Thank you very much.
Thank you so much John💚. What a great teacher you are 👏
My OMEN PC is able to sort 1 billion integers in Java!!! Wow!!! The thing's got some rapid power!
Awesome! The amount of memory Java allocates to the stack definitely matters, and with a lot of stack memory you can sort crazy amounts of numbers. The modest laptop that I use when recording probably doesn't give Java a ton to work with.
@@CodingWithJohn That's just what a modern gaming PC can do to help any CS student watching this channel.
I tried implementing this in C++ however, and even though your implementation runs, "stack memory" gets corrupted. I also tried an implementation on an app that I downloaded ("Code Recipes Pro", available for iOS devices. The implementations for Java and Python work AWESOME on the latest versions of both languages.), and the allocator memory was corrupted.
If you know of a channel that could possibly help, could you please reply with the UA-cam link for the corresponding video/channel? Thanks!
Nice, didn’t fall asleep in all 24mins.
Revisiting my engineering days at the university. Felt nostalgic after hearing the terms Pivot, Left pointer, Right Pointer, and the easy-peasy Swap method and of course the Quick sort, the fastest sorting algorithm, while its poor siblings like Bubble sort, Merge sort, Heap Sort, and so on suck big time with their efficiency. Great job John. Keep up the good work and keep inspiring the needy.
did you just call merge sort inefficient??
We're waitin for Heap Sort !! And thanks for your effort
Awesome explanation! really appreciate the time taken to make these videos.
*Excellent explanation.* Far better than my 7 books on Data Structures & Algorithms (yes, 7! I was a game programmer) including Sedgewick & Cormen’s.
One thing though, _please_ consider using PasteBin or a link to a file as a source. That particular site is really finicky & picky with what it allows with what browser & doesn’t like mobile much at all.
Thanks! Yeah I'm certainly not married to codepile for the sources. When I have some time I'll investigate other options.
your explanations are amazing
Thank you so very much for helping me understand the concept as well as the implementation
Also can we reduce one extra swap inside the while by surrounding it with an if condition which says that left pointer is not equal to right pointer
Your channel is true gem..
you also have drums behind you... thats awesome
Thank you John. Your explanation is very understandable...
Hey man, Data structures and algorithms will become an interesting topic if everyone teaches like you.👍👍
very understandable! you are amazing tutor! keep doing such a wonderful video!
Thanks alot. My request was answered.
Best ever,! Thank you so much for sharing this!
The best quick sort tutorial
Thank you so much for this (and all of your other vids). You truly have an extraordinary ability to explain difficult things in an understandable and nicely communicated way.
I simply love your vids! Keep up the good work!
Thanks for the very kind words!
excellent. can you also give couple of minutes to discuss Time and Space complexity of such Algo problems in terms of big O please. I find your videos very useful and well explained along the way. Thank you.
There are great lectures on MIT open courseware, that also cover quicksort's complexity along many others. Check them out. :)
Oh man you are amazing. Clear explanation. You have rightfully earned a sub sir.
Thank you very, very much for your videos, they are very helpful for me. You are doing a great Job. ♥♥♥
Very easy and clear explaination! Thank you so much.
Was waiting for this ❤
Me too. I'd recently watched the merge sort video and wanted a quicksort to compare it with.
You're amazing John, i am your new subscriber! I'm enjoying your content
I have only one word for you sir, Greaaat
Really like your channel! Keep going, your are the best!🏆🏆🏆👍
Wish I had found this channel earlier. Great explanation once again, thanks!
agreed 100%
You are too good. Wonderful explanation. Thank you tons.