Data Structures & AlgorithmsModerateProduct-company placement

Six sorted files have 10, 12, 13, 21, 23, 42 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. 313
  2. B. 298
  3. C. 242
  4. D. 308

Correct answer: B. 298

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic