Sub topic 9
Local Search: A 1/2-Approximation for Max-Cut
This chapter assumes you know basic graph terms (degree, edges), Big-O notation, and the definition of an approximation ratio for maximization problems from earlier chapters.
The Problem
In Max-Cut, you are given an undirected graph G = (V, E). You split the vertices into two sides, A and B. An edge is cut if its endpoints are on different sides. The goal is to maximize the number of cut edges. Max-Cut is NP-hard, but a very simple local search algorithm always cuts at least half of the optimum.
The Local Search Algorithm
Local search starts from any solution and keeps making small changes that improve it. It stops when no small change helps. For Max-Cut, the small change is moving one vertex to the other side.
- Put every vertex on side A.
- If some vertex has more neighbors on its own side than on the other side, move it to the other side.
- Repeat until no vertex qualifies. The resulting partition is a local optimum.
def local_search_maxcut(n, edges):
side = [0] * n
adj = [[] for _ in range(n)]
for u, v in edges:
adj[u].append(v)
adj[v].append(u)
improved = True
while improved:
improved = False
for v in range(n):
same = sum(1 for w in adj[v] if side[w] == side[v])
if same > len(adj[v]) - same:
side[v] ^= 1
improved = True
cut = sum(1 for u, v in edges if side[u] != side[v])
return side, cut
edges = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 0), (0, 2)]
print(local_search_maxcut(5, edges))This prints ([1, 0, 1, 0, 0], 4). The optimum for this graph is 5, for example with sides {0, 3} and {1, 2, 4}. A local optimum is not always a global optimum.
Why It Terminates in Polynomial Time
When vertex v flips, its same-side edges become cut and its cut edges become uncut. The algorithm flips only when same-side edges outnumber cut edges, so each flip raises the cut size by at least 1. The cut size can never go above |E|, so there are at most |E| flips. Each pass over the vertices costs O(n + m), which gives O(m(n + m)) time in total.
Why It Is a 1/2-Approximation
The proof uses the upper bound OPT ≤ |E|, since no cut can contain more edges than the graph has.
At a local optimum, every vertex v has at least half of its edges cut. Write c(v) for the number of cut edges at v:
- c(v) ≥ deg(v) / 2 for every v.
- Summing over all vertices counts each cut edge twice, so 2·|cut| = Σ c(v) ≥ Σ deg(v) / 2 = |E|.
- So |cut| ≥ |E| / 2 ≥ OPT / 2.
| Quantity | Value in the example | Column | Column |
|---|---|---|---|
| \ | E\ | (upper bound on OPT) | 6 |
| OPT | 5 | ||
| Local search cut | 4 | ||
| Guaranteed minimum (\ | E\ | / 2) | 3 |
Common Errors
- Treating the local optimum as the true optimum. The example above shows a gap.
- Comparing the result with OPT directly. The proof compares it with |E|, a bound you can compute.
- Assuming the weighted version runs in polynomial time without the ε-threshold.
Exercise
On a complete graph with 4 vertices (6 edges), local search ends with sides {0, 1} and {2, 3}. Is this a local optimum, how many edges does it cut, and how does this compare with the guaranteed bound?
Show answer
Each vertex has 1 neighbor on its own side and 2 on the other side, so no flip helps and the partition is a local optimum. It cuts 2 × 2 = 4 edges, which is more than the guaranteed |E|/2 = 3. It is also optimal, because a 1–3 split cuts only 3 edges.
Exercise
Why does every flip in the unweighted algorithm increase the cut by at least 1, and why does that give a polynomial running time?
Show answer
A flip happens only when v has more same-side neighbors (s) than cut neighbors (d). After the flip, s edges become cut and d become uncut, so the gain is s − d ≥ 1. The cut size is an integer between 0 and |E|, so there are at most |E| flips, each found in O(n + m) time.