Let's march ahead, and create an unmatchable DSA course! ❤ The worst case complexity will be O(N ^ 2) if we end up choosing the largest or smallest element as the pivot always. We will add this in the notes in the description. I missed this in the video.
Since, we are always choosing pivot to be the first element of the array, we can always avoid the O(n^2) case by pre-checking if the array is pre-sorted (with O(n) Time Complexity) and if it is not then only feed it into the quick sort function.
I have to state it that "I tried to learn all sorting techniques various time. I learned but after a few days I forgot. But when you just added the real meaning of each sorting techniques. Like why it is called as selection sort and so on.... SO now I just remember their meanings and write the algorithm on my own." Thank you very much. Loved your teaching style
Quick Sort's in-place partitioning makes it more memory-efficient than Merge Sort in practice, but the worst-case space complexity can be higher when the partitioning is unbalanced. Time Complexity: Best Case: O(n log n) when the pivot choices consistently lead to balanced partitions. Average Case: O(n log n) Worst Case: O(n^2) when the pivot choices consistently lead to unbalanced partitions. However, with good pivot selection strategies (e.g., using the median element), this can be mitigated. Space Complexity: O(log n) auxiliary space for the recursive call stack in the best and average cases. O(n) in the worst case when the partitioning is highly unbalanced. Quick Sort's in-place partitioning makes it more memory-efficient than Merge Sort in practice, but the worst-case space complexity can be higher when the partitioning is unbalanced. Quick Sort tends to perform well in practice and is often faster than other O(n log n) algorithms, but its worst-case time complexity is worse than Merge Sort. Merge Sort's space complexity makes it less memory-efficient compared to some other sorting algorithms, but its stable performance and guaranteed O(n log n) time complexity in all cases make it a preferred choice for certain scenarios. Space Complexity: O(n) additional space is required for the temporary arrays during the merging process. It has a space complexity of O(n) due to the need for additional space for merging.
Damn, I have been looking at sort, recursion, etc forever. I was first confronted with merge/quicksort back in 2019. Been looking at them from various other sources over the years but nobody ever explained it like you do. You are absolutely amazing at this stuff. Idk where you are in life but I hope you go onto make amazing things because someone with this in depth knowledge shouldn't be stuck teaching!
please upload full course you are douing a good job bhaiyaaa ,you are really a honest teacher other youtubers who has million subscribers just make us fool on name of dsa course ,they just tell the problem and paste the soultion but you solve every aspect -f our doubt please cpmplete this and dont worry of views and watch time,time will come when everyone will know who is the best teacher on youtube for dsa
When I try to run this code(using array), I getting no output and the code runs for infinite time. When I try with ArrayList, I am getting output. Explain why? This put me into severe headache
@@DineshKumar-pw7qb Heyy!! You mean my code? Either way, can you send me the code you are working on. I want to try it. How about that? Maybe we can fix it together?
@@DineshKumar-pw7qb Hey, mate! I copied my code, and yes it works with arrays. It doesn't give me errors or infinite loops, but... this line: while(arr[i] > pivot && i < high) I missed the =. I am so sorry. I should be: while(arr[i] >= pivot && i < high) Check it out now. But as I understand, the problem with your code is the array itself, yes? Not the output? If you want you can send the code. Because mine works well with array. P.S.: I will edit the original comment, and put the equal.
Excellent explanation as usual. Thank you. I am posting the iterative version which should further save on recursion call stack space. I have used a queue as the data structure but stack works just as well. void quickSort (vector &nums) { int n = nums.size(); queue q; q.push({0, n-1}); int low, high, pivot, i, j; while(!q.empty()) { low = q.front().first; high = q.front().second; q.pop(); if (low >= high) continue; pivot = nums[low]; i = low; j = high; while (j > i) { while (nums[i] pivot && j > 0) j--; if (j >= i) swap(nums[i], nums[j]); } swap (nums[low], nums[j]); q.push({low, j-1}); q.push({j+1, high}); } }
So Yah u tried the iterative version of Quick Sort but still you are using the space what the Recursive func calls use in func call stack in the QUEUE FORM. O(logN) Queue takes as extra space. Like the point is Quick sort no matter what -> You can further optimize. Func Stk Space or in Iterative normal stack or queue space is needed. As we need to store it somewhere -> what are the next range of places where it is unsorted. Either use the system's func call stack or make ur own.
#Free Education For All...... # Bhishma Pitamah of DSA...You could have earned in lacs by putting it as paid couses on udamey or any other elaerning portals, but you decided to make it free...it requires a greate sacrifice and a feeling of giving back to community, there might be very few peope in world who does this...."विद्या का दान ही सर्वोत्तम दान होता है" Hats Off to you man, Salute from 10+ yrs exp guy from BLR, India.......
For Descennding Order Sorting -> //Just Reverse the inequality sign in partition function :- #include int partition(vector&arr,int low,int high){ int pivot =arr[low]; int i=low ,j=high; while(i
Damn it, i have learnt sorting algorithms a lot of times, but i aways manage to somehow forget.But after seeing this video now i understand it in so much more detail and depth which i earlier didn't even notice. thanks you soo much striver !
Understood sir. For descending order: int partitionFunction(int arr[], int low, int high){ int i = low, j = high, temp; int pivot = arr[low]; while(ipivot and i
// for descending order just we have to do the tweaks in the how we are selecting elements when which we are stopping when we are finding element smaller in left and stop when we find the element greater the pivot then we just we swap it than it goes in the recursion stack public class Quicksort { static int partiton(int arr [] , int low , int high ){ int pivot = arr[low]; int i= low; int j = high; while (i < j ) { while (arr[i] >= pivot && i = low + 1 ) { j--; } if(i < j ){ int temp = arr[i]; arr[i] = arr [j]; arr[j] = temp; } } int temp = arr[j]; arr[j] = arr[low]; arr[low] = temp; return j ; } static void quicksort(int arr [] , int low , int high){ if(low < high ){ int PartionIndex = partiton(arr,low,high) ;
Its a great video, but you should also explain the cases where complexity for quick sort can result to O(n^2) in the case where all elements of array are same and when array is already sorted, in those cases partition will always be 1, n-1.
by the way, there exist some examples where the code shown can return in out of vector subscript error because the partition index might be returned as 0 and when we try to access pIndex-1 it will of course crash. so put an extra little check where the code just returns if pIndex is 0.
Wonderful Explanation!! Notes include the space complexity as O(1)+O(N) auxiliary stack space. Is it the worst case space complexity? And is the best and average case auxiliary space complexity O(logN)?
Quick sort in Descending order in Python: def qS(array): if len(array) pivot] return qS(elm_grater_than_pivot) + elm_equal_pivot + qS(elm_less_than_pivot)
public: // Function to sort an array using quick sort algorithm in descending order. void quickSort(int arr[], int low, int high) { if (low < high) { int pIndex = partition(arr, low, high); quickSort(arr, low, pIndex - 1); quickSort(arr, pIndex + 1, high); } } public: int partition(int arr[], int low, int high) { int pivot = arr[low]; int i = low; int j = high; int temp; while (i < j) { while (arr[i] >= pivot && i = low + 1) { j--; } if (i < j) { temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } temp = arr[low]; arr[low] = arr[j]; arr[j] = temp; return j; } }
I will recommend you to take examples and do a dry run, that will help you immensely to learn! I can answer, but finding out yourself on pen and paper is what will help you grow :)
@@elizabethr5161 No it will matter because you want the swapping to occur between the elements of the array. With what you are saying, the j-th position will get the correct value, but 'low' position will not have been swapped. The swapping needs to occur in the array. You are getting confused as the values being swapped are effectively the same, but where the swap occurs is not the same.
pivot is just some another independent variable having same value as arr[low], swapping with pivot means swapping values with an independent variable, we want swapping with the array's low itself so we explicitly use arr[low] here.
Let's march ahead, and create an unmatchable DSA course! ❤
The worst case complexity will be O(N ^ 2) if we end up choosing the largest or smallest element as the pivot always. We will add this in the notes in the description. I missed this in the video.
Yes striver , even i was thinking same that you didn't explain this thing , btw thankyou so much for this much crystal clear explaination ..
Hi striver @takeUforward ,
when are you going to release video solutions for string type problems and heaps?
There is a minor mistake in your algo at 23:54 in while loop condition must be arr[i]
Since, we are always choosing pivot to be the first element of the array, we can always avoid the O(n^2) case by pre-checking if the array is pre-sorted (with O(n) Time Complexity) and if it is not then only feed it into the quick sort function.
I have to state it that "I tried to learn all sorting techniques various time. I learned but after a few days I forgot. But when you just added the real meaning of each sorting techniques. Like why it is called as selection sort and so on.... SO now I just remember their meanings and write the algorithm on my own." Thank you very much. Loved your teaching style
same here
same heree
same here
Same
Not same 😢
I tried to learn this from every yt channel but striver is the one i got it from, respect++
then you haven't tried Abdul Bari
@@navagharkiran5769 sadly I did, its not that abdul bari is not good, its me who is dumb uk but striver made me understand it anyhow
@@navagharkiran5769 abdul bari is better for college academics but striver is for campus selections
//for descending
while (arr[i]>=pivot && i
yes i am thinking about this mistake ..thank you
Probably one of the crisp and to the point explanation of quick sort algorithm available online!!
Quick Sort's in-place partitioning makes it more memory-efficient than Merge Sort in practice, but the worst-case space complexity can be higher when the partitioning is unbalanced.
Time Complexity:
Best Case: O(n log n) when the pivot choices consistently lead to balanced partitions.
Average Case: O(n log n)
Worst Case: O(n^2) when the pivot choices consistently lead to unbalanced partitions. However, with good pivot selection strategies (e.g., using the median element), this can be mitigated.
Space Complexity:
O(log n) auxiliary space for the recursive call stack in the best and average cases.
O(n) in the worst case when the partitioning is highly unbalanced.
Quick Sort's in-place partitioning makes it more memory-efficient than Merge Sort in practice, but the worst-case space complexity can be higher when the partitioning is unbalanced.
Quick Sort tends to perform well in practice and is often faster than other O(n log n) algorithms, but its worst-case time complexity is worse than Merge Sort.
Merge Sort's space complexity makes it less memory-efficient compared to some other sorting algorithms, but its stable performance and guaranteed O(n log n) time complexity in all cases make it a preferred choice for certain scenarios.
Space Complexity:
O(n) additional space is required for the temporary arrays during the merging process.
It has a space complexity of O(n) due to the need for additional space for merging.
Appreciate the effort you put for writing this comment 😇❤
Thanks for the comment. i was looking for it.
Hey can you give me the code for pivot = median element pls??
@@dreamer12nwhat kind of code do you want
@@dreamer12nJust set pivot = (low + high)/ 2 or in a better way to deal with larger numbers make it low +(high -low)/2
Thanks for this amazing lecture,this is my humble request please complete this course as soon as possible.
Really you make everything a cakewalk!
Thank you so much sir, it takes a big heart to do such a lot for the community for free❤
Damn, I have been looking at sort, recursion, etc forever. I was first confronted with merge/quicksort back in 2019. Been looking at them from various other sources over the years but nobody ever explained it like you do. You are absolutely amazing at this stuff. Idk where you are in life but I hope you go onto make amazing things because someone with this in depth knowledge shouldn't be stuck teaching!
Don't worry he is working at Google. Doing great in life :)
Understood!
Thank you!! You are the best!
Thanks a lot for making this DSA playlist! It really is helping me a lot!
1 video every 2 days...
Seems TRUE ❣️
please upload full course you are douing a good job bhaiyaaa ,you are really a honest teacher other youtubers who has million subscribers just make us fool on name of dsa course ,they just tell the problem and paste the soultion but you solve every aspect -f our doubt please cpmplete this and dont worry of views and watch time,time will come when everyone will know who is the best teacher on youtube for dsa
how do you know which doubts are going to come in my mind. GREAT LECTURE SIR 🔥
Because once he was also in the same place as we are now and he worked hard to reach this point now he is helping us
A great man with the best of the best teaching skills and a kind attitude to make it free is awesome ❤
CODE FOR DESCENDING (JAVA):
public void quickSort(int[] arr, int low, int high){
if(low low){
j--;
}
if(i
When I try to run this code(using array), I getting no output and the code runs for infinite time. When I try with ArrayList, I am getting output.
Explain why? This put me into severe headache
@@DineshKumar-pw7qb Heyy!! You mean my code?
Either way, can you send me the code you are working on. I want to try it. How about that? Maybe we can fix it together?
@@tasneemayham974bro are sure about your code is working well with array?
@@DineshKumar-pw7qb Hey, mate! I copied my code, and yes it works with arrays. It doesn't give me errors or infinite loops, but...
this line:
while(arr[i] > pivot && i < high)
I missed the =. I am so sorry. I should be:
while(arr[i] >= pivot && i < high)
Check it out now. But as I understand, the problem with your code is the array itself, yes? Not the output? If you want you can send the code. Because mine works well with array.
P.S.: I will edit the original comment, and put the equal.
This is gold... Plz keep doing this..
Excellent explanation as usual. Thank you.
I am posting the iterative version which should further save on recursion call stack space. I have used a queue as the data structure but stack works just as well.
void quickSort (vector &nums)
{
int n = nums.size();
queue q;
q.push({0, n-1});
int low, high, pivot, i, j;
while(!q.empty())
{
low = q.front().first;
high = q.front().second;
q.pop();
if (low >= high) continue;
pivot = nums[low];
i = low; j = high;
while (j > i)
{
while (nums[i] pivot && j > 0)
j--;
if (j >= i)
swap(nums[i], nums[j]);
}
swap (nums[low], nums[j]);
q.push({low, j-1});
q.push({j+1, high});
}
}
So Yah u tried the iterative version of Quick Sort but still you are using the space what the Recursive func calls use in func call stack in the QUEUE FORM. O(logN) Queue takes as extra space.
Like the point is Quick sort no matter what -> You can further optimize. Func Stk Space or in Iterative normal stack or queue space is needed.
As we need to store it somewhere -> what are the next range of places where it is unsorted.
Either use the system's func call stack or make ur own.
striver you are the best out of best....this tutorial is just amazing and you are like god for us A big thank you so much for your effort 🙂
hence proved , Striver is GOAT.
it's very understandable way you teach. thank you for this amazing lecture
Quick sort in Descending order-(PYTHON)
arr=[25,1,8,7,32,2,5]
def piviot(arr,high,low):
piviot=arr[high]
i=high
j=low
while(i=piviot and i
Hey I haven't done a dryrun of your code but as i has index of high how can in increment in the while loop?
yes make sense and have to chnage the while (i
shouldn't it be while(i > j) ?
Understood.... 💯💯 Excited for Arrays playlist❤
Here is my Assignment question solution :
#include
using namespace std;
int partition(vector &arr, int low, int high){
int pivot = arr[low];
int i = low;
int j = high;
while(i < j){
while(arr[i] >= pivot && i = low + 1) j--;
if(i < j) swap(arr[i], arr[j]);
}
swap(arr[low], arr[j]);
return j;
}
void qs(vector& arr, int low, int high){
if(low < high){
int pIndex = partition(arr, low, high);
qs(arr, low, pIndex - 1);
qs(arr, pIndex + 1, high);
}
}
int main(void){
// vector v = {4, 3, 2, 1};
vector v = {4, 3, 2, 1, 4, 7, 5, 6};
int n = v.size();
qs(v, 0, n-1);
for(auto it : v) cout
at time 23:52 it should be pivot not ar[pivot] thanks bhaiya
Yes bro.👊 😊
bro you are a true saviour !!
Thanks a lot for Quick Short. Feels easier to understand 🥰
best explanation of quick sort on youtube
Understood, will be a quick way to remember the algorithm, well taught!! Thanks
Manhhhh 🥵, you are awesome. I can see the effort you are putting in! Thanks a lot! ❤
Thanks for recursive effort brother.And till now all your lectures are absolutely awesome 🔥🔥
Excellent content about DSA .I am follwing you A-Z coarse and improve my self in DSA day by DSA Thanks for making such a amazing content
for the assigment problem just change the condition while (i < j) {
while (arr[i] > pivot && i
Best explanation ever ❤️❤️❤️
Thanks bhaiya
Thank You anna because of u I have learned something new today🙂
Kaha se sikha hai aise padana?
vai koi vi nahi hai tumhare jaisa.
Maza aa gaya
#Free Education For All...... # Bhishma Pitamah of DSA...You could have earned in lacs by putting it as paid couses on udamey or any other elaerning portals, but you decided to make it free...it requires a greate sacrifice and a feeling of giving back to community, there might be very few peope in world who does this...."विद्या का दान ही सर्वोत्तम दान होता है" Hats Off to you man, Salute from 10+ yrs exp guy from BLR, India.......
u r just amazing. keep educating man u r blessing for us.❤
love from pakistan we need these type of legend to teach progamming
Your explanations are the best 💕👌👌
Thanks for giving this content for free it helps me a lot
For Descennding Order Sorting ->
//Just Reverse the inequality sign in partition function :-
#include
int partition(vector&arr,int low,int high){
int pivot =arr[low];
int i=low ,j=high;
while(i
Understanding everything u r teaching to us u r magician striver
for decreasing Quick Sort:-
int partition(vector &arr, int low, int high) {
int pivot = arr[low];
int i = low;
int j = high;
while (i < j) {
while (arr[i] >= pivot && i = low + 1) {
j--;
}
if (i < j) {
swap(arr[i], arr[j]);
}
}
swap(arr[low], arr[j]);
return j;
}
void quickSort(vector &arr, int low, int high) {
if (low < high) {
int pIndex = partition(arr, low, high);
quickSort(arr, low, pIndex - 1);
quickSort(arr, pIndex + 1, high);
}
}
vector sortArray(vector &arr) {
quickSort(arr, 0, arr.size() - 1);
return arr;
}
understood Bhayya.The best explanation in youtube😎
Damn it, i have learnt sorting algorithms a lot of times, but i aways manage to somehow forget.But after seeing this video now i understand it in so much more detail and depth which i earlier didn't even notice. thanks you soo much striver !
Understood sir.
For descending order:
int partitionFunction(int arr[], int low, int high){
int i = low, j = high, temp;
int pivot = arr[low];
while(ipivot and i
Why can't we give while (i
awesom explanation , love it learning DSA .
Why we are using while (i
Understood! Super amazing explanation as always, thank you very much!!
Can't thank you more. Great lectures. Appreciate it.
checking for out of bounds like this makes it simple and natural
while (i pivot) {
j--;
}
16 Aug 2024, 2:00 a.m.🎯🔥
26:58 That will be |1 3 2| 4. Right?
// for descending order
just we have to do the tweaks in the how we are selecting elements when which we are stopping when we are finding element smaller in left and stop when we find the element greater the pivot then we just we swap it
than it goes in the recursion stack
public class Quicksort {
static int partiton(int arr [] , int low , int high ){
int pivot = arr[low];
int i= low;
int j = high;
while (i < j ) {
while (arr[i] >= pivot && i = low + 1 ) {
j--;
}
if(i < j ){
int temp = arr[i];
arr[i] = arr [j];
arr[j] = temp;
}
}
int temp = arr[j];
arr[j] = arr[low];
arr[low] = temp;
return j ;
}
static void quicksort(int arr [] , int low , int high){
if(low < high ){
int PartionIndex = partiton(arr,low,high) ;
quicksort(arr, low , PartionIndex-1);
quicksort(arr, PartionIndex+1 , high);
}
}
public static void main(String[] args) {
int arr [] = {10, 80, 30, 90, 40};
int n = arr.length-1;
quicksort(arr, 0, n);
for (int i : arr) {
System.out.print(i + " ");
}
}
}
Instead of 3,2,1 it should be 1,3,2 coz we have done swapping b/w 4 & 1 like swap(arr[low], arr[j]) right ?
Crystal clear bhaiya 😍
int partition (int arr[], int low, int high)
{
int p=arr[low];
int i=low,j=high;
while(i=p && i
I also completed 2 steps can we connect?
Awesome explaintion ❤
Best , Detailed and Crisp
very well explained brother appreciate your efforts
Why not
ilow
Can anyone explain why striver doesn't take these ??
Understood,Thanks striver for this amazing video.
Excellent explanation :)
Understood sir.....u r the best👍💞
Thanks Striver :)
Its a great video, but you should also explain the cases where complexity for quick sort can result to O(n^2) in the case where all elements of array are same and when array is already sorted, in those cases partition will always be 1, n-1.
sorted or even if sorted in descending order complexity will be n^2
Was eagerly waiting for your videos 🙌
by the way, there exist some examples where the code shown can return in out of vector subscript error because the partition index might be returned as 0 and when we try to access pIndex-1 it will of course crash. so put an extra little check where the code just returns if pIndex is 0.
Wonderful Explanation!!
Notes include the space complexity as O(1)+O(N) auxiliary stack space. Is it the worst case space complexity? And is the best and average case auxiliary space complexity O(logN)?
Code for descending order :-
#include
int fn(vector &arr,int low, int high){
int pivot = arr[low];
int i = low;
int j = high;
while(i=pivot && i
Awesome explanation! TYSM for the videos
Quick Sort in Descending Order (C++):
int partitionArray(int input[], int start, int end) {
int pivot = input[start];
int i = start;
int j = end;
while (i < j) {
while (input[i] >= pivot && i < end) {
i++;
}
while (input[j] < pivot && j > start) {
j--;
}
if (i < j) {
int temp = input[i];
input[i] = input[j];
input[j] = temp;
}
}
input[start] = input[j];
input[j] = pivot;
return j;
}
void quickSort(int input[], int start, int end) {
if (start >= end) return;
int partition = partitionArray(input, start, end);
quickSort(input, start, partition - 1);
quickSort(input, partition + 1, end);
}
You rocks the DSA
bro is the angel!
Quicksort in python.
def partition(L,lower,upper):
i=lower
pivot=L[lower]
for j in range(lower+1,upper+1):
if(L[j]
understood everything sir so far all sorting techniques
Quick sort in Descending order in Python:
def qS(array):
if len(array) pivot]
return qS(elm_grater_than_pivot) + elm_equal_pivot + qS(elm_less_than_pivot)
Thanks striver this video helped me ❤
Understood
Striver on TOP!
us!!
please add it in the same playlist as that will be more organised .
❣❣
Understood bhaiya! Thank you
Is recursive stack space not required while computing space somplexity?
23:27 why i
// condition i
Yes you are right, it should evaluate this first as a precaution.
Completely Understood 👍👍
nice way of explaination
public:
// Function to sort an array using quick sort algorithm in descending order.
void quickSort(int arr[], int low, int high)
{
if (low < high) {
int pIndex = partition(arr, low, high);
quickSort(arr, low, pIndex - 1);
quickSort(arr, pIndex + 1, high);
}
}
public:
int partition(int arr[], int low, int high)
{
int pivot = arr[low];
int i = low;
int j = high;
int temp;
while (i < j) {
while (arr[i] >= pivot && i = low + 1) {
j--;
}
if (i < j) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
temp = arr[low];
arr[low] = arr[j];
arr[j] = temp;
return j;
}
}
After checking all lectures on internet...None has explained better than you
Should be include stack space in recursion problems while stating space complexity ?
After long time ❤️❤️
Step-2 completed! Understood
Understood 😄. But will you please explain why we swapped between (arr[j] , arr[low]) instead of (arr[j], pivot)?
I will recommend you to take examples and do a dry run, that will help you immensely to learn! I can answer, but finding out yourself on pen and paper is what will help you grow :)
@@takeUforward Thank you. I will surely do as suggested 😄.
We have taken low as a pivot, so it doesn't matter whether we swap it with low or pivot.
@@elizabethr5161 No it will matter because you want the swapping to occur between the elements of the array. With what you are saying, the j-th position will get the correct value, but 'low' position will not have been swapped. The swapping needs to occur in the array. You are getting confused as the values being swapped are effectively the same, but where the swap occurs is not the same.
pivot is just some another independent variable having same value as arr[low], swapping with pivot means swapping values with an independent variable, we want swapping with the array's low itself so we explicitly use arr[low] here.
Thank you so much sir for this content. Very good explanation
for descending order
const partition = (arr, low, high) => {
let pivot = arr[low];
let i = low;
let j = high;
while (i < j) {
while (arr[i] >= pivot && i < high) {
i++;
}
while (arr[j] low) {
j--;
}
if (i < j) {
let temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
let temp = arr[low];
arr[low] = arr[j];
arr[j] = temp;
return j
};
const quickSort = (arr, low, high) => {
if (low < high) {
let partitionIndex = partition(arr, low, high);
quickSort(arr, low, partitionIndex - 1, high);
quickSort(arr, partitionIndex + 1, high);
}
console.log(arr)
};
Why do we ignore recursion stack space when calculating Space Complexity? I think that should count.
Thank you bhaiya. Amazing explanation ❤
//Code for reversing the sorted array using quick sort
// feel free to review
class ReverseSortedArray {
public static void main(String[] args) {
int[] arr = {1,3,5,2,7,6,8,10};
Qsort(arr,0,arr.length - 1);
for(int i :arr){
System.out.print(i + " ");
}
}
public static void Qsort(int[] arr,int low,int high){
if(low < high){
int partition = parrtitionArrray(arr,low,high);
Qsort(arr,low,partition - 1);
Qsort(arr,partition + 1,high);
}
}
static int parrtitionArrray(int[] arr,int low,int high){
int val = arr[low];
int i = low,j = high;
while(i < j){
while(val = low - 1){
j--;
}
if(i < j){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
int temp = arr[low];
arr[low] = arr[j];
arr[j] = temp;
return j;
}
}
thank you so muchbhiaya for this masterpiece
understand bhaiya !!!
thank uh so much
yes all looks deep and good but recursion is tricky if we do 1 condition wrong very difficult to get it. In iterative its quite easy to get all.
tusi great ho
tofa Kabul karo.