Data Structures & AlgorithmsHardGATE CS · Product-company placement
Five matrices have dimensions 12×5 , 5×12 , 12×10 , 10×3 , 3×5. What is the minimum number of scalar multiplications needed to compute their product?
- A. 2700
- B. 900
- C. 1350
- D. 2910
Correct answer: B. 900
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 900. Left-to-right gives 2700, right-to-left 1350.
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 rod of length 8 can be cut into integer pieces; a piece of length i sells for p(i) with p(1..8) = 2, 8, 10, 13, 21, 22, 25, 28. What is…
- What is the minimum number of cuts needed to split 'abacdcab' into pieces that are all palindromes?
- What is the length of the longest common subsequence of PLATFORM and PLACEMENT, and how many DISTINCT longest common subsequences (as…
- How many topological orderings does the DAG on vertices A–F with edges B→C, D→C, E→A, E→C, E→D, E→F have?
- Dijkstra's algorithm runs from A on the directed graph A→B (15), A→C (3), A→D (13), C→B (9), D→C (4), D→E (1), D→F (10), E→B (12), E→C…
- Using parts 2, 3, 5 (each any number of times), in how many ways can 11 be written as an ORDERED sum (so 1 + 2 and 2 + 1 count separately)?