1 of 39

Lecture 21

Wrapping up Max Flow �& Intro to P, NP, and computational hardness

CSE 421 Autumn 2026

1

2 of 39

Max Flow algorithms

For integer capacities:

Original Ford-Fulkerson: runtime

    • Pick any augmenting path

“Capacity-scaling” Ford-Fulkerson: runtime

    • Look for augmenting paths with high bottleneck capacity first

2

For non-integer capacities:

Edmonds-Karp: runtime

    • Pick the shortest augmenting path (in terms of # of edges)

3 of 39

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.

4 of 39

Edmonds-Karp algorithm

  • Initialize and
  • While there is a path in :
    • Pick the shortest path (# of edges)
    • Compute bottleneck capacity and update by augmenting along at capacity . Update .
  • Output resulting flow .

4

How to find the shortest path?

Recall: BFS finds the shortest path! (vertices are discovered in order of distance from the source)

5 of 39

Edmonds-Karp algorithm

  • Initialize and
  • While there is a path in :
    • Run BFS to find shortest path (# of edges)
    • Compute bottleneck capacity and update by augmenting along at capacity . Update .
  • Output resulting flow .

5

Claim: Only iterations are needed to find the max flow!

6 of 39

Edmonds-Karp algorithm

  • It suffices to show that each edge can only be the bottleneck in at most augmenting paths. Since there are edges, this would yield a max of iterations.
  • Key idea: show that each time an edge is the bottleneck in a shortest path, the distance from to one of its endpoints (in the residual graph) has increased by at least 2.

6

Claim: Only iterations are needed to find the max flow.

Proof ideas:

7 of 39

Max Flow algorithms

For integer capacities:

Original Ford-Fulkerson: runtime

    • Pick any augmenting path

“Capacity-scaling” Ford-Fulkerson: runtime

    • Look for augmenting paths with high bottleneck capacity first

Chen, Li, Liu, Peng, Probst Gutenberg, Sachdeva [2022!]: runtime

7

For non-integer capacities:

Edmonds-Karp: runtime

    • Pick the shortest augmenting path (in terms of # of edges)

8 of 39

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 .

    • is a trivial vertex cover for .

Input: An undirected graph

Output: A minimal vertex cover for .

​

  • Min Vertex Cover is a -complete problem
  • However, Min Vertex Cover on bipartite graphs can be solved efficiently!

8

9 of 39

Another application: minimum vertex cover

Bipartite graphs

9

The idea: given as input an undirected bipartite graph,

10 of 39

Another application: minimum vertex cover

Bipartite graphs

10

The idea: given as input an undirected bipartite graph, generate the following flow network:

11 of 39

Another application: minimum vertex cover

Bipartite graphs

11

The idea: given as input an undirected bipartite graph, generate the following flow network:

11

12 of 39

Another application: minimum vertex cover

Bipartite graphs

Consider the min-cut.

12

12

13 of 39

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

14 of 39

Another application: minimum vertex cover

Bipartite graphs

Consider the min-cut. Since middle edges have capacity , no middle edges cross the min-cut.

14

15 of 39

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 .

16 of 39

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

17 of 39

Baseball winner

  • Consider the following scenario: the team(s) that wins the most games overall is crowned the winner(s).
  • Midway through the season, we have the following win totals for the teams

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?

18 of 39

Baseball winner

  • Best case is Mariners win all of their games — 82 wins. �We should assume that.
  • Still, it depends also on the games between the other teams. How do we algorithmically decide if mariners can win?
  • In order to win or tie, Mariners must have a run total at least as high as every other team.

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!

19 of 39

Baseball winner

  • Best case is Mariners win all of their games — 82 wins. �We should assume that.
  • Still, it depends also on the games between the other teams. How do we algorithmically decide if mariners can win?
  • In order to win or tie, Mariners must have a run total at least as high as every other team.

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

—

20 of 39

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?

21 of 39

Baseball winner

  • If there was a way that the games could play out such that no team got wins then there would be a flow of value in this network.
  • Is there such a flow?

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

—

22 of 39

Baseball winner

  • If there was a way that the games could play out such that no team got wins then there would be a flow of value in this network.
  • No, the min cut equals = 10

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

—

23 of 39

Baseball winner

  • Even though no team has won > 82 games yet, this proves that the Mariners cannot win/tie for 1st.
  • A clever way to get to the answer without exploring all possible game outcomes

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

—

24 of 39

P vs NP, and problems that are just too hard

24

25 of 39

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.

    • Input: Program code.
    • Output: Whether the program terminates or runs forever.

25

Theorem [Turing, 1936]: There is no algorithm for solving the halting problem.

We say that the halting problem is undecidable.

26 of 39

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 !

27 of 39

Decision problems

Definition: A decision problem is any problem which has a boolean (yes vs. no) answer.

27

Examples:

    • Input: . Output: Does a graph have a vertex cover of size?
    • Input: . Output: Is there an MST of weight?
    • Input: Boolean circuit . Output: Is there an such that ?
    • Input: . Output: Is there a valid Knapsack of weight and value?
    • Input: Sudoku problem. Output: Is there a solution to this problem?
    • Input: . Output: Is there a max flow of size?

28 of 39

The class

Definition: An algorithm runs in time if, for every input , terminates in at most “steps”.

    • An algorithm runs in polynomial time if for some constant
    • We say a decision problem can be solved in polynomial time if there is a polynomial-time algorithm that solves it.

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

29 of 39

The class

Some of the problems in :

    • Input: . Output: Is there a path to of length?
    • Input: . Output: Is there a max flow of size?
    • Input: matrices . Output: If .
    • Input: expressed in binary. Output: if is prime.
    • And most of the problems we saw in this class..

29

30 of 39

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.

31 of 39

Examples of problems in

Factoring

  • Proof: is the prime factor.
  • Verifier: :
    • Check if and divides . Output “yes” if it does, and “no” otherwise.

31

Input: an integer (expressed in binary), and another integer .

Output: “yes” if has a prime factor , and “no” otherwise.

32 of 39

Examples of problems in

Knapsack

  • Proof: is the list of items to include.
  • Verifier: :
    • Check if the total weight of items in is at most and the total value is at least .

32

Input: .

Output: “yes” if there is a valid Knapsack of weight and value, and “no” otherwise.

33 of 39

Examples of problems in

k-coloring

  • Proof: is the coloring itself (i.e. an assignment of a color to each vertex)
  • Verifier: :
    • Check that is a valid coloring. If so, output “yes”. Otherwise “no”.

33

Input: A graph .

Output: “yes” if there is a valid -coloring, and “no” otherwise.

34 of 39

Examples of problems in

3SAT

  • Proof: Let simply be such that .
  • Verifier: :
    • Check that . If so, output “yes”. Otherwise “no”.

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

35 of 39

Examples of problems in

Min Cut

  • Proof: describes the vertices in for an s-t cut
  • Verifier: :
    • Check that describes a valid s-t cut.
    • Compute,
    • Check if

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?

36 of 39

Examples of problems in

Min Cut

  • Proof: empty string
  • Verifier: :
    • Compute min cut using Edmonds-Karp flow algorithm.
    • Compute,
    • Check if .

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.

37 of 39

and

  • : decision problems with a poly-time algorithm
  • : decision problems with a poly-time verifier
  • : decision problems with a exp-time algorithm

37

Theorem:

Theorem:

by the previous slide

Proof:

38 of 39

and

  • : decision problems with a poly-time algorithm
  • : decision problems with a poly-time verifier
  • : decision problems with a exp-time algorithm

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..

39 of 39

The million dollar question: Is ?

  • Is the problem of deciding if something is true as easy as verifying a proof that it is true?
  • There is a $1 million bounty for solving the problem (in either direction!)

39

  • If yes: There is a poly-time algorithm for every problem
  • If no: No efficient/poly-time algorithm for some problems such as 3-coloring, Traveling Salesman, 3SAT, Knapsack, Vertex Cover..