GATE Computer ScienceEasyGATE CS (PYQ pattern)
What is the minimum number of comparisons that guarantees finding the median (the third smallest) of 5 distinct elements in the worst case?
- A. 5
- B. 7
- C. 8
- D. 6
Correct answer: D. 6
An exhaustive minimax search over the 120 orderings shows 6 comparisons suffice and 5 do not; sorting first would cost 7. Finding the median needs fewer comparisons than a full sort because the relative order of the other four need not be known.
More Algorithms questions
- A hash table with chaining has m = 50 slots and stores n = 200 keys; each key is equally likely to be in any slot (simple uniform…
- Twenty distinct keys are hashed independently and uniformly into 100 slots. What is the expected number of keys that share their slot with…
- The closed intervals [1,4], [2,6], [3,5], [7,10], [8,12], [9,11], [13,15], [5,8], [10,14], [0,2] are given. What is the minimum number of…
- From index 0 of the array [3, 1, 4, 1, 2, 1, 1, 5, 2, 1, 1, 3, 1, 2, 1] you may jump forward at most a[i] positions from index i. What is…
- The array [12, 7, 9, 14, 5, 11, 8, 10, 6] must be split into 3 contiguous parts so that the largest part sum is as small as possible. What…
- Coupons of 6 equally likely types are drawn with replacement. What is the expected number of draws until 4 different types have been seen?