Skip to content
Official PYQ · 2008

GATE CS 2008 Q43 — Searching, Sorting, Hashing

Explain with AI

Consider the Quicksort algorithm. Suppose there is a procedure for finding a pivot element which splits the list into two sub-lists each of which contains at least one-fifth of the elements. Let T(n)T(n) be the number of comparisons required to sort nn elements. Then

Choose one option
View worked solution

Answer: B

In the Quicksort algorithm, the list of size nn is partitioned into two sub-lists around a pivot element. The cost of this partitioning step is O(n)O(n) comparisons (represented here as nn).

We are given that each of the two resulting sub-lists contains at least one-fifth of the elements. Let the sizes of the two sub-lists be n1n_1 and n2n_2. This condition implies:

n5≤n1,n2≤4n5\frac{n}{5} \leq n_1, n_2 \leq \frac{4n}{5}

In the worst-case scenario that satisfies this condition, the split is as unbalanced as possible. This occurs when one sub-list is of the minimum possible size, n5\frac{n}{5}, and the other sub-list is of the maximum possible size, 4n5\frac{4n}{5}.

Therefore, the recurrence relation for the number of comparisons T(n)T(n) is bounded by:

T(n)≤T(n5)+T(4n5)+nT(n) \leq T\left(\frac{n}{5}\right) + T\left(\frac{4n}{5}\right) + n

Hence, the correct option is B.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Searching, Sorting, Hashing questions