Lecture 8
Greedy graph approximation algorithms (max-cut)
CSE 421 Autumn 2026
1
Previously…
2
Minimum spanning trees
Input: A connected graph , edge weights
Output: A tree , with , such that every vertex is connected and is minimized. This is called a minimum spanning tree.
3
Greedy Minimum MST algorithms
4
Build up the set of edges according to a simple rule.
Never go back and change.
Possible rules?
Prim’s algorithm
Kruskal’s algorithm
A unified argument for proving correctness
Of both Prim’s and Kruskal’s algorithm
Definition: An edge is safe for some subset of edges if there is some compatible cut such that is the minimum weight edge crossing the cut.
Theorem: Greedy algorithms that always choose edges that are safe for the current set of selected edges correctly compute an MST.
5
We proved this powerful theorem.
Then, all that was left to do was to argue that Prim’s and Kruskal’s always pick a safe edge.
Greedy algorithm proof strategies
6
What we did to prove correctness of greedy algorithm that adds safe edges.
Today
7
Greedy Minimum MST algorithms
8
Build up the set of edges according to a simple rule.
Never go back and change.
Possible rules?
Prim’s algorithm
Kruskal’s algorithm
Implementation of Prim’s & runtime
We need a data structure to quickly find the minimal-weight edge from the current vertex set to .
Similar to Dijkstra’s. We can use a priority queue (binary heap) keyed by, for each vertex , the weight of the minimum edge connecting to .
This allows us to efficiently:
Both of these operations can be done in time. So, with this implementation,�Prim’s runtime: .�
9
Greedy Minimum MST algorithms
10
Build up the set of edges according to a simple rule.
Never go back and change.
Possible rules?
Prim’s algorithm
Kruskal’s algorithm
Implementation of Kruskal’s & runtime
We need a data structure to quickly find minimal-weight edges that don’t create a cycle.
For this, we can use a “disjoint-set data structure” (also called union-find) to keep a partition of the vertex set into connected components based on the current edge set. ��So, initially, when the edge set is empty, each vertex is its own connected component. These components get merged as we add more edges.
The union-find data structure allows us to efficiently:
11
Implementation of Kruskal’s & runtime
The union-find data structure allows us to efficiently:
We can proceed as follows:
With union-find, checking and merging both take almost constant time, so the runtime of the algorithm is dominated by the sorting of the edges: .
12
Applications of MST
13
Greedy graph approximation algorithms
14
Maximizing bipartiteness
15
Why is it called MaxCut?
16
A proof that MaxCut is always
17
A proof that MaxCut is always
18
Finding a cut with crossing edges
We know a cut exists crossing edges. Can we find it efficiently?
First idea: based on the previous slide, we could pick a uniformly random color for each vertex.
Since the average number of edges crossing is , we should have at least a reasonable probability of getting a cut that has crossings?
19
This is not true :) (Think about why!)
If you are satisfied with , for some , then you can get a constant probability of that happening. But you can’t avoid a small loss.
Finding a cut with crossing edges
We know a cut exists crossing edges. Can we find it efficiently?
Second idea:
20
Finding a cut with crossing edges
We know a cut exists crossing edges. Can we find it efficiently?
Second idea: let’s use a greedy algorithm!
21
Algorithm overview: Color the first vertex as 0 (yellow). Then, for every future vertex , if has more 0 (yellow) neighbors than 1’s (blue), assign it the color 1 (blue), otherwise assign it 0 (yellow).
Finding a cut with crossing edges
We know a cut exists crossing edges. Can we find it efficiently?
Second idea: let’s use a greedy algorithm!
22
Algorithm overview: Color the first vertex as 0 (yellow). Then, for every future vertex , if has more 0 (yellow) neighbors than 1’s (blue), assign it the color 1 (blue), otherwise assign it 0 (yellow).
Finding a cut with crossing edges
We know a cut exists crossing edges. Can we find it efficiently?
Second idea: let’s use a greedy algorithm!
23
Algorithm overview: Color the first vertex as 0 (yellow). Then, for every future vertex , if has more 0 (yellow) neighbors than 1’s (blue), assign it the color 1 (blue), otherwise assign it 0 (yellow).
Finding a cut with crossing edges
We know a cut exists crossing edges. Can we find it efficiently?
Second idea: let’s use a greedy algorithm!
24
Algorithm overview: Color the first vertex as 0 (yellow). Then, for every future vertex , if has more 0 (yellow) neighbors than 1’s (blue), assign it the color 1 (blue), otherwise assign it 0 (yellow).
Finding a cut with crossing edges
We know a cut exists crossing edges. Can we find it efficiently?
Second idea: let’s use a greedy algorithm!
25
Algorithm overview: Color the first vertex as 0 (yellow). Then, for every future vertex , if has more 0 (yellow) neighbors than 1’s (blue), assign it the color 1 (blue), otherwise assign it 0 (yellow).
Finding a cut with crossing edges
We know a cut exists crossing edges. Can we find it efficiently?
Second idea: let’s use a greedy algorithm!
26
Algorithm overview: Color the first vertex as 0 (yellow). Then, for every future vertex , if has more 0 (yellow) neighbors than 1’s (blue), assign it the color 1 (blue), otherwise assign it 0 (yellow).
Finding a cut with crossing edges
We know a cut exists crossing edges. Can we find it efficiently?
Second idea: let’s use a greedy algorithm!
27
Algorithm overview: Color the first vertex as 0 (yellow). Then, for every future vertex , if has more 0 (yellow) neighbors than 1’s (blue), assign it the color 1 (blue), otherwise assign it 0 (yellow).
Finding a cut with crossing edges
We know a cut exists crossing edges. Can we find it efficiently?
Second idea: let’s use a greedy algorithm!
28
Algorithm overview: Color the first vertex as 0 (yellow). Then, for every future vertex , if has more 0 (yellow) neighbors than 1’s (blue), assign it the color 1 (blue), otherwise assign it 0 (yellow).
Finding a cut with crossing edges
We know a cut exists crossing edges. Can we find it efficiently?
Second idea: let’s use a greedy algorithm!
29
Algorithm overview: Color the first vertex as 0 (yellow). Then, for every future vertex , if has more 0 (yellow) neighbors than 1’s (blue), assign it the color 1 (blue), otherwise assign it 0 (yellow).
Here, 10 out of 14 edges are good.
What about in general?
Proof greedy algorithm gets at least
30
Proof:
Theorem: The greedy algorithm always produces a cut with crossing edges.
Proof greedy algorithm gets at least
31
Proof: Consider the set of edges used to determine the color of vertex .
Theorem: The greedy algorithm always produces a cut with crossing edges.
Proof greedy algorithm gets at least
32
Proof: Consider the set of edges used to determine the color of vertex . By choosing the color of to be the opposite of the majority of neighbors, at least half of the edges of will cross the cut.
Theorem: The greedy algorithm always produces a cut with crossing edges.
Proof greedy algorithm gets at least
33
Proof: Consider the set of edges used to determine the color of vertex . By choosing the color of to be the opposite of the majority of neighbors, at least half of the edges of will cross the cut.
Note that every edge is in exactly one set where is the later of its two vertices to be assigned a color.
Since and at least half of the edges of each cross the cut, then at least half the edges of cross the cut.
Theorem: The greedy algorithm always produces a cut with crossing edges.
Proof greedy algorithm gets at least
34
Theorem: The greedy algorithm always produces a cut with crossing edges.
We showed that the greedy algorithm finds a cut with at least crossings.
Does it actually do even better?
Greedy algorithm can be suboptimal
The greedy algorithm can be suboptimal and fail to find the max cut. One can design examples where it fails.
Consider this graph on vertices:
35
The greedy algorithm that explores vertices in the order that they are numbered colors as in the picture.
Greedy algorithm can be suboptimal
The greedy algorithm can be suboptimal and fail to find the max cut. One can design examples where it fails.
Consider this graph on vertices:
36
The greedy algorithm that explores vertices in the order that they are numbered colors as in the picture.
Greedy algorithm can be suboptimal
The greedy algorithm can be suboptimal and fail to find the max cut. One can design examples where it fails.
Consider this graph on vertices:
37
The greedy algorithm that explores vertices in the order that they are numbered colors as in the picture.
Greedy cut:
Optimal cut:
The ratio tends to 1/2!
If the rule breaks ties in favor of yellow
Color left half blue, and right half yellow
NP-completeness
38