------------------------------------- m matrix = |------------------------------------------------ |P 1 2 3 4 5 6 |------------------------------------------------ |1| 0 150 330 405 1655 2010 |2| 0 360 330 2430 1950 |3| 0 180 930 1770 |4| 0 3000 1860 |5| 0 1500 |6| 0 ------------------------------------- s matrix = |------------------------------------------------ |P 1 2 3 4 5 6 |------------------------------------------------ |1| 0 1 2 2 4 2 |2| 0 2 2 2 2 |3| 0 3 4 4 |4| 0 4 4 |5| 0 5 |6| 0 ------------------------------------- Optimal paranthesization: (A B) ((C D) (E F)) The procedure MATRIX-CHAIN-ORDER runs in Runtime: O(n3) Space: O(n2) space to store the C and S tables. The procedure PRINT-OPTIMAL-PARENS runs in O(n) time and uses no additional space. The overall running time is O(n3) and the space requirement is O(n2).