Skip to content
Official PYQ · 2019

GATE CS 2019 Q20 — Searching, Sorting, Hashing

Explain with AI
An array of 2525 distinct elements is to be sorted using quicksort. Assume that the pivot element is chosen uniformly at random. The probability that the pivot element gets placed in the worst possible location in the first round of partitioning (rounded off to 22 decimal places) is ________
View worked solution

Answer: 0.08

In Quicksort, the worst-case partitioning occurs when the pivot splits the array of size nn into two highly unbalanced subproblems of sizes 00 and n−1n-1.

This worst-case scenario happens when the chosen pivot is either:

  1. The minimum element of the array (placed at the leftmost position after partitioning).
  2. The maximum element of the array (placed at the rightmost position after partitioning).

For an array of n=25n = 25 distinct elements:

  • Total number of possible pivot choices = 2525
  • Number of choices leading to the worst-case partition = 22 (the minimum and the maximum elements)

Since the pivot is chosen uniformly at random, the probability PP of selecting a worst-case pivot is:

P=225=0.08P = \frac{2}{25} = 0.08

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

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