3,129 views
10 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 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
Position:
Show:

Related questions

3 3 votes
4 4 answers
2.5k
2.5k views
newdreamz a1-z0 asked Jan 21, 2019
2,521 views
Consider a scenario of modified quick sort, where we have given an input sorted array A[1 .. . n], all elements of array are distinct and n >=3. Pivot is the median of se...
1 1 vote
2 2 answers
6.0k
6.0k views
Shubhanshu asked Dec 1, 2018
5,969 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 0 votes
2 answers 2 answers
2.3k
2.3k views
Siddharth Bhardawaj asked Jul 19, 2018
2,329 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.