Karger's algorithm

From HandWiki
Short description: Randomized algorithm for minimum cuts
A graph and two of its cuts. The dotted line in red is a cut with three crossing edges. The dashed line in green is a min-cut of this graph, crossing only two edges.

In computer science and graph theory, Karger's algorithm is a randomized algorithm to compute a minimum cut of a connected graph. It was invented by David Karger and first published in 1993.[1]

The idea of the algorithm is based on the concept of contraction of an edge [math]\displaystyle{ (u, v) }[/math] in an undirected graph [math]\displaystyle{ G = (V, E) }[/math]. Informally speaking, the contraction of an edge merges the nodes [math]\displaystyle{ u }[/math] and [math]\displaystyle{ v }[/math] into one, reducing the total number of nodes of the graph by one. All other edges connecting either [math]\displaystyle{ u }[/math] or [math]\displaystyle{ v }[/math] are "reattached" to the merged node, effectively producing a multigraph. Karger's basic algorithm iteratively contracts randomly chosen edges until only two nodes remain; those nodes represent a cut in the original graph. By iterating this basic algorithm a sufficient number of times, a minimum cut can be found with high probability.

The global minimum cut problem

Main page: Minimum cut

A cut [math]\displaystyle{ (S,T) }[/math] in an undirected graph [math]\displaystyle{ G = (V, E) }[/math] is a partition of the vertices [math]\displaystyle{ V }[/math] into two non-empty, disjoint sets [math]\displaystyle{ S\cup T= V }[/math]. The cutset of a cut consists of the edges [math]\displaystyle{ \{\, uv \in E \colon u\in S, v\in T\,\} }[/math] between the two parts. The size (or weight) of a cut in an unweighted graph is the cardinality of the cutset, i.e., the number of edges between the two parts,

[math]\displaystyle{ w(S,T) = |\{\, uv \in E \colon u\in S, v\in T\,\}|\,. }[/math]

There are [math]\displaystyle{ 2^{|V|} }[/math] ways of choosing for each vertex whether it belongs to [math]\displaystyle{ S }[/math] or to [math]\displaystyle{ T }[/math], but two of these choices make [math]\displaystyle{ S }[/math] or [math]\displaystyle{ T }[/math] empty and do not give rise to cuts. Among the remaining choices, swapping the roles of [math]\displaystyle{ S }[/math] and [math]\displaystyle{ T }[/math] does not change the cut, so each cut is counted twice; therefore, there are [math]\displaystyle{ 2^{|V|-1}-1 }[/math] distinct cuts. The minimum cut problem is to find a cut of smallest size among these cuts.

For weighted graphs with positive edge weights [math]\displaystyle{ w\colon E\rightarrow \mathbf R^+ }[/math] the weight of the cut is the sum of the weights of edges between vertices in each part

[math]\displaystyle{ w(S,T) = \sum_{uv\in E\colon u\in S, v\in T} w(uv)\,, }[/math]

which agrees with the unweighted definition for [math]\displaystyle{ w=1 }[/math].

A cut is sometimes called a “global cut” to distinguish it from an “[math]\displaystyle{ s }[/math]-[math]\displaystyle{ t }[/math] cut” for a given pair of vertices, which has the additional requirement that [math]\displaystyle{ s\in S }[/math] and [math]\displaystyle{ t\in T }[/math]. Every global cut is an [math]\displaystyle{ s }[/math]-[math]\displaystyle{ t }[/math] cut for some [math]\displaystyle{ s,t\in V }[/math]. Thus, the minimum cut problem can be solved in polynomial time by iterating over all choices of [math]\displaystyle{ s,t\in V }[/math] and solving the resulting minimum [math]\displaystyle{ s }[/math]-[math]\displaystyle{ t }[/math] cut problem using the max-flow min-cut theorem and a polynomial time algorithm for maximum flow, such as the push-relabel algorithm, though this approach is not optimal. Better deterministic algorithms for the global minimum cut problem include the Stoer–Wagner algorithm, which has a running time of [math]\displaystyle{ O(mn+n^2\log n) }[/math].[2]

Contraction algorithm

The fundamental operation of Karger’s algorithm is a form of edge contraction. The result of contracting the edge [math]\displaystyle{ e=\{u,v\} }[/math] is a new node [math]\displaystyle{ uv }[/math]. Every edge [math]\displaystyle{ \{w,u\} }[/math] or [math]\displaystyle{ \{w,v\} }[/math] for [math]\displaystyle{ w\notin\{u,v\} }[/math] to the endpoints of the contracted edge is replaced by an edge [math]\displaystyle{ \{w,uv\} }[/math] to the new node. Finally, the contracted nodes [math]\displaystyle{ u }[/math] and [math]\displaystyle{ v }[/math] with all their incident edges are removed. In particular, the resulting graph contains no self-loops. The result of contracting edge [math]\displaystyle{ e }[/math] is denoted [math]\displaystyle{ G/e }[/math].

The marked edge is contracted into a single node.

The contraction algorithm repeatedly contracts random edges in the graph, until only two nodes remain, at which point there is only a single cut.

The key idea of the algorithm is that it is far more likely for non min-cut edges than min-cut edges to be randomly selected and lost to contraction, since min-cut edges are usually vastly outnumbered by non min-cut edges. Subsequently, it is plausible that the min-cut edges will survive all the edge contraction, and the algorithm will correctly identify the min-cut edge.

Successful run of Karger’s algorithm on a 10-vertex graph. The minimum cut has size 3.
   procedure contract([math]\displaystyle{ G=(V,E) }[/math]):
   while [math]\displaystyle{ |V| \gt  2 }[/math]
       choose [math]\displaystyle{ e\in E }[/math] uniformly at random
       [math]\displaystyle{ G \leftarrow G/e }[/math]
   return the only cut in [math]\displaystyle{ G }[/math]

When the graph is represented using adjacency lists or an adjacency matrix, a single edge contraction operation can be implemented with a linear number of updates to the data structure, for a total running time of [math]\displaystyle{ O(|V|^2) }[/math]. Alternatively, the procedure can be viewed as an execution of Kruskal’s algorithm for constructing the minimum spanning tree in a graph where the edges have weights [math]\displaystyle{ w(e_i)=\pi(i) }[/math] according to a random permutation [math]\displaystyle{ \pi }[/math]. Removing the heaviest edge of this tree results in two components that describe a cut. In this way, the contraction procedure can be implemented like Kruskal’s algorithm in time [math]\displaystyle{ O(|E|\log |E|) }[/math].

The random edge choices in Karger’s algorithm correspond to an execution of Kruskal’s algorithm on a graph with random edge ranks until only two components remain.

The best known implementations use [math]\displaystyle{ O(|E|) }[/math] time and space, or [math]\displaystyle{ O(|E|\log |E|) }[/math] time and [math]\displaystyle{ O(|V|) }[/math] space, respectively.[1]

Success probability of the contraction algorithm

In a graph [math]\displaystyle{ G=(V,E) }[/math] with [math]\displaystyle{ n=|V| }[/math] vertices, the contraction algorithm returns a minimum cut with polynomially small probability [math]\displaystyle{ \binom{n}{2}^{-1} }[/math]. Recall that every graph has [math]\displaystyle{ 2^{n-1} -1 }[/math] cuts (by the discussion in the previous section), among which at most [math]\displaystyle{ \tbinom{n}{2} }[/math] can be minimum cuts. Therefore, the success probability for this algorithm is much better than the probability for picking a cut at random, which is at most [math]\displaystyle{ \frac{\tbinom{n}{2}}{2^{n-1} -1} }[/math].

For instance, the cycle graph on [math]\displaystyle{ n }[/math] vertices has exactly [math]\displaystyle{ \binom{n}{2} }[/math] minimum cuts, given by every choice of 2 edges. The contraction procedure finds each of these with equal probability.

To further establish the lower bound on the success probability, let [math]\displaystyle{ C }[/math] denote the edges of a specific minimum cut of size [math]\displaystyle{ k }[/math]. The contraction algorithm returns [math]\displaystyle{ C }[/math] if none of the random edges deleted by the algorithm belongs to the cutset [math]\displaystyle{ C }[/math]. In particular, the first edge contraction avoids [math]\displaystyle{ C }[/math], which happens with probability [math]\displaystyle{ 1-k/|E| }[/math]. The minimum degree of [math]\displaystyle{ G }[/math] is at least [math]\displaystyle{ k }[/math] (otherwise a minimum degree vertex would induce a smaller cut where one of the two partitions contains only the minimum degree vertex), so [math]\displaystyle{ |E|\geqslant nk/2 }[/math]. Thus, the probability that the contraction algorithm picks an edge from [math]\displaystyle{ C }[/math] is

[math]\displaystyle{ \frac{k}{|E|} \leqslant \frac{k}{nk/2} = \frac{2}{n}. }[/math]

The probability [math]\displaystyle{ p_n }[/math] that the contraction algorithm on an [math]\displaystyle{ n }[/math]-vertex graph avoids [math]\displaystyle{ C }[/math] satisfies the recurrence [math]\displaystyle{ p_n \geqslant \left( 1 - \frac{2}{n} \right) p_{n-1} }[/math], with [math]\displaystyle{ p_2 = 1 }[/math], which can be expanded as

[math]\displaystyle{ p_n \geqslant \prod_{i=0}^{n-3} \Bigl(1-\frac{2}{n-i}\Bigr) = \prod_{i=0}^{n-3} {\frac{n-i-2}{n-i}} = \frac{n-2}{n}\cdot \frac{n-3}{n-1} \cdot \frac{n-4}{n-2}\cdots \frac{3}{5}\cdot \frac{2}{4} \cdot \frac{1}{3} = \binom{n}{2}^{-1}\,. }[/math]

Repeating the contraction algorithm

10 repetitions of the contraction procedure. The 5th repetition finds the minimum cut of size 3.

By repeating the contraction algorithm [math]\displaystyle{ T = \binom{n}{2}\ln n }[/math] times with independent random choices and returning the smallest cut, the probability of not finding a minimum cut is

[math]\displaystyle{ \left[1-\binom{n}{2}^{-1}\right]^T \leq \frac{1}{e^{\ln n}} = \frac{1}{n}\,. }[/math]

The total running time for [math]\displaystyle{ T }[/math] repetitions for a graph with [math]\displaystyle{ n }[/math] vertices and [math]\displaystyle{ m }[/math] edges is [math]\displaystyle{ O(Tm) = O(n^2 m \log n) }[/math].

Karger–Stein algorithm

An extension of Karger’s algorithm due to David Karger and Clifford Stein achieves an order of magnitude improvement.[3]

The basic idea is to perform the contraction procedure until the graph reaches [math]\displaystyle{ t }[/math] vertices.

   procedure contract([math]\displaystyle{ G=(V,E) }[/math], [math]\displaystyle{ t }[/math]):
   while [math]\displaystyle{ |V| \gt  t }[/math]
       choose [math]\displaystyle{ e\in E }[/math] uniformly at random
       [math]\displaystyle{ G \leftarrow G/e }[/math]
   return [math]\displaystyle{ G }[/math]

The probability [math]\displaystyle{ p_{n,t} }[/math] that this contraction procedure avoids a specific cut [math]\displaystyle{ C }[/math] in an [math]\displaystyle{ n }[/math]-vertex graph is

[math]\displaystyle{ p_{n,t} \ge \prod_{i=0}^{n-t-1} \Bigl(1-\frac{2}{n-i}\Bigr) = \binom{t}{2}\Bigg/\binom{n}{2}\,. }[/math]

This expression is approximately [math]\displaystyle{ t^2/n^2 }[/math] and becomes less than [math]\displaystyle{ \frac{1}{2} }[/math] around [math]\displaystyle{ t= n/\sqrt 2 }[/math]. In particular, the probability that an edge from [math]\displaystyle{ C }[/math] is contracted grows towards the end. This motivates the idea of switching to a slower algorithm after a certain number of contraction steps.

   procedure fastmincut([math]\displaystyle{ G= (V,E) }[/math]):
   if [math]\displaystyle{ |V| \le 6 }[/math]:
       return contract([math]\displaystyle{ G }[/math], [math]\displaystyle{ 2 }[/math])
   else:
       [math]\displaystyle{ t\leftarrow \lceil 1 + |V|/\sqrt 2\rceil }[/math]
       [math]\displaystyle{ G_1 \leftarrow  }[/math] contract([math]\displaystyle{ G }[/math], [math]\displaystyle{ t }[/math])
       [math]\displaystyle{ G_2 \leftarrow  }[/math] contract([math]\displaystyle{ G }[/math], [math]\displaystyle{ t }[/math])
       return min{fastmincut([math]\displaystyle{ G_1 }[/math]), fastmincut([math]\displaystyle{ G_2 }[/math])}

Analysis

The probability [math]\displaystyle{ P(n) }[/math] the algorithm finds a specific cutset [math]\displaystyle{ C }[/math] is given by the recurrence relation

[math]\displaystyle{ P(n)= 1-\left(1-\frac{1}{2} P\left(\Bigl\lceil 1 + \frac{n}{\sqrt{2}}\Bigr\rceil \right)\right)^2 }[/math]

with solution [math]\displaystyle{ P(n) = \Omega\left(\frac{1}{\log n}\right) }[/math]. The running time of fastmincut satisfies

[math]\displaystyle{ T(n)= 2T\left(\Bigl\lceil 1+\frac{n}{\sqrt{2}}\Bigr\rceil\right)+O(n^2) }[/math]

with solution [math]\displaystyle{ T(n)=O(n^2\log n) }[/math]. To achieve error probability [math]\displaystyle{ O(1/n) }[/math], the algorithm can be repeated [math]\displaystyle{ O(\log n/P(n)) }[/math] times, for an overall running time of [math]\displaystyle{ T(n) \cdot \frac{\log n}{P(n)} = O(n^2\log ^3 n) }[/math]. This is an order of magnitude improvement over Karger’s original algorithm.

Improvement bound

To determine a min-cut, one has to touch every edge in the graph at least once, which is [math]\displaystyle{ \Theta(n^2) }[/math] time in a dense graph. The Karger–Stein's min-cut algorithm takes the running time of [math]\displaystyle{ O(n^2\ln ^{O(1)} n) }[/math], which is very close to that.

References

  1. 1.0 1.1 Karger, David (1993). "Global Min-cuts in RNC and Other Ramifications of a Simple Mincut Algorithm". http://people.csail.mit.edu/karger/Papers/mincut.ps. 
  2. Stoer, M.; Wagner, F. (1997). "A simple min-cut algorithm". Journal of the ACM 44 (4): 585. doi:10.1145/263867.263872. 
  3. Karger, David R.; Stein, Clifford (1996). "A new approach to the minimum cut problem". Journal of the ACM 43 (4): 601. doi:10.1145/234533.234534. http://www.columbia.edu/~cs2035/courses/ieor6614.S09/Contraction.pdf.