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?
- A. 647
- B. 755
- C. 502
- 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.
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
- What is the minimum number of edges that must be deleted from the undirected graph with edges A–B, B–C, B–E, B–F, C–D, C–E, C–F, D–F, E–F…
- What does f(3) print? c void f(int n) { if (n <= 0) return; printf("%d", n); f(n - 2); printf("%d", n); f(n - 1); }
- All suffixes of the string 'mississ' are inserted into a character trie (a suffix trie). How many nodes does it have, including the root?
- Keys 14, 86, 32, 49, 38, 76, 17, 91, 35, 81, 16 are inserted in that order into an empty BST. Then 32 is deleted and after that 86 is…
- The weighted undirected graph A–B (2), A–E (1), B–C (6), B–D (1), B–E (2), C–D (6), D–E (3) has repeated weights. How many different…
- What is the edit distance (insert, delete, substitute; each cost 1) between SUBSEQUENT and PLATFORM?