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?
- A. 313
- B. 298
- C. 242
- 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.
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
- 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)?
- For the string ABRACADABRA, what are the lengths of the longest palindromic SUBSTRING and the longest palindromic SUBSEQUENCE?
- Heap sort (ascending) is run on [20, 37, 49, 16, 22, 10, 31, 33]: build a max-heap bottom-up, then repeatedly swap the root with the last…
- What is the length of the longest BITONIC subsequence (strictly increasing then strictly decreasing; either part may be empty) of [20, 21…