retagged by
913 views
1 votes
1 votes

Recall the Partition subroutine that we used in QuickSort. Suppose that the following array has just been partitioned around some pivot element $: 3,1,2,4,5,8,7,6,9.$
Which of these element(s) could have been the pivot element?

  1. $4$
  2. $5$
  3. $2$
  4. $9$
retagged by

1 Answer

3 votes
3 votes
In order to determine which element(s) could have been the pivot element used in the Partition subroutine for the given array, we need to check whether all the elements to the left of the potential pivot are smaller than it and whether all the elements to the right of the potential pivot are larger than it. Following this property, the only possible elements that could have been the pivot are: $4,5$ and $9$
Answer: