Lecture 21
Wrapping up Max Flow �& Intro to P, NP, and computational hardness
CSE 421 Autumn 2026
1
Max Flow algorithms
For integer capacities:
Original Ford-Fulkerson: runtime
“Capacity-scaling” Ford-Fulkerson: runtime
2
For non-integer capacities:
Edmonds-Karp: runtime
Edmonds-Karp algorithm
3
Edmonds-Karp’s idea: pick the shortest augmenting path (in terms of # of edges)
Ford-Fulkerson gives a template: pick a path in the residual graph.
Recall..
Follows the Ford-Fulkerson template, but with a particular instantiation for how to pick augmenting paths.
Edmonds-Karp algorithm
4
How to find the shortest path?
Recall: BFS finds the shortest path! (vertices are discovered in order of distance from the source)
Edmonds-Karp algorithm
5
Claim: Only iterations are needed to find the max flow!
Edmonds-Karp algorithm
6
Claim: Only iterations are needed to find the max flow.
Proof ideas:
Max Flow algorithms
For integer capacities:
Original Ford-Fulkerson: runtime
“Capacity-scaling” Ford-Fulkerson: runtime
Chen, Li, Liu, Peng, Probst Gutenberg, Sachdeva [2022!]: runtime
7
For non-integer capacities:
Edmonds-Karp: runtime
Another application: minimum vertex cover
Definition: A subset of vertices is a vertex cover of an undirected graph iff every edge is touched by some vertex in .
Input: An undirected graph
Output: A minimal vertex cover for .
8
Another application: minimum vertex cover
Bipartite graphs
9
The idea: given as input an undirected bipartite graph,
Another application: minimum vertex cover
Bipartite graphs
10
The idea: given as input an undirected bipartite graph, generate the following flow network:
Another application: minimum vertex cover
Bipartite graphs
11
The idea: given as input an undirected bipartite graph, generate the following flow network:
11
Another application: minimum vertex cover
Bipartite graphs
Consider the min-cut.
12
12
Another application: minimum vertex cover
Bipartite graphs
Consider the min-cut. Since middle edges have capacity , no middle edges cross the min-cut.
13
13
Another application: minimum vertex cover
Bipartite graphs
Consider the min-cut. Since middle edges have capacity , no middle edges cross the min-cut.
14
Another application: minimum vertex cover
Bipartite graphs
Consider the min-cut. Since middle edges have capacity , no middle edges cross the min-cut.
The vertices of the original graph involved in the min-cut are a minimum-size set of vertices blocking all flow from to .
Another application: minimum vertex cover
Bipartite graphs
Consider the min-cut. Since middle edges have capacity , no middle edges cross the min-cut.
The vertices of the original graph involved in the min-cut are a minimum-size set of vertices blocking all flow from to . They also form a vertex cover!
Prove as an exercise
Baseball winner
17
Team | Wins | Games remaining vs Angels | Games remaining vs Rangers | Games remaining vs Athletics | Games remaining vs Mariners |
Angels | 81 | — | 5 | 4 | 3 |
Rangers | 80 | 5 | — | 3 | 4 |
Athletics | 69 | 4 | 3 | — | 5 |
Mariners | 70 | 3 | 4 | 5 | — |
Could the Mariners possibly win or tie for first?
Baseball winner
18
Team | Wins | Games remaining vs Angels | Games remaining vs Rangers | Games remaining vs Athletics | Games remaining vs Mariners |
Angels | 81 | — | 5 | 4 | 3 |
Rangers | 80 | 5 | — | 3 | 4 |
Athletics | 69 | 4 | 3 | — | 5 |
Mariners | 70 | 3 | 4 | 5 | — |
We can build the right flow network!
Baseball winner
19
Team | Wins | Games remaining vs Angels | Games remaining vs Rangers | Games remaining vs Athletics | Games remaining vs Mariners |
Angels | 81 | — | 5 | 4 | 3 |
Rangers | 80 | 5 | — | 3 | 4 |
Athletics | 69 | 4 | 3 | — | 5 |
Mariners | 70 | 3 | 4 | 5 | — |
Baseball winner
20
Team | Wins | Games remaining vs Angels | Games remaining vs Rangers | Games remaining vs Athletics | Games remaining vs Mariners |
Angels | 81 | — | 5 | 4 | 3 |
Rangers | 80 | 5 | — | 3 | 4 |
Athletics | 69 | 4 | 3 | — | 5 |
Mariners | 70 | 3 | 4 | 5 | — |
How to know if the mariners can win?
Baseball winner
21
Team | Wins | Games remaining vs Angels | Games remaining vs Rangers | Games remaining vs Athletics | Games remaining vs Mariners |
Angels | 81 | — | 5 | 4 | 3 |
Rangers | 80 | 5 | — | 3 | 4 |
Athletics | 69 | 4 | 3 | — | 5 |
Mariners | 70 | 3 | 4 | 5 | — |
Baseball winner
22
Team | Wins | Games remaining vs Angels | Games remaining vs Rangers | Games remaining vs Athletics | Games remaining vs Mariners |
Angels | 81 | — | 5 | 4 | 3 |
Rangers | 80 | 5 | — | 3 | 4 |
Athletics | 69 | 4 | 3 | — | 5 |
Mariners | 70 | 3 | 4 | 5 | — |
Baseball winner
23
Team | Wins | Games remaining vs Angels | Games remaining vs Rangers | Games remaining vs Athletics | Games remaining vs Mariners |
Angels | 81 | — | 5 | 4 | 3 |
Rangers | 80 | 5 | — | 3 | 4 |
Athletics | 69 | 4 | 3 | — | 5 |
Mariners | 70 | 3 | 4 | 5 | — |
P vs NP, and problems that are just too hard
24
When does a problem not have an efficient algorithm?
Let’s back up. Are there problems that don’t have any algorithms?
Yes! One example is the halting problem.
25
Theorem [Turing, 1936]: There is no algorithm for solving the halting problem.
We say that the halting problem is undecidable.
When does a problem not have an efficient algorithm?
Let’s restrict to problems that are decidable, i.e. there is some algorithm that always outputs the correct answer. Is it necessary that those algorithms are efficient?
26
Theorem (“time hierarchy”): There exist decision problems that can be solved in exponential time but cannot be solved in polynomial time.
Are there (decision) problems that can be solved in exponential time, but not in polynomial time?
These are “artificial” problems. The theorem doesn’t say anything about “natural”problems that we care about, e.g. Knapsack, Traveling Salesman, 3-SAT, ..
In fact, there are decision problems that can be solved in time but not in time !
Decision problems
Definition: A decision problem is any problem which has a boolean (yes vs. no) answer.
27
Examples:
The class
Definition: An algorithm runs in time if, for every input , terminates in at most “steps”.
Definition: is the class of decision problems that can be solved in polynomial time.
Definition: is the class of decision problems that can be solved in exponential time, i.e. in time = for some positive integer .
28
Roughly speaking, we take to be the class of (decision) problems that can be solved “efficiently”.
on every input
The class
Some of the problems in :
29
The class
Definition: An algorithm is a verifier for the problem if, for every input , the answer is “yes” iff there exists a proof of length such that .
Definition: is the class of decision problems that have a polynomial-time verifier.
30
Informally: the class of problems for which “yes” inputs have an efficiently verifiable “proof”, and “no” inputs don’t.
Remark: stands for non-deterministic polynomial time.
Examples of problems in
Factoring
31
Input: an integer (expressed in binary), and another integer .
Output: “yes” if has a prime factor , and “no” otherwise.
Examples of problems in
Knapsack
32
Input: .
Output: “yes” if there is a valid Knapsack of weight and value, and “no” otherwise.
Examples of problems in
k-coloring
33
Input: A graph .
Output: “yes” if there is a valid -coloring, and “no” otherwise.
Examples of problems in
3SAT
34
Input: A 3-CNF formula .
Output: “yes” if there exists a such that . “No” otherwise.
e.g.
A 3-CNF is a function defined as an AND of ORs, where each OR acts on at most 3 variables (i.e. bits of the input) or their negations
Examples of problems in
Min Cut
35
Input: .
Output: “Yes” if there is a min cut of size, “no otherwise.
Can you think of a different verifier (and proof) for this problem?
Examples of problems in
Min Cut
36
Input: .
Output: “Yes” if there is a min cut of size, “no” otherwise.
Any problem in is also in : �the verifier can ignore the proof, and solve the problem by itself.
and
37
Theorem:
Theorem:
by the previous slide
Proof:
and
38
Theorem:
Theorem:
by the previous slide
Proof: If a problem is in , then one can always do a brute force search for a proof that is accepted by the verifier. Since the proof is required to be of length , this search can be done in time .
We don’t know if inclusions are strict..
The million dollar question: Is ?
39