Data Structures & AlgorithmsHardProduct-company placement
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 product?
- A. 336
- B. 380
- C. 528
- D. 248
Correct answer: D. 248
m[i][j] = min over split k of m[i][k] + m[k+1][j] + p(i−1)·p(k)·p(j); the full chain costs 248. Left-to-right gives 336, right-to-left 380.
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
- 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…
- 0/1 knapsack with capacity 17: items (weight, value) = (9, 21), (6, 19), (3, 9), (7, 13), (3, 27). What is the maximum total value?