Lecture Notes for CS 512, Algorithm Design
5 April 2000, Dynamic Programming
matrix
M
1
with
r
1
rows and
c
2
columns
the product
M
3
=
M
1
M
2
M
3
[i, j] = dot(
M
1
[i, *],
M
2
[*, j])
matrix multiplication is associative, but order is important
((10, 5) (5, 12)) (12, 7)
(10, 5) ((5, 12) (12, 7))
600
420
(10, 12) (12, 7)
(10, 5) (5, 7)
840
350
(10, 7)
(10, 7)
1440
780
how to parenthesize expression to minimize multiplications
try exhaustive search
look at every possible sequence
what is the structure of an optimal solution
if the multiplication (
M
1
...
M
i
)(
M
i
+1
,
M
n
) is optimal, what about
M
1
...
M
i
and
M
i
+1
,
M
n
mults
(
M
i
...
M
j
) =
mults
(
M
i
...
M
k
)
mults
(
M
i
+1
...
M
j
) +
c
i
r
i
c
j
but, we don't know the dividing point
k
; we have to look for it
a exponential algorithm
how many subproblems are there?
there are only Theta(
n
2
) subproblems in an exponential algorithm
doing polynomial things in exponential time means there's repitition
the dynamic programming method
the two dynamic programming requirements
optimal subproblems
repeated subproblems
dynamic programming - compute the subproblem once, then recall it
memoization - dynamic programming without the optimal subproblem property
This page last modified on 5 April 2000.