Sub topic 9
Local Search: A 1/2-Approximation for Max-Cut
This chapter assumes you know the approximation-ratio definition from earlier chapters, basic graph terms (degree, neighbors, edge sets), and the idea of bounding the unknown optimum to prove a guarantee. The code uses only plain Python.
Every algorithm so far built its solution in a single pass, either greedily or by a combinatorial construction. Local search works differently. It starts from any feasible solution and repeatedly makes a small change that improves it. It stops when no small change helps. The solution it returns is a local optimum, and the analysis shows that every local optimum is good enough.
The Max-Cut Problem
A cut of an undirected graph G = (V, E) is a partition of the vertices into two sets S and V \ S. An edge crosses the cut if its endpoints lie on different sides. The size of the cut is the number of crossing edges. In the weighted version it is their total weight. The Max-Cut problem asks for a cut of maximum size.
Min-Cut can be solved in polynomial time with max-flow. Max-Cut is NP-hard, and its decision version was on Karp's original list of 21 NP-complete problems. Max-Cut is a maximization problem, so a 1/2-approximation must return a cut of size at least OPT/2.
The Single-Flip Neighborhood
A local search algorithm needs a neighborhood, which is the set of solutions reachable by one small move. For Max-Cut the natural move is to flip one vertex to the other side.
Look at a vertex v. Call its neighbors on the same side its same edges and its neighbors on the other side its cross edges. Flipping v turns every same edge into a cross edge and every cross edge into a same edge. Edges not touching v are unaffected. The cut therefore changes by exactly
gain(v) = same(v) − cross(v).
A flip helps when same(v) > cross(v), which means v has more neighbors on its own side than across.
Implementation
def local_search_maxcut(n, edges, side=None):
adj = [[] for _ in range(n)]
for u, v in edges:
adj[u].append(v)
adj[v].append(u)
side = [0] * n if side is None else list(side)
flips = 0
improved = True
while improved:
improved = False
for v in range(n):
same = sum(1 for w in adj[v] if side[w] == side[v])
cross = len(adj[v]) - same
if same > cross:
side[v] = 1 - side[v]
flips += 1
improved = True
cut = sum(1 for u, v in edges if side[u] != side[v])
return side, cut, flips
cycle4 = [(0, 1), (1, 2), (2, 3), (3, 0)]
print(local_search_maxcut(4, cycle4)) # ([1, 0, 1, 0], 4, 2)
print(local_search_maxcut(4, cycle4, [0, 0, 1, 1])) # ([0, 0, 1, 1], 2, 0)
k4 = [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]
print(local_search_maxcut(4, k4)) # ([1, 1, 0, 0], 4, 2)The code assumes a simple graph with no self-loops and no parallel edges. On the 4-cycle, starting with every vertex on side 0, the algorithm flips vertex 0 and then vertex 2, and it finds the optimal cut of 4. Started from [0, 0, 1, 1], it makes no flips at all and returns a cut of 2. Both outputs are local optima. Only the first one is globally optimal.
Why It Terminates in Polynomial Time
In the unweighted case each flip raises the cut size by at least 1. The cut size is between 0 and |E|, so the algorithm performs at most |E| flips. Each pass of the outer loop either flips at least one vertex or ends the algorithm, so there are at most |E| + 1 passes. A pass computes same for every vertex, which touches each edge twice, so it costs O(n + m). The total running time is O(m(n + m)), which is polynomial.
This argument is the standard potential-function argument for local search. You need a quantity that improves by a fixed amount on every move and is bounded in range. Here the cut size itself plays that role.
The Approximation Guarantee
The proof uses the trivial upper bound OPT ≤ |E|, since no cut can contain more edges than the graph has.
When the algorithm stops, no vertex has an improving flip. So for every vertex v,
cross(v) ≥ same(v), which means cross(v) ≥ deg(v)/2.
Sum this inequality over all vertices. Each crossing edge is counted once at each endpoint, so the sum of cross(v) equals 2·|cut|. The sum of degrees equals 2|E|. That gives
2·|cut| ≥ (1/2)·2|E|, so |cut| ≥ |E|/2 ≥ OPT/2.
Every local optimum is therefore a 1/2-approximation. The guarantee is a property of the stopping condition alone. It does not depend on the starting partition or on the order in which vertices are scanned.
The Bound Is Tight for Local Search
The second run on the 4-cycle is a worst case. With S = {0, 1}, every vertex has one neighbor on its side and one across, so no flip helps. The cut has 2 edges, while S = {0, 2} cuts all 4. The ratio is exactly 1/2, so the analysis cannot be improved for the single-flip neighborhood.
The Weighted Case and Its Pitfall
With edge weights, define gain(v) as the total weight of same edges minus the total weight of cross edges. The same summation argument gives w(cut) ≥ W/2, where W is the total edge weight, so every local optimum is still a 1/2-approximation.
The running time argument breaks, though. A flip may raise the cut by a tiny amount, and the weights can be exponentially large in the input size. Finding a single-flip local optimum of weighted Max-Cut is PLS-complete (Schäffer and Yannakakis, 1991), and there are instances where improving-flip sequences take exponentially many steps.
The standard fix accepts only big improvements. A flip is performed only if it raises the cut weight by at least (2ε/n)·w(cut). Kleinberg and Tardos show that this version stops after O((n/ε)·log W) flips and returns a cut of weight at least OPT/(2 + ε). You give up an arbitrarily small amount of the guarantee in exchange for a polynomial bound on the running time. The same trade appears in many local search algorithms.
| Variant | Stopping rule | Flips | Guarantee | Column | Column |
|---|---|---|---|---|---|
| Unweighted, any improving flip | No vertex has gain > 0 | at most \ | E\ | ≥ OPT/2 | |
| Weighted, any improving flip | No vertex has gain > 0 | can be exponential | ≥ OPT/2 | ||
| Weighted, big-improvement flips | No vertex has gain ≥ (2ε/n)·w(cut) | O((n/ε) log W) | ≥ OPT/(2 + ε) |
Common Errors
- Updating the cut by recounting edges. Updating it by gain(v) after each flip is enough, and it is cheaper. Recounting every edge costs O(m) per flip.
- Assuming the starting point matters for the guarantee. It affects which local optimum you reach and how fast, but the 1/2 bound holds for all of them.
- Carrying the unweighted running-time argument over to weights. The "+1 per flip" step relies on integer edge counts.
- Treating a local optimum as a global one. The 4-cycle example shows that these can differ by a factor of 2.
How It Compares
A uniformly random partition also gives an expected cut of |E|/2. By linearity of expectation, each edge crosses with probability 1/2. Local search gives the same bound deterministically, with no derandomization needed. Goemans and Williamson's semidefinite programming algorithm achieves about 0.878. Under the Unique Games Conjecture no polynomial-time algorithm does better. Unconditionally, Håstad showed that approximating Max-Cut within a factor better than 16/17 is NP-hard, so Max-Cut has no PTAS unless P = NP.
Exercise
Run the single-flip local search on the path 0–1–2 (edges (0,1) and (1,2)), starting from all vertices on side 0 and scanning vertices in order 0, 1, 2. List each flip, then state the final cut and whether it is optimal.
Show answer
Vertex 0 has same = 1 and cross = 0, so it flips, giving sides [1, 0, 0]. Vertex 1 has neighbor 0 across and neighbor 2 on its side, so same = cross = 1 and it does not flip. Vertex 2 has same = 1 and cross = 0, so it flips, giving [1, 0, 1]. The next pass finds no improving flips. The cut contains both edges, which is optimal.
Exercise
Prove that at a local optimum of single-flip local search, every vertex v of degree at least 1 has at least ceil(deg(v)/2) of its edges in the cut. Then explain why this does not by itself give a ratio better than 1/2 on the 4-cycle.
Show answer
At a local optimum, cross(v) ≥ same(v), and cross(v) + same(v) = deg(v). So cross(v) ≥ deg(v)/2, and since cross(v) is an integer, cross(v) ≥ ceil(deg(v)/2). On the 4-cycle every vertex has degree 2, so ceil(2/2) = 1 cut edge per vertex. Summing over vertices gives at least 4/2 = 2 cut edges, which is exactly the bad local optimum with S = {0, 1}, at half the optimum of 4.
Exercise
Change the program so that it keeps the cut size up to date with each flip instead of recounting edges at the end. What is the change in the cut when vertex v flips?
Show answer
Start with cut = number of edges whose endpoints have different sides in the initial assignment. When v flips, add same − cross, using the values computed just before the flip. For example, insert cut += same - cross before side[v] = 1 - side[v], and remove the final recount. This works because flipping v changes only the status of edges incident to v.