Matrix Chain Multiplication
Partition DP & MCM DSA practice problem on Onlearn.
Difficulty: hard.
Topics: Matrix Chain Multiplication and Partition DP, Dynamic Programming, Recursion, Memoization, Matrices, Time Complexity, Space Complexity, Optimal Substructure, Overlapping Subproblems, Arrays, Loops, Base Cases, Optimization, memoization, recursion, dynamic programming, Partition DP.
Matrix Chain Multiplication Problem Statement Given a chain of matrices $A 1, A 2, \dots, A n$. The dimensions of these matrices are represented by an array arr of size n+1, where arr[i 1] and arr[i] are the dimensions of matrix $A i$. Find the minimum number of scalar multiplications required to multiply these $n$ matrices. Rules of Matrix Multiplication: Two matrices $A 1$ (dimensions $p \times q$) and $A 2$ (dimensions $r \times s$) can only be multiplied if and only if $q = r$. The resulting matrix will have dimensions $p \times s$. The total number of scalar multiplications required to multiply $A 1$ and $A 2$ is $p \cdot q \cdot s$. Example: Given dimensions arr = {10, 20, 30, 40, 50}. Here, $n=4$ matrices are involved: $A 1$ of size $10 \times 20$ $A 2$ of size $20 \times 30$ $A 3$ of size $30 \times 40$ $A 4$ of size $40 \times 50$ Output: The minimum number of scalar operations. Sample Test Case: Input: arr = {10, 20, 30, 40, 50} Output: 38000