Data Structures & AlgorithmsHardProduct-company placement
Five matrices have dimensions 12×10 , 10×4 , 4×6 , 6×6 , 6×8. What is the minimum number of scalar multiplications needed to compute their product?
- A. 1200
- B. 1776
- C. 1760
- D. 2040
Correct answer: A. 1200
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 1200. Left-to-right gives 1776, right-to-left 1760.
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
- An undirected graph has edges A–D, A–F, A–G, B–C, B–F, C–D, C–E, E–G, F–G. An ITERATIVE DFS starts with stack [A]; it pops a vertex, skips…
- What is the length of the longest common subsequence of ONTOLOGY and TOPOLOGY, and how many DISTINCT longest common subsequences (as…
- Edit distance between MARTIAN and COMPILER where insert and delete cost 1 each but a substitution costs 2: what is the minimum total cost?
- Dijkstra's algorithm runs from A on the directed graph A→C (4), B→A (1), B→F (6), C→B (7), C→E (12), C→F (6), D→C (3), E→A (15), E→B (3)…
- The weighted undirected graph A–B (27), A–D (3), A–E (1), B–C (25), B–D (8), B–E (18), B–F (5), C–E (9) has a unique MST. What is the…
- A simple undirected graph has 13 vertices and exactly 4 connected components. What is the maximum possible number of edges?