Data Structures & AlgorithmsModerateGATE CS · Product-company placement

Six sorted files have 27, 35, 38, 45, 52, 54 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. 647
  2. B. 755
  3. C. 502
  4. D. 674

Correct answer: A. 647

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic