GATE Computer ScienceVery hardGATE CS (PYQ pattern)

Eight files of sizes 4, 7, 9, 12, 15, 18, 22 and 25 are merged using 3-way merges (merging any 3 files costs the sum of their sizes; merge results can be merged again). What is the minimum total cost of merging them into one file?

  1. A. 244
  2. B. 210
  3. C. 274
  4. D. 320

Correct answer: B. 210

With k = 3, the number of leaves must satisfy (n − 1) mod (k − 1) = 0; since 7 mod 2 = 1, add one dummy file of size 0 and then merge the 3 smallest each time: cost 210. Merging without the dummy costs 244, and binary merging of the same files costs 320.

More Algorithms questions

Exams that ask this topic