1,455 views
10 votes
10 votes
There are many variations of Quicksort. We may choose the pivot for each partition step in various ways. There are various strategies for partitioning an array segment into one subpartition of consecutive array positions that has values less than or equal to the pivot and another subpartition of consecutive array positions with those values greater than the pivot. The recursion that partitions the array into smaller and smaller segments may be stopped in various ways. However, even with all that variation, not any set of values can ever be a partition at any level. Your problem is to consider the Quicksorting of an array that initially has the values 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7 and identify below the one set of values that could possibly be one entire partition at some level of the Quicksort recursion

a) 6, 9, 7, 8, 9

b) 3, 1, 3, 1

c) 5, 4, 3, 3, 5

d) 1, 4, 1, 3

1 Answer

6 votes
6 votes
Question is very unique from normal ones. But definite possibility of being asked for GATE.

3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7

The thing is any partition of a quick sort will need to be consecutive sequence in the final sorted array. So, lets sort the given array of 14 elements. We get

1 1 2 3 3 4 5 5 5 6 7 8 9 9

Now, we can see if we get a contiguous space for each of the choices.

a) 6, 9, 7, 8, 9 - possible in the last 5 places.
b) 3, 1, 3, 1 - not possible as 2 must be inside them
c) 5, 4, 3, 3, 5 - possible from places 3-7 (starting from 0)
d) 1, 4, 1, 3 - not possible as one 2 and 1 3 is missing in between

Related questions

1 votes
1 votes
2 answers
2
Shubhanshu asked Dec 1, 2018
5,040 views
Is Quick sort an adaptive sorting Algorithm? I think no. Because as per the definition given in the Wikipedia is that A adaptive sorting Algorithm is one who takes the ad...
0 votes
0 votes
2 answers
3
Siddharth Bhardawaj asked Jul 19, 2018
1,591 views
The maximum number of swap possible of an unsorted array[1....n] in quicksort is?a) O(n)b) O($n^{2}$)Explain briefly.