Guest User

Untitled

a guest
Jan 22nd, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. I came across following problem:
  2.  
  3. > Consider an array consisting of the following elements in unsorted order but 60 as first element:
  4.  
  5. > 60,80,15,95,7,12,35,90,55
  6.  
  7. > Quick sort partition algorithm is applied by choosing first element as pivot. How many total number of arrangements of array integers is possible preserving the effect of first pass of partition algorithm?
  8.  
  9. Solution given was
  10.  
  11. > We write the sorted array as : 7 12 15 35 55 60 80 90 95
  12. > So as shown above we will have 5 elements to left of 60 and 3 elements to right of 60.
  13. > Hence number of required permutations = no of permutations of left part * right part
  14. = 5!*3!
  15. = 120*6
  16. = 7200
  17.  
  18. **My doubt**
  19.  
  20. I feel partition can result in exactly one arrangement after first pass:
  21.  
  22. 55, 15, 7, 12, 35, 60, 80, 90, 95
  23.  
  24. and it is incorrect to do factorial of elements on either side of pivot. So question in a sense incorrect. Am I right or am missing something here?
  25.  
  26. PS: I am assuming standard quick sort, for example one which is given in CLRS.
Add Comment
Please, Sign In to add comment