# Dijkstra 4 Named after its inventor Edsger Dijkstra

• Slides: 55

Dijkstra算法 4 Named after its inventor Edsger Dijkstra (1930 -2002) Truly one of the "founders" of computer science This is just one of his many contributions

1, c U 1 2 b 7 8 a 8, c 2 1 s 0 4 d 4, c e 3 2 4 3 5 1 4 7, cf 7 c 2, c h 3 4 g 6

1, c S 2 b 7 1 8 a c 8, c 2 3 2 4 d 4, c 4 4 1 7, cf 3 5 U 2 e 7 0 2, c h 3 4 g 6 4, b

S 1, c 2 b 7 8 a 8, c 2 1 s 0 4 d 4, c e 3 2 4 3 5 1 4 6, e 7, cf 7 c 2, c h 3 4 g U 3 6 4, b 3, e

S 1, c 2 b 7 8 a 8, c 2 1 s 0 4 d U 4 4, c e 3 2 4 3 5 1 4 6, ef 7 c 2, c h 3 4 g 6 9, h 3, e

S 1, c 2 b 7 8 a 8, c 6, d 2 1 s 0 4 d 4, c e 3 2 4 3 5 1 4 6, ef 7 c 2, c U 5 h 3 4 g 6 9, h 3, e

1 7 8 6 2 1 2 2 7 5 3 6 2 s 0 4 4 4 3 5 4 2 1 2 2 1 3 2 6 7 s 0 4 4 3 3 4 5 4 1 5 6 9 3 3 1 6 7 9 8 6 2 1 2 2 5 2 6 7 s 0 4 4 3 5 1 3 3 3 4 9 6

Floyd-Warshall算法 动态规划方法：Use optimal substructure of shortest paths: Any subpath of a shortest path is a shortest path. 构建一个三维矩阵: � 定义dij(k)：中间节点在{1, 2, 节点j的最短距离 � 最终目的是要计算dij(n) …, k}中的从节点i到

Step 1

Step 2

Step 3

Step 4

Step 5

45 Labeling Algorithm (Ford & Fulkson) Initialization: set all flow to 0 N 1, all nodes connected to the source by an edge with positive excess capacity Step 1: (1) Identify N 1 (2) Label nodes in N 1 as follows [4, 1] Excess capacity of (1, j) [Ej, 1] 1 Denoting node 1 4 e 1, 4= 4 e 4, 1= 0 e 1, 2= 5 e 2, 1= 0 4 2 5 2 [5, 1] 3 5 4 2 3 6 3 3

46 Labeling Algorithm (Ford & Fulkson) N 2(j), all unlabelled nodes connected to node j by an edge with positive excess capacity Also N 2, in this case Step 2: (1) Identify N 2(j), based on the node j, with the smallest number, in N 1 (2) Label nodes in N 2(j) as follows min{Ej, Excess capacity of (j, k)} [Ek, j] Denoting node j (3) Do as above for all j in N 1, and let e 4, 5= 3 e 5, 4= 0 [4, 1] 4 e 1, 4= 4 e 4, 1= 0 1 e 1, 2= 5 e 2, 1= 0 3 4 2 2 5 [5, 1] j 5 4 e 2, 5= 2 e 5, 2= 0 3 2 [2, 2] e 2, 3= 3 e 3, 2= 0 6 3 3 [3, 2]

47 Labeling Algorithm (Ford & Fulkson) Step 3: Continue as in step 2, forming N 3, N 4, N 5, . . . , until: i. the sink has been labeled, (goto step 4) ii. the sink has not been labeled, and no other nodes can be labeled according to the rules (algorithm ends, and the total flow is the maximum flow) (note: the source is not labeled) N 3, the sink has been labeled e 4, 5= 3 e 5, 4= 0 [4, 1] 4 e 1, 4= 4 e 4, 1= 0 1 e 1, 2= 5 e 2, 1= 0 3 4 2 2 5 [5, 1] j 5 e 2, 5= 2 e 5, 2= 0 3 2 [2, 2] e 2, 3= 3 e 3, 2= 0 4 [3, 3] 6 3 3 [3, 2] e 3, 6= 3 e 6, 3= 0

48 Labeling Algorithm (Ford & Fulkson) Step 4: The label of sink is [En, m] (here, [3, 3]), where En is the amount of extra flow that can be made to reach the sink through a path , and the path can be traced backward by node m Update ei, j, ej, i accordingly, and then return to step 1 [4, 1] [2, 2] 4 1 e 1, 2= 2 e 2, 1= 3 3 4 4 6 3 3 2 [5, 1] [3, 3] 2 2 5 5 j e 2, 3= 0 e 3, 2= 3 3 [3, 2] e 3, 6= 0 e 6, 3= 3

Max Flow Min Cut Theorem 54 For any flow F, and any cut K, all parts of F must pass through the edges of K. Since c(K) is the maximum amount that can pass through the edges of K, so, value(F) c(K). If value(F)=c(K), then the flow uses the full capacity of all edges in K, F must be a flow with maximum value, and, on the other hand, K must be a cut with minimum capacity. Theorem A maximum flow F in a network has value equal to the capacity of a minimum cut of the network 4 (4, 2) 1 (3, 2) (2, 0) value(F)=7 5 (4, 4) 6 (2, 2) (5, 5) 2 (3, 3) 3 (3, 3)