GATE Computer ScienceHardGATE CS (PYQ pattern)

Eight sorted lists of 100 keys each (800 distinct keys) are merged with the standard two-way merge, whose worst case for lists of sizes p and q is p + q - 1 comparisons. Strategy S merges list 1 with list 2, then the result with list 3, and so on up to list 8. Strategy B merges them in pairs, then the four results in pairs, then the final two. What are the worst-case total comparisons of S and of B?

  1. A. 3500 and 2400
  2. B. 3493 and 2400
  3. C. 2793 and 2393
  4. D. 3493 and 2393

Correct answer: D. 3493 and 2393

S: the k-th merge (k = 2..8) combines 100(k - 1) keys with 100, costing 100k - 1; the sum is 100(2 + ... + 8) - 7 = 3500 - 7 = 3493. B: three rounds, each touching all 800 keys: 4 merges of 200 (4 * 199), 2 of 400 (2 * 399) and 1 of 800 (799), total 2393. Forgetting the -1 per merge adds 7 to each.

More Programming and Data Structures (GATE) questions

Exams that ask this topic