Data Structures & AlgorithmsHardGATE CS · Product-company placement
Five matrices have dimensions 10×15 , 15×3 , 3×5 , 5×15 , 15×15. What is the minimum number of scalar multiplications needed to compute their product?
- A. 1800
- B. 3600
- C. 4275
- D. 6975
Correct answer: A. 1800
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 1800. Left-to-right gives 3600, right-to-left 4275.
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, A–D, A–E, B–E, B–F, C–D, C–F, D–E, E–F…
- A 4-ary max-heap is stored in a 0-indexed array (children of i at 4i + 1 … 4i + 4): [51, 46, 36, 39, 2, 22, 35, 14, 13, 24]. After…
- How many subsets of {4, 7, 9, 10, 11, 13, 14} have sum exactly 31?
- Unit-time jobs (deadline, profit): J1 (3, 45), J2 (2, 47), J3 (1, 77), J4 (1, 75), J5 (1, 13), J6 (2, 37), J7 (3, 59). One job runs at a…
- A directed graph on A–H has edges B→A, B→C, C→F, C→H, D→C, E→C, E→H, F→G, F→H, G→C, H→A. How many strongly connected components does it…
- 0/1 knapsack with capacity 18: items (weight, value) = (2, 25), (5, 31), (8, 37), (4, 22), (4, 27). What is the maximum total value?