, ▁for ▁each ▁ 2 ▁ ≤ ▁k ▁ ≤ ▁n , ▁the ▁minimum ▁costs ▁of ▁all ▁subsequ ences ▁of ▁length ▁k ▁using ▁the ▁costs ▁of ▁smaller ▁subsequ ences ▁already ▁computed . ▁It ▁has ▁the ▁same ▁asympt otic ▁runtime ▁and ▁requires ▁no ▁recursion . ▁ ▁Pse udo code : ▁// ▁Matrix ▁A [ i ] ▁has ▁dimension ▁dim s [ i - 1 ] ▁x ▁dim s [ i ] ▁for ▁i ▁= ▁ 1 .. n ▁Matrix Chain Order ( int ▁dim s []) ▁{ ▁▁▁▁ ▁// ▁length [ dim s ] ▁= ▁n ▁+ ▁ 1 ▁▁▁▁ ▁n ▁= ▁dim s . length ▁- ▁ 1 ; ▁▁▁▁ ▁// ▁m [ i , j ] ▁= ▁Min imum ▁number ▁of ▁scalar ▁multip lications ▁( i . e ., ▁cost ) ▁▁▁▁ ▁// ▁needed ▁to ▁compute ▁the ▁matrix ▁A [ i ] A [ i + 1 ] ... A [ j ] ▁= ▁A [ i .. j ] ▁▁▁▁ ▁// ▁The ▁cost ▁is ▁zero ▁when ▁multip lying ▁one ▁matrix ▁▁▁▁ ▁for ▁( i ▁= ▁ 1 ; ▁i ▁<= ▁n ; ▁i ++) ▁▁▁▁▁▁▁▁ ▁m [ i , ▁i ] ▁= ▁ 0 ; ▁▁▁▁▁ ▁for ▁( len ▁= ▁ 2 ; ▁len ▁<= ▁n ; ▁len ++) ▁{ ▁// ▁Sub sequence ▁lengths ▁▁▁▁▁▁▁▁ ▁for ▁( i ▁= ▁ 1 ; ▁i ▁<= ▁n ▁- ▁len ▁+ ▁ 1 ; ▁i ++) ▁{ ▁▁▁▁▁▁▁▁▁▁▁▁ ▁j ▁= ▁i ▁+ ▁len ▁- ▁ 1 ; ▁▁▁▁▁▁▁▁▁▁▁▁ ▁m [ i , ▁j ]