
A top-down approach of computing, say, f(5) is inefficient do to repeated subcomputations.
A bottom-up approach computes f(0), f(1), f(2), f(3), f(4), f(5) in the listed order.
A dynamic programming algorithm.
FOR k=1 TO n FOR i=1 TO n FOR j=1 TO n c(i,j,k) = min( c(i,j,k-1), c(i,k,k-1)+c(k,j,k-1) )
| k = Ø |
a b c d e f
a 1 7 5
b 7 3
c 1 2
d 8
e 4
f
|
| k = {a} |
a b c d e f
a 1 7 5
b 7,b-a-c ,b-a-d 3,b-a-e ,b-a-f
c ,c-a-d 1,c-a-e 2,c-a-f
d 8,d-a-e ,d-a-f
e 4,e-a-f
f
|
| k = {a, b} | |
| k = {a, b, c} | |
| k = {a, b, c, d} | |
| k = {a, b, c, d, e} | |
| k = {a, b, c, d, e, f} |