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?
- A. 534
- B. 481
- C. 386
- 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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Kruskal's algorithm runs on the weighted undirected graph A–B (15), A–F (7), A–G (21), B–C (17), B–D (23), B–F (22), D–F (8), E–F (13)…
- A complete binary tree (array form, all levels full except possibly the last, which is filled from the left) has 131 nodes. How many…
- 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…
- Five matrices have dimensions 3×2 , 2×4 , 4×2 , 2×8 , 8×10. What is the minimum number of scalar multiplications needed to compute their…
- Keys 17, 35, 21, 81, 58, 30, 62, 57, 82, 93, 61 are inserted in that order into an empty BST. Then 58 is deleted and after that 35 is…
- Using parts 1, 2, 3 (each any number of times), in how many ways can 7 be written as an ORDERED sum (so 1 + 2 and 2 + 1 count separately)?