Course: 113-1 Introduction to Algorithms. Lecturer: Huilan Chang. 2024.11.28 Reference: Chained Matrix Multiplication (Section 3.4 in Foundations Of Algorithms by Neapolitan)

Preliminaries


Brute-force method (暴力法)


Thus $t_n\geq 2t_{n-1}$. Therefore, $t_n\geq 2^{n-2}t_2=2^{n-2}$. QED.

Dynamic Programming (動態規劃)


<aside>

Definition. For $1\leq i\leq j\leq n$, let

$M[i][j]$ = the minimum number of multiplications to multiply $A_i$ through $A_j$ if $i<j$. $M[i][i]= 0$.

</aside>

Screenshot 2024-11-28 at 16.59.30.png

For $k=1\cdots 5$, the minimum number of multiplications for the $k$-th factorization is $M[1][k]+M[k+1][6]+d_0d_kd_6$ Then $M[1][6]=\displaystyle\min_{1\leq k\leq 5} M[1][k]+M[k+1][6]+d_0d_kd_6$.

<aside>

Generally, $M[i][j]=\displaystyle\min_{i\leq k\leq j-1} M[i][k]+M[k+1][j]+d_{i-1}d_kd_j$ if $i<j$, and

$M[i][i]=0$.

</aside>

注意:當中用到一個重要的性質”optimal substructure”: The optimal order for multiplying $n$ matrices contains the optimal order of the multiplication of some matrices within it. Example. If $(A_1(((A_2(A_3 A_4)) A_5) A_6))$ is optimal, then $((A_2(A_3 A_4)) A_5)$ is optimal for multiplying $A_2$ through $A_5$.

Screenshot 2024-11-28 at 17.27.28.png