Data Structures & AlgorithmsHardGATE CS
Five matrices have dimensions 5×5 , 5×5 , 5×15 , 15×4 , 4×3. What is the minimum number of scalar multiplications needed to compute their product?
- A. 860
- B. 555
- C. 1155
- D. 510
Correct answer: D. 510
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 510. Left-to-right gives 860, right-to-left 555.
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
- The directed graph A→B (4), A→C (5), A→E (3), B→D (6), B→E (-3), C→E (7), D→C (1), E→D (2) has one negative edge but no negative cycle…
- Dijkstra's algorithm runs from A on the directed graph A→C (15), A→D (3), B→E (4), B→F (12), C→B (12), C→E (1), D→B (2), D→C (9), E→A…
- Heap sort (ascending) is run on [44, 9, 47, 27, 1, 46, 30, 10]: build a max-heap bottom-up, then repeatedly swap the root with the last…
- A binary search tree holds exactly the keys 17, 22, 27, 39, 40, 92, 97, 98. Which ONE of the following can be its POSTORDER traversal?
- A BST holds integer keys between 1 and 100. Which sequence CANNOT be the sequence of keys examined while searching for 58?
- What is the length of the longest common subsequence of MATRIX and MARTIAN, and how many DISTINCT longest common subsequences (as strings)…