Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
A chain of 6 matrices M1 to M6 has dimensions given by the sequence p = [20, 8, 2, 10, 19, 2, 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. 5560
- B. 3436
- C. 2968
- D. 1048
Correct answer: D. 1048
The interval DP gives 1048. Multiplying strictly left to right costs 5560; the greedy 'cheapest adjacent pair first' rule gives 3436, 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
- A trie keeps a counter at each node, and every word of the list W = ['a', 'c', 'a', 'a', 'cac', 'caa', 'bc', 'bcb'] is inserted once per…
- Tree with vertices 0 to 8, root 0, edges 0–1, 0–2, 1–3, 3–4, 2–5, 1–6, 1–7, 3–8 (parent–child). Vertex weights (vertex:weight) 0:10, 1:9…
- A chain of 4 matrices M1 to M4 has dimensions given by the sequence p = [17, 3, 2, 3, 5], where Mi has size p[i−1] × p[i] (1-indexed)…
- Directed graph on vertices A, B, C, D, E, F, G with edges A→C, D→E, F→B, F→G, D→F, C→G, F→D, F→E (no weights). What is the number of…
- Undirected graph on vertices A, B, C, D, E, F, G with edges A–B (1), A–C (1), B–C (1), B–D (1), B–E (1), B–F (1), C–E (1), D–E (1), E–G…
- Words ['dd', 'bb', 'bcd', 'bcc', 'cad', 'baa'] (each may be used at most once). A chain is a sequence of these words in which the first…