324 views
7 votes
7 votes

Which of the following is/are the possible array contents after second pass of Quick Sort for the following initial ordering assuming first element is taken as pivot?$$34, 8, 64, 51, 32, 21$$

  1. $8, 21, 32, 34, 51, 64$
  2. $8, 32, 34, 51, 64, 21$
  3. $8, 34, 51, 64, 32, 21$
  4. $8, 34, 64, 51, 32, 21$

2 Answers

2 votes
2 votes
In first pass $34$ is the pivot. So, it'll get position as in the final sorted order which is $4^{th}$ position. This is true only for option A.
0 votes
0 votes

So basically in first pass (or swap) 21 and 64 get swapped and in 2nd Swap when the Right Bound crosses Left Bound, 34 gets placed before 51. Giving us 8,21,32,34,51,64

Answer:

Related questions