Download presentation
Presentation is loading. Please wait.
Published byAnnabella Ross Modified over 8 years ago
1
Honors Track: Competitive Programming & Problem Solving Push-Relabel Algorithm Claire Claassen
2
Graph algorithms Structure Max-flow problem Recap augmenting path algorithms Push relabel algorithm Pseudocode Example Prove Run-time
3
Max-flow problem Maximum flow problem Intuition: Given a network of pipes and a source and sink, how much water can be transported from source to sink?
4
Max-flow problem Bipartite graphs: Model relations between two classes of objects Examples Boys and girls: “boy x likes girl y” A B
5
Max-flow problem Bipartite graphs: Model relations between two classes of objects Examples Boys and girls: “boy x likes girl y” Players and clubs: “player x wants to play in club y” A B
6
Max-flow problem Bipartite graphs: Model relations between two classes of objects Examples Boys and girls: “boy x likes girl y” Players and clubs: “player x wants to play in club y” Employees and jobs: “employee x can perform job y” A B
7
Max-flow problem Maximum flow problem Input: A graph with edge capacities c ij and a source s and sink t Output: The maximum flow f ij satisfying the flow constraints Flow constraints 0 ≤ f ij ≤ c ij “flow is within capacity” Σ k f ki = Σ k f ik for all i ≠ s, t “flow in = flow out” s = 0 t = 5 1 2 3 4 c 01 c 02 c 12 c 13 c 14 c 24 c 35 c 45 c 43
8
Augmenting path algorithm Idea: Find path from s to t and increase flow on the entire path s = 0 t = 5 1 2 3 4 0/3 0/2 0/1 0/2 0/3 0/2 0/1
9
Augmenting path algorithm Idea: Find path from s to t and increase flow on the entire path s = 0 t = 5 1 2 3 4 0/3 0/2 0/1 0/2 0/3 0/2 0/1
10
Augmenting path algorithm Idea: Find path from s to t and increase flow on the entire path s = 0 t = 5 1 2 3 4 2/3 0/3 2/2 0/2 0/1 2/2 0/3 2/2 0/1
11
Augmenting path algorithm Idea: Find path from s to t and increase flow on the entire path s = 0 t = 5 1 2 3 4 2/3 0/2 2/2 0/1 2/2 2/3 2/2 0/1
12
Augmenting path algorithm Idea: Find path from s to t and increase flow on the entire path s = 0 t = 5 1 2 3 4 3/3 2/3 0/2 2/2 1/1 2/2 3/3 2/2 1/1 Finish: no augmenting path left
13
Max-Flow idea General idea: The flow is optimal if there’s no path between s and t Graph approach: DFS ➨ Ford-Fulkerson algorithm with O(E f*) running time BFS ➨ Edmonds-Karp algorithm with O(V E 2 ) running time Without searching for path Push-relabel algorithm ➨ O(V 2 E)
14
Push-relabel approach
15
Pseudocode Pseudo-code: h[s] = |V| For each v V – {s} do h[v] = 0 For each (s,v) E do f(s,v) = c(s,v) While f is not feasible flow If there’s a vertex v V – {s,t} and a vertex w V with e(v) > 0and h[v] > h[w] and c’(v,w) > 0 Push min(c’(v,w), e(v)) over edge (v,w) Else h[v] = h[v] +1
16
Example HeightExcess flow 11 10 9 8 7 6s 5 4 3 2 1 01 2 3 4 t1 2 3 4 s = 0 t = 5 1 2 3 4 0/3 0/2 0/1 0/2 0/3 0/2 0/1
17
Example s = 0 t = 5 1 2 3 4 3/3 0/2 0/1 0/2 0/3 0/2 0/1 HeightExcess flow 11 10 9 8 7 6s 5 4 31 2 2 1 01 2 3 4 t3 4
18
Example s = 0 t = 5 1 2 3 4 3/3 0/2 0/1 0/2 0/3 0/2 0/1 HeightExcess flow 11 10 9 8 7 6s 5 4 31 2 2 11 02 3 4 t3 4
19
Example s = 0 t = 5 1 2 3 4 3/3 0/2 2/2 0/1 0/2 0/3 0/2 0/1 HeightExcess flow 11 10 9 8 7 6s 5 4 32 23 111 02 3 4 t4
20
Example s = 0 t = 5 1 2 3 4 3/3 0/2 2/2 1/1 0/2 0/3 0/2 0/1 HeightExcess flow 11 10 9 8 7 6s 5 4 32 23 114 02 3 4 t1
21
Example s = 0 t = 5 1 2 3 4 3/3 0/2 2/2 1/1 0/2 0/3 0/2 0/1 HeightExcess flow 11 10 9 8 7 6s 5 4 32 23 11 24 03 4 t1
22
Example s = 0 t = 5 1 2 3 4 3/3 0/2 2/2 1/1 2/2 0/3 0/2 0/1 HeightExcess flow 11 10 9 8 7 6s 5 4 34 23 11 22 03 4 t1
23
Example s = 0 t = 5 1 2 3 4 3/3 0/2 2/2 1/1 2/2 0/3 0/2 0/1 HeightExcess flow 11 10 9 8 7 6s 5 4 34 223 112 03 4 t1
24
Example s = 0 t = 5 1 2 3 4 3/3 0/2 2/2 1/1 2/2 0/3 0/2 0/1 HeightExcess flow 11 10 9 8 7 6s 5 4 324 23 112 03 4 t1
25
Example s = 0 t = 5 1 2 3 4 3/3 0/2 2/2 1/1 2/2 0/3 0/2 0/1 HeightExcess flow 11 10 9 8 7 6s 5 42 34 23 112 03 4 t1
26
Example s = 0 t = 5 1 2 3 4 3/3 0/2 2/2 1/1 2/2 0/3 0/2 0/1 HeightExcess flow 11 10 9 8 7 6s 52 4 34 23 112 03 4 t1
27
Example s = 0 t = 5 1 2 3 4 3/3 0/2 2/2 1/1 2/2 0/3 0/2 0/1 HeightExcess flow 11 10 9 8 7 6s 2 5 4 34 23 112 03 4 t1
28
Example s = 0 t = 5 1 2 3 4 3/3 0/2 2/2 1/1 2/2 0/3 0/2 0/1 HeightExcess flow 11 10 9 8 72 6s 5 4 34 23 112 03 4 t1
29
Example s = 0 t = 5 1 2 3 4 3/3 2/3 0/2 2/2 1/1 2/2 0/3 0/2 0/1 HeightExcess flow 11 10 9 8 72 6s 5 4 34 23 11 03 4 t1 2
30
Example s = 0 t = 5 1 2 3 4 3/3 2/3 0/2 2/2 1/1 2/2 0/3 0/2 0/1 HeightExcess flow 11 10 9 8 72 6s 5 4 34 23 11 3 04 t1 2
31
Example s = 0 t = 5 1 2 3 4 3/3 2/3 0/2 2/2 1/1 2/2 2/3 0/2 0/1 HeightExcess flow 11 10 9 8 72 6s 5 4 34 2 11 3 04 t1 2 3
32
Example s = 0 t = 5 1 2 3 4 3/3 2/3 0/2 2/2 1/1 2/2 2/3 0/2 0/1 HeightExcess flow 11 10 9 8 72 6s 5 4 34 2 11 3 4 0t1 2 3
33
Example s = 0 t = 5 1 2 3 4 3/3 2/3 0/2 2/2 1/1 2/2 2/3 2/2 0/1 HeightExcess flow 11 10 9 8 72 6s 5 4 3 2 11 3 44 0t1 2 3
34
Example s = 0 t = 5 1 2 3 4 3/3 2/3 0/2 2/2 1/1 2/2 2/3 2/2 0/1 HeightExcess flow 11 10 9 8 72 6s 5 4 3 24 11 34 0t1 2 3
35
Example s = 0 t = 5 1 2 3 4 3/3 2/3 0/2 2/2 1/1 2/2 2/3 2/2 1/1 HeightExcess flow 11 10 9 8 72 6s 5 4 3 24 11 33 0t1 2 4
36
Example s = 0 t = 5 1 2 3 4 3/3 2/3 0/2 2/2 1/1 2/2 3/3 2/2 1/1 HeightExcess flow 11 10 9 8 72 6s 5 4 3 24 11 3 0t1 2 3 4
37
Comparison s = 0 t = 5 1 2 3 4 3/3 2/3 0/2 2/2 1/1 2/2 3/3 2/2 1/1 s = 0 t = 5 2 4 3/3 2/3 0/2 1/1 2/2 3/3 2/2 1/1
38
Prove NodeExcess flow 0-3 13 20 30 s = 0 1 t=3 2 3/3 0/2 0/1
39
Prove s = 0 t = 5 1 2 3 4 3/3 0/2 0/1 0/2 0/3 0/2 0/1
40
Prove 0 1 2
41
Run time
42
Run time 2
43
Run time comparison Ford-Fulkinson s = 0 1 2 0/1000 0/1 0/1000
44
Run time comparison Ford-Fulkinson s = 0 1 2 0/1000 0/1 0/1000
45
Run time comparison Ford-Fulkinson s = 0 1 2 1/1000 0/1000 1/1 0/1000 1/1000
46
Run time comparison Ford-Fulkinson s = 0 1 2 1/1000 0/1000 1/1 0/1000 1/1000
47
Run time comparison Ford-Fulkinson s = 0 1 2 1/1000 0/1 1/1000
48
Run time comparison Ford-Fulkinson s = 0 1 2 1/1000 0/1 1/1000
49
Run time comparison Ford-Fulkinson s = 0 1 2 2/1000 1/1000 1/1 1/1000 2/1000
50
Run time comparison Ford-Fulkinson s = 0 1 2 2/1000 1/1000 1/1 1/1000 2/1000
51
Run time comparison Ford-Fulkinson s = 0 1 2 2/1000 0/1 2/1000
52
Run time comparison Ford-Fulkinson s = 0 1 2 2/1000 0/1 2/1000
53
Run time comparison Ford-Fulkinson s = 0 1 2 3/1000 2/1000 1/1 2/1000 3/1000
54
Run time comparison Ford-Fulkinson s = 0 1 2 3/1000 2/1000 1/1 2/1000 3/1000
55
Run time comparison Ford-Fulkinson s = 0 1 2 3/1000 0/1 3/1000
56
Run time comparison Ford-Fulkerson Edmonds-Karp s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 0/1000 0/1 0/1000
57
Run time comparison Ford-Fulkerson Edmonds-Karp s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 0/1000 0/1 0/1000
58
Run time comparison Ford-Fulkerson Edmonds-Karp s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1000 0/1 1000/1000 0/1000
59
Run time comparison Ford-Fulkerson Edmonds-Karp s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1000 0/1 1000/1000 0/1000
60
Run time comparison Ford-Fulkerson Edmonds-Karp s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 1000/1000
61
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 0/1000 0/1 0/1000
62
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 0/1000
63
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 0/1000
64
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 1/1 0/1000
65
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 1/1 999/1000 0/1000
66
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 1/1 999/1000 0/1000
67
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 1/1 999/1000 1000/1000
68
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 999/1000 1000/1000
69
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 999/1000 1000/1000
70
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 1000/1000
71
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 1000/1000
72
Run time comparison s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 1000/1000 s = 0 1 2 1000/1000 0/1 1000/1000
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.