Can we initialise i and j both with s and in the code first do swapping and then increment i?
PLease answer this
hello @garganshul151
it is upto u.
if u change i and j initialisation then u need to change ur implementation accordingly.
so make changes and try it . if it didnt work then ping me back along with ur source code
i want to ask—I got 2,1,4,6,7,5,8 after first recursion then while doing recursion at right,ie taking 8 as pivot how will the elements able sort because all are lesser than 8 so nothing will happen?
yeah because evrthing is lesser than 8.
we will only work for left part .
and right part will remain same i.e nothing will happen
but right part is not sorted yet,ie,6,7,5,8?How will it sort
we get pivot at 8 rigth.
so we will call quicksort to its left (6,7,5)
which will sort it.
u can use this visualizer -> https://www.hackerearth.com/practice/algorithms/sorting/quick-sort/visualize/
to understand the algorithm
i want to ask one thing in recursion i am not able to explain in chat…can i dm on whatsapp u?
u can ask here as well na.
what problem u r havng?
i am not getting int p=partition(a,s,e); //Left Part quickSort(a,s,p-1); //Right Part quickSort(a,p+1,e);its execution…that how will it execute when left part is sorted and right have to be sorted
Please reply to this
hey partition will segregrate our given array into two sections .
ie left section will contain all the elements which comes to left of partition and
right section will contain all the elements which comes to right of partition.
now we call the same quicksort function over this two section .
to sort them recursively.
if still not clear then pls refer this video by prateek bhaiya. he has explained its working.
try to watch this video and do a dry run over some test cases to understand it better
did both quicksort functions,ie for left part and right part will call simultaneously or first left part quicksort is called and it sorts the whole left part and then right part?
it depends on ur implementation.
if u r calling on left part first then it will get sorted first and then right part.
i am not asking that
i am not asking that i am asking that after first partition will my left part will sort to the fullest firstly or left and right simultaneously as in the code i have sent to u
first left one and then right one
i am not able to get the stack memory can u please send…it will be a grt help
i am not able to get the dry run in stack memory can u please send…it will be a grt help
i didnt get ur question.
what u want, do u want code or what?