Data Structures & AlgorithmsModerateGATE CS

Six sorted files have 8, 23, 33, 38, 42, 49 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. 534
  2. B. 481
  3. C. 386
  4. D. 489

Correct answer: B. 481

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic