Data Structures & AlgorithmsModerateGATE CS

Six sorted files have 14, 31, 34, 35, 36, 58 records. Merging two files of sizes a and b costs a + b. What is the minimum total cost to merge them all into one file?

  1. A. 596
  2. B. 416
  3. C. 544
  4. D. 530

Correct answer: D. 530

Optimal merge pattern = Huffman: always merge the two smallest current files; the total is 530. Merging left to right in the given order costs 596.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic