Honors Track: Competitive Programming & Problem Solving Push-Relabel Algorithm Claire Claassen
Graph algorithms Structure Max-flow problem Recap augmenting path algorithms Push relabel algorithm Pseudocode Example Prove Run-time
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?
Max-flow problem Bipartite graphs: Model relations between two classes of objects Examples Boys and girls: “boy x likes girl y” A B
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
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
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 = c 01 c 02 c 12 c 13 c 14 c 24 c 35 c 45 c 43
Augmenting path algorithm Idea: Find path from s to t and increase flow on the entire path s = 0 t = /3 0/2 0/1 0/2 0/3 0/2 0/1
Augmenting path algorithm Idea: Find path from s to t and increase flow on the entire path s = 0 t = /3 0/2 0/1 0/2 0/3 0/2 0/1
Augmenting path algorithm Idea: Find path from s to t and increase flow on the entire path s = 0 t = /3 0/3 2/2 0/2 0/1 2/2 0/3 2/2 0/1
Augmenting path algorithm Idea: Find path from s to t and increase flow on the entire path s = 0 t = /3 0/2 2/2 0/1 2/2 2/3 2/2 0/1
Augmenting path algorithm Idea: Find path from s to t and increase flow on the entire path s = 0 t = /3 2/3 0/2 2/2 1/1 2/2 3/3 2/2 1/1 Finish: no augmenting path left
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)
Push-relabel approach
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
Example HeightExcess flow s t s = 0 t = /3 0/2 0/1 0/2 0/3 0/2 0/1
Example s = 0 t = /3 0/2 0/1 0/2 0/3 0/2 0/1 HeightExcess flow s t3 4
Example s = 0 t = /3 0/2 0/1 0/2 0/3 0/2 0/1 HeightExcess flow s t3 4
Example s = 0 t = /3 0/2 2/2 0/1 0/2 0/3 0/2 0/1 HeightExcess flow s t4
Example s = 0 t = /3 0/2 2/2 1/1 0/2 0/3 0/2 0/1 HeightExcess flow s t1
Example s = 0 t = /3 0/2 2/2 1/1 0/2 0/3 0/2 0/1 HeightExcess flow s t1
Example s = 0 t = /3 0/2 2/2 1/1 2/2 0/3 0/2 0/1 HeightExcess flow s t1
Example s = 0 t = /3 0/2 2/2 1/1 2/2 0/3 0/2 0/1 HeightExcess flow s t1
Example s = 0 t = /3 0/2 2/2 1/1 2/2 0/3 0/2 0/1 HeightExcess flow s t1
Example s = 0 t = /3 0/2 2/2 1/1 2/2 0/3 0/2 0/1 HeightExcess flow s t1
Example s = 0 t = /3 0/2 2/2 1/1 2/2 0/3 0/2 0/1 HeightExcess flow s t1
Example s = 0 t = /3 0/2 2/2 1/1 2/2 0/3 0/2 0/1 HeightExcess flow s t1
Example s = 0 t = /3 0/2 2/2 1/1 2/2 0/3 0/2 0/1 HeightExcess flow s t1
Example s = 0 t = /3 2/3 0/2 2/2 1/1 2/2 0/3 0/2 0/1 HeightExcess flow s t1 2
Example s = 0 t = /3 2/3 0/2 2/2 1/1 2/2 0/3 0/2 0/1 HeightExcess flow s t1 2
Example s = 0 t = /3 2/3 0/2 2/2 1/1 2/2 2/3 0/2 0/1 HeightExcess flow s t1 2 3
Example s = 0 t = /3 2/3 0/2 2/2 1/1 2/2 2/3 0/2 0/1 HeightExcess flow s t1 2 3
Example s = 0 t = /3 2/3 0/2 2/2 1/1 2/2 2/3 2/2 0/1 HeightExcess flow s t1 2 3
Example s = 0 t = /3 2/3 0/2 2/2 1/1 2/2 2/3 2/2 0/1 HeightExcess flow s t1 2 3
Example s = 0 t = /3 2/3 0/2 2/2 1/1 2/2 2/3 2/2 1/1 HeightExcess flow s t1 2 4
Example s = 0 t = /3 2/3 0/2 2/2 1/1 2/2 3/3 2/2 1/1 HeightExcess flow s t
Comparison s = 0 t = /3 2/3 0/2 2/2 1/1 2/2 3/3 2/2 1/1 s = 0 t = /3 2/3 0/2 1/1 2/2 3/3 2/2 1/1
Prove NodeExcess flow s = 0 1 t=3 2 3/3 0/2 0/1
Prove s = 0 t = /3 0/2 0/1 0/2 0/3 0/2 0/1
Prove 0 1 2
Run time
Run time 2
Run time comparison Ford-Fulkinson s = /1000 0/1 0/1000
Run time comparison Ford-Fulkinson s = /1000 0/1 0/1000
Run time comparison Ford-Fulkinson s = /1000 0/1000 1/1 0/1000 1/1000
Run time comparison Ford-Fulkinson s = /1000 0/1000 1/1 0/1000 1/1000
Run time comparison Ford-Fulkinson s = /1000 0/1 1/1000
Run time comparison Ford-Fulkinson s = /1000 0/1 1/1000
Run time comparison Ford-Fulkinson s = /1000 1/1000 1/1 1/1000 2/1000
Run time comparison Ford-Fulkinson s = /1000 1/1000 1/1 1/1000 2/1000
Run time comparison Ford-Fulkinson s = /1000 0/1 2/1000
Run time comparison Ford-Fulkinson s = /1000 0/1 2/1000
Run time comparison Ford-Fulkinson s = /1000 2/1000 1/1 2/1000 3/1000
Run time comparison Ford-Fulkinson s = /1000 2/1000 1/1 2/1000 3/1000
Run time comparison Ford-Fulkinson s = /1000 0/1 3/1000
Run time comparison Ford-Fulkerson Edmonds-Karp s = /1000 0/1 1000/1000 s = /1000 0/1 0/1000
Run time comparison Ford-Fulkerson Edmonds-Karp s = /1000 0/1 1000/1000 s = /1000 0/1 0/1000
Run time comparison Ford-Fulkerson Edmonds-Karp s = /1000 0/1 1000/1000 s = /1000 0/1000 0/1 1000/1000 0/1000
Run time comparison Ford-Fulkerson Edmonds-Karp s = /1000 0/1 1000/1000 s = /1000 0/1000 0/1 1000/1000 0/1000
Run time comparison Ford-Fulkerson Edmonds-Karp s = /1000 0/1 1000/1000 s = /1000 0/1 1000/1000
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = /1000 0/1 1000/1000 s = /1000 0/1 1000/1000 s = /1000 0/1 0/1000
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = /1000 0/1 1000/1000 s = /1000 0/1 1000/1000 s = /1000 0/1 0/1000
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = /1000 0/1 1000/1000 s = /1000 0/1 1000/1000 s = /1000 0/1 0/1000
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = /1000 0/1 1000/1000 s = /1000 0/1 1000/1000 s = /1000 1/1 0/1000
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = /1000 0/1 1000/1000 s = /1000 0/1 1000/1000 s = /1000 1/1 999/1000 0/1000
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = /1000 0/1 1000/1000 s = /1000 0/1 1000/1000 s = /1000 1/1 999/1000 0/1000
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = /1000 0/1 1000/1000 s = /1000 0/1 1000/1000 s = /1000 1/1 999/ /1000
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = /1000 0/1 1000/1000 s = /1000 0/1 1000/1000 s = /1000 0/1 999/ /1000
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = /1000 0/1 1000/1000 s = /1000 0/1 1000/1000 s = /1000 0/1 999/ /1000
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = /1000 0/1 1000/1000 s = /1000 0/1 1000/1000 s = /1000 0/1 1000/1000
Run time comparison Ford-Fulkerson Edmonds-Karp Push-Relabel Algorithm s = /1000 0/1 1000/1000 s = /1000 0/1 1000/1000 s = /1000 0/1 1000/1000
Run time comparison s = /1000 0/1 1000/1000 s = /1000 0/1 1000/1000 s = /1000 0/1 1000/1000