|
 |
 |
 |
 |
 |
 |
 |
 |
| • |
Time: O(n3)
|
|
|
|
|
| • |
Space: O(n2)
|
|
|
|
|
| • |
This
algorithm only
|
|
|
|
computed
the least cost.
|
|
|
|
How
do we remember which
|
|
multiplies
led to the least
|
|
|
|
cost?
|
|
|
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
| • |
To
remember choices:
|
|
|
|
– |
Whenever
we assigned a
|
|
|
|
cost to
C[i,j], we had a
|
|
|
|
particular
k we were using
|
|
|
|
– |
So we
use another array
|
|
|
|
Mem[i,j]
= k whenever C[i,j]
|
|
|
|
is
assigned
|
|
|
|
– |
The
sequence of multiplies
|
|
|
|
can be
reconstructed
|
|
|
|
starting
with the last multiply
|
|
|
which
is held in Mem[1,n]
|
|
|
|