Data Structures & AlgorithmsVery hardICPC regional · GATE CS top band
A chain of 5 matrices M1 to M5 has dimensions given by the sequence p = [20, 17, 5, 11, 19, 20], 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. 6645
- B. 13780
- C. 18548
- D. 14580
Correct answer: A. 6645
The interval DP gives 6645. Multiplying strictly left to right costs 14580; the greedy 'cheapest adjacent pair first' rule gives 18548, 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, F with edges A–E (3), A–F (5), B–D (1), B–E (2), C–F (20), D–E (17), D–F…
- Directed weighted graph on vertices A, B, C, D with edges (u→v, w): D→B (3); B→C (4); A→C (6); D→A (2); A→D (2); D→C (6); B→A (8); B→D…
- Directed weighted graph on vertices A, B, C, D, E, F with edges listed in this exact order: E→D (1); F→D (5); F→C (1); B→E (5); F→A (4)…
- Coins of denominations [12, 9, 8, 2] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 18?…
- Array A = [9, 3, 3, 8, 2, 4, 3] (indices 0 to 6). Count the non-empty subsets of positions (each position used at most once, subsets not…
- Rooted tree with root 0 and vertices 0 to 9; the edges are 0–1, 1–2, 1–3, 0–4, 2–5, 5–6, 1–7, 2–8, 6–9 (parent–child). Every edge has…