Data Structures & AlgorithmsVery hardGATE CS
Matrices A1…A7 have dimensions 5×10, 10×3, 3×12, 12×5, 5×50, 50×6, 6×8. What is the minimum number of scalar multiplications needed to compute the product A1A2…A7?
- A. 2184
- B. 3620
- C. 2484
- D. 2034
Correct answer: A. 2184
The matrix-chain DP gives 2184. Multiplying strictly left to right costs 3620.
More Coding Interview Problems questions
- A 2 × 11 board is tiled completely using 1 × 2 dominoes (placed either way) and 2 × 2 squares. How many different tilings are there?
- The 3 × 3 grid graph (9 vertices, 12 edges) has a diagonal edge added between its top-left corner and its centre vertex, giving a 13-edge…
- 50 people stand in a circle numbered 1 to 50. Starting the count at person 1, every 7th person (counting the first as 1) is removed, and…
- How many subsets of {1, 2, ..., 15} (including the empty set) contain no two consecutive integers and have an even sum?
- How many integers n with 1 <= n <= 100000 are divisible by exactly one of the numbers 6, 10 and 15?
- How many primes p < 500 have p - 2 or p + 2 also prime (that is, belong to at least one twin-prime pair, counted as individual primes)?