Untitled
QuickSort (ascending order) : (Striver logic) 1. pick pivot - can be 1st ele , last ele or median or random element Gold standard -- pick 1st element 2. U place the pivot at its sorted position while at the same time u place all the elements lesser than pivot on the left of the sorted pos & all elements greater than or equal to pivot on right of the sorted pos of the pivot. U do this in place , Use low & high pointer. u do inward 2 pointer approach , i = arr[low] & j = arr[high] while(i<j) { for i,find first ele >pivot & stop , for j , find first elemt from right do j-- which is <=pivot & stop , swap(i,j) } From low to j , all elements < pivot & from j+1 to high , all elements >= pivot , end : swap(j,low)
Leave a Comment