GATE Computer ScienceHardGATE CS (PYQ pattern)
For n = 5 distinct keys, let M be the worst-case comparisons of top-down merge sort (split ⌈n/2⌉ + ⌊n/2⌋, merge stops when one side is empty), B the worst-case comparisons of binary insertion sort, and O the minimum worst-case comparisons of any comparison sort. What is (M, B, O)?
- A. (8, 8, 7)
- B. (8, 7, 7)
- C. (7, 8, 7)
- D. (9, 8, 7)
Correct answer: A. (8, 8, 7)
M: sorting 3 costs 3 and 2 costs 1, plus a final merge of 4: 8. B: inserting the k-th key into k − 1 sorted keys costs ⌈log₂ k⌉: 1 + 2 + 2 + 3 = 8. O = 7 = ⌈log₂ 120⌉, achieved by a special merge-insertion scheme. Brute force over all 120 inputs confirms M = B = 8.
More Algorithms questions
- What is the minimum number of comparisons that guarantees finding the median (the third smallest) of 5 distinct elements in the worst case?
- 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…