Академический Документы
Профессиональный Документы
Культура Документы
Dynamic Programming
The airplane problem
Function mincost(i)
Analysis:
n−1
X
T (n) := T (i) + Θ(n);
i=0
From this we can conclude
T (n) = 2T (n − 1) + Θ(1), ∀n ≥ 2.
Function M incost(i)
Example:
i Air cost(i)
i Hotel cost(1)
1 1
1 2
2 4
2 2
3 9
3 5
4 16
Final solution: 0 → 2 → 3 → 4?
Critical Paths
t1=5
t3=3
t5=5
t0
t4=3
t2=11
t7=1
t6=6
End
t1=5
t3=3
t5=5
t0
t4=3
t2=11
t7=1
t6=6
End
a d
k−1
X
cost(TL) = pl ∗ depthTL (l).
l=i
Similarly we can define cost(TR ).
Defining The Cost Function:2
Function cost(i, j)
Function cost(i, j)
For j := 1 to n do
For i := j down to 1 do
c(i, j) = min c(i, k−1)+c(k+1, j)+w(i, j);
i≤k≤j
End-for
end
1 3 6 10 7 8 9 10 1 5 8 10
2 5 9 6 5 4 2 6 9
4 8 3 2 3 7
7 1 4
Solution 1 Incorrect Solution 2
Solution 2
Function cost(i, j)
For s := 1 to n do
For i := 1 to n − s + 1 do
j := i + s − 1;
k := arg min c(i, k − 1) + c(k + 1, j);
i≤k≤j
Node A B C D
Consider
prob ∗ 10 1 4 2 3
A
B
9
B A
B C
8 12
C B
C D
8
7
C
D
C
A B
B
B
A
C
15 10 13
C
A
Case for
{A,B,C}
D
B C
17
D B
16 B
16 D C
C
Case for
{B,C,D}
A
B
C
A D
B
D
18
26 C
D
C
D
B
B
C
19
A
20
A
The algorithm
Floyd-Warshall Algorithm
EditDistance (P,T)
b c d e f f g h i x
0 1 2 3 4 5 6 7 8 9 10
a 1 1 2 3 4 5 6 7 8 9 10
b 2 1 2 3 4 5 6 7 8 9 10
c 3 2 1 2 3 4 5 6 7 8 9
d 4 3 2 1 2 3 4 5 6 7 8
e 5 4 3 2 1 2 3 4 5 6 7
f 6 5 4 3 2 1 2 3 4 5 6
g 7 6 5 4 3 2 2 2 3 4 5
h 8 7 6 5 4 3 3 3 2 3 4
i 9 8 7 6 5 4 4 4 3 2 3
j 10 9 8 7 6 5 5 5 4 3 3
Traveling salesman:Revisit
Problem: to find the minimum cost cycle in a di-
rected graph. L(i, j) denote the length from i to j.