11. Quick sort⭐

Smart Divide & Conquer

( time- NlogN,    space- 1 )

pick a pivot & place it in its correct position in sorted array















--------------------------------------------------------------------------------------------------------------------------
1. make low and high
2. choose pivot
3. take 2 pointers i=low & j=high
4. if, a[i] > pivot  &  a[j]<= pivot,  swap the two else i++ and j--
5. for one round do this till,  i>j
6. last mein pivot se swap karo
7. ab partition bangya, so 
put pivot in right place--> sort left and right half
------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------

Comments

Popular posts from this blog

30.) DP on subsequences

19. Strings (LB)

32. Binary Trees-2 (bfs/dfs med problems)