Data Structures & AlgorithmsVery hardICPC regional · GATE CS top band
A chain of 6 matrices M1 to M6 has dimensions given by the sequence p = [16, 18, 7, 19, 14, 15, 7], where Mi has size p[i−1] × p[i] (1-indexed). Multiplying two matrices of sizes a×b and b×c costs a·b·c scalar multiplications. What is the minimum total number of scalar multiplications over all parenthesisations?
- A. 6916
- B. 6818
- C. 13440
- D. 7161
Correct answer: B. 6818
The interval DP gives 6818. Multiplying strictly left to right costs 13440; the greedy 'cheapest adjacent pair first' rule gives 6916, which is not optimal.
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
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–B (12), A–C (16), A–D (15), B–C (2), B–D (20), B–E (17), C–E…
- Directed weighted graph on vertices A, B, C, D, E with edges (u→v, w): E→B (1); A→E (3); C→E (3); C→B (8); D→C (7); D→A (9); C→D (5); D→E…
- Bipartite graph with left side {A, B, C}, right side {D, E, F, G} and edges B–D, B–G, C–D, C–E, C–F. What is the size of a maximum…
- Rooted tree with root 0 and vertices 0 to 9; the edges are 0–1, 1–2, 2–3, 2–4, 2–5, 0–6, 2–7, 7–8, 3–9 (parent–child). Every edge has…
- Array A = [6, 24, 27, 0, 7, 23, 30, 19]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 25? (A trie with subtree counts answers this…
- Tree with vertices 0 to 9, root 0, edges 0–1, 1–2, 1–3, 1–4, 3–5, 1–6, 2–7, 5–8, 4–9 (parent–child). Vertex weights (vertex:weight) 0:16…