Skip to content
GATEiit

GATE CSE 2019 Q30: Quicksort on 25 distinct elements: probability pivot lands in worst location

Syllabus topic: Searching, sorting and hashing

Question

An array of 25 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 2 decimal places) is ________.

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 0.08 (official GATE 2019 final answer key)

Concept used: Quicksort's worst split happens when the pivot is the smallest or largest element, leaving one empty side.

Concept notes

Loading notes…

First step: Identify which pivot choices put it at an end of the array, and divide that count by the 25 equally likely choices.

Full step-by-step solution

Loading…

Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.

More questions on Searching, sorting and hashing

Every PYQ on this topic →

Share this question

WhatsAppDownload image

Source: official GATE 2019 CS question paper and final answer key, organised by IIT Madras. Question paper · Answer key