# 概率论与数理统计 (Spring 2023)/Karger's min-cut algorithm

Let $\displaystyle{ G(V, E) }$ be an undirected graph. A subset $\displaystyle{ C\subseteq E }$ of edges is a cut of graph $\displaystyle{ G }$ if $\displaystyle{ G }$ becomes disconnected after deleting all edges in $\displaystyle{ C }$.

Let $\displaystyle{ \{S,T\} }$ be a bipartition of $\displaystyle{ V }$ into nonempty subsets $\displaystyle{ S,T\subseteq V }$, where $\displaystyle{ S\cap T=\emptyset }$ and $\displaystyle{ S\cup T=V }$. A cut $\displaystyle{ C }$ is specified by this bipartition as

$\displaystyle{ C=E(S,T)\, }$,

where $\displaystyle{ E(S,T) }$ denotes the set of "crossing edges" with one endpoint in each of $\displaystyle{ S }$ and $\displaystyle{ T }$, formally defined as

$\displaystyle{ E(S,T)=\{uv\in E\mid u\in S, v\in T\} }$.

The min-cut problem, also called the global minimum cut problem, is defined as follows.

 Min-cut problem Input: an undirected graph $\displaystyle{ G(V,E) }$; Output: a cut $\displaystyle{ C }$ in $\displaystyle{ G }$ with the smallest size $\displaystyle{ |C| }$.

Equivalently, the problem asks to find a bipartition of $\displaystyle{ V }$ into disjoint non-empty subsets $\displaystyle{ S }$ and $\displaystyle{ T }$ that minimizes $\displaystyle{ |E(S,T)| }$.

We consider the problem in a slightly more generalized setting, where the input graphs $\displaystyle{ G }$ can be multi-graphs, meaning that there could be multiple parallel edges between two vertices $\displaystyle{ u }$ and $\displaystyle{ v }$. The cuts in multi-graphs are defined in the same way as before, and the cost of a cut $\displaystyle{ C }$ is given by the total number of edges (including parallel edges) in $\displaystyle{ C }$. Equivalently, one may think of a multi-graph as a graph with integer edge weights, and the cost of a cut $\displaystyle{ C }$ is the total weights of all edges in $\displaystyle{ C }$.

A canonical deterministic algorithm for this problem is through the max-flow min-cut theorem. The max-flow algorithm finds us a minimum $\displaystyle{ s }$-$\displaystyle{ t }$ cut, which disconnects a source $\displaystyle{ s\in V }$ from a sink $\displaystyle{ t\in V }$, both specified as part of the input. A global min cut can be found by exhaustively finding the minimum $\displaystyle{ s }$-$\displaystyle{ t }$ cut for an arbitrarily fixed source $\displaystyle{ s }$ and all possible sink $\displaystyle{ t\neq s }$.

## Karger's Algorithm

We will describe a simple and elegant randomized algorithm for the min-cut problem. The algorithm is due to David Karger.

Let $\displaystyle{ G(V, E) }$ be a multi-graph, which allows more than one parallel edges between two distinct vertices $\displaystyle{ u }$ and $\displaystyle{ v }$ but does not allow any self-loops: the edges that adjoin a vertex to itself. A multi-graph $\displaystyle{ G }$ can be represented by an adjacency matrix $\displaystyle{ A }$, in the way that each non-diagonal entry $\displaystyle{ A(u,v) }$ takes nonnegative integer values instead of just 0 or 1, representing the number of parallel edges between $\displaystyle{ u }$ and $\displaystyle{ v }$ in $\displaystyle{ G }$, and all diagonal entries $\displaystyle{ A(v,v)=0 }$ (since there is no self-loop).

Given a multi-graph $\displaystyle{ G(V,E) }$ and an edge $\displaystyle{ e\in E }$, we define the following contraction operator Contract($\displaystyle{ G }$, $\displaystyle{ e }$), which transform $\displaystyle{ G }$ to a new multi-graph.

 The contraction operator Contract($\displaystyle{ G }$, $\displaystyle{ e }$) say $\displaystyle{ e=uv }$: replace $\displaystyle{ \{u,v\} }$ by a new vertex $\displaystyle{ x }$; for every edge (no matter parallel or not) in the form of $\displaystyle{ uw }$ or $\displaystyle{ vw }$ that connects one of $\displaystyle{ \{u,v\} }$ to a vertex $\displaystyle{ w\in V\setminus\{u,v\} }$ in the graph other than $\displaystyle{ u,v }$, replace it by a new edge $\displaystyle{ xw }$; the reset of the graph does not change.

In other words, the $\displaystyle{ Contract(G,uv) }$ merges the two vertices $\displaystyle{ u }$ and $\displaystyle{ v }$ into a new vertex $\displaystyle{ x }$ whose incident edges preserves the edges incident to $\displaystyle{ u }$ or $\displaystyle{ v }$ in the original graph $\displaystyle{ G }$ except for the parallel edges between them. Now you should realize why we consider multi-graphs instead of simple graphs, because even if we start with a simple graph without parallel edges, the contraction operator may create parallel edges.

The contraction operator is illustrated by the following picture:

Karger's algorithm uses a simple idea:

• At each step we randomly select an edge in the current multi-graph to contract until there are only two vertices left.
• The parallel edges between these two remaining vertices must be a cut of the original graph.
• We return this cut and hope that with good chance this gives us a minimum cut.

The following is the pseudocode for Karger's algorithm.

 RandomContract (Karger 1993) Input: multi-graph $\displaystyle{ G(V,E) }$; while $\displaystyle{ |V|\gt 2 }$ do choose an edge $\displaystyle{ uv\in E }$ uniformly at random; $\displaystyle{ G=Contract(G,uv) }$; return $\displaystyle{ C=E }$ (the parallel edges between the only two vertices in $\displaystyle{ V }$);

Another way of looking at the contraction operator Contract($\displaystyle{ G }$,$\displaystyle{ e }$) is that it unions two classes of vertices. Let $\displaystyle{ V=\{v_1,v_2,\ldots,v_n\} }$ be the set of all vertices. We start with $\displaystyle{ n }$ vertex classes $\displaystyle{ S_1,S_2,\ldots, S_n }$ with each class $\displaystyle{ S_i=\{v_i\} }$ contains one vertex. By calling $\displaystyle{ Contract(G,uv) }$, where $\displaystyle{ u\in S_i }$ and $\displaystyle{ v\in S_j }$ for distinct $\displaystyle{ i\neq j }$, we take union of $\displaystyle{ S_i }$ and $\displaystyle{ S_j }$. The edges in the contracted multi-graph are the edges that cross between different vertex classes.

This view of contraction is illustrated by the following picture:

## Analysis of Karger's Algorithm

We now analyze the above algorithm. Since the algorithm is randomized, its output cut is random even when the input is fixed, so the output may not always be correct. We want to give a theoretical guarantee of the chance that the algorithm returns a correct answer on an arbitrary input.

More precisely, on an arbitrarily fixed input multi-graph $\displaystyle{ G }$, we want to answer the following question rigorously:

$\displaystyle{ p_{\text{correct}}=\Pr[\,\text{a minimum cut is returned by }RandomContract\,]\ge ? }$

To answer this question, we prove a stronger statement: for arbitrarily fixed input multi-graph $\displaystyle{ G }$ and a particular minimum cut $\displaystyle{ C }$ in $\displaystyle{ G }$,

$\displaystyle{ p_{C}=\Pr[\,C\mbox{ is returned by }RandomContract\,]\ge ? }$

Obviously this will imply the previous lower bound for $\displaystyle{ p_{\text{correct}} }$ because the event in $\displaystyle{ p_{C} }$ implies the event in $\displaystyle{ p_{\text{correct}} }$.

 In above argument we use the simple law in probability that $\displaystyle{ \Pr(A)\le \Pr(B) }$ if $\displaystyle{ A\subseteq B }$, i.e. event $\displaystyle{ A }$ implies event $\displaystyle{ B }$.

We introduce the following notations:

• Let $\displaystyle{ e_1,e_2,\ldots,e_{n-2} }$ denote the sequence of random edges chosen to contract in a running of RandomContract algorithm.
• Let $\displaystyle{ G_1=G }$ denote the original input multi-graph. And for $\displaystyle{ i=1,2,\ldots,n-2 }$, let $\displaystyle{ G_{i+1}=Contract(G_{i},e_i) }$ be the multigraph after $\displaystyle{ i }$th contraction.

Obviously $\displaystyle{ e_1,e_2,\ldots,e_{n-2} }$ are random, and they are the only random choices used in the algorithm: meaning that they along with the input $\displaystyle{ G }$, uniquely determine the sequence of multi-graphs $\displaystyle{ G_1,G_2,\ldots,G_{n-2} }$ in every iteration as well as the final output.

We now compute the probability $\displaystyle{ p_C }$ by decompose it into more elementary events involving $\displaystyle{ e_1,e_2,\ldots,e_{n-2} }$. This is due to the following proposition.

 Proposition 1 If $\displaystyle{ C }$ is a minimum cut in a multi-graph $\displaystyle{ G }$ and $\displaystyle{ e\not\in C }$, then $\displaystyle{ C }$ is still a minimum cut in the contracted graph $\displaystyle{ G'=contract(G,e) }$.
Proof.
 We first observe that contraction will never create new cuts: every cut in the contracted graph $\displaystyle{ G' }$ must also be a cut in the original graph $\displaystyle{ G }$. We then observe that a cut $\displaystyle{ C }$ in $\displaystyle{ G }$ "survives" in the contracted graph $\displaystyle{ G' }$ if and only if the contracted edge $\displaystyle{ e\not\in C }$. Both observations are easy to verify by the definition of contraction operator (in particular, easier to verify if we take the vertex class interpretation).
$\displaystyle{ \square }$

Recall that $\displaystyle{ e_1,e_2,\ldots,e_{n-2} }$ denote the sequence of random edges chosen to contract in a running of RandomContract algorithm.

By Proposition 1, the event $\displaystyle{ \mbox{}C\mbox{ is returned by }RandomContract\mbox{''}\, }$ is equivalent to the event $\displaystyle{ \mbox{}e_i\not\in C\mbox{ for all }i=1,2,\ldots,n-2\mbox{''} }$. Therefore:

\displaystyle{ \begin{align} p_C &= \Pr[\,C\mbox{ is returned by }{RandomContract}\,]\\ &= \Pr[\,e_i\not\in C\mbox{ for all }i=1,2,\ldots,n-2\,]\\ &= \prod_{i=1}^{n-2}\Pr[e_i\not\in C\mid \forall j\lt i, e_j\not\in C]. \end{align} }

The last equation is due to the chain rule.

Now our task is to give lower bound to each $\displaystyle{ p_i=\Pr[e_i\not\in C\mid \forall j\lt i, e_j\not\in C] }$. The condition $\displaystyle{ \mbox{}\forall j\lt i, e_j\not\in C\mbox{''} }$ means the min-cut $\displaystyle{ C }$ survives all first $\displaystyle{ i-1 }$ contractions $\displaystyle{ e_1,e_2,\ldots,e_{i-1} }$, which due to Proposition 1 means that $\displaystyle{ C }$ is also a min-cut in the multi-graph $\displaystyle{ G_i }$ obtained from applying the first $\displaystyle{ (i-1) }$ contractions.

Then the conditional probability $\displaystyle{ p_i=\Pr[e_i\not\in C\mid \forall j\lt i, e_j\not\in C] }$ is the probability that no edge in $\displaystyle{ C }$ is hit when a uniform random edge in the current multi-graph is chosen assuming that $\displaystyle{ C }$ is a minimum cut in the current multi-graph. Intuitively this probability should be bounded from below, because as a min-cut $\displaystyle{ C }$ should be sparse among all edges. This intuition is justified by the following proposition.

 Proposition 2 If $\displaystyle{ C }$ is a min-cut in a multi-graph $\displaystyle{ G(V,E) }$, then $\displaystyle{ |E|\ge \frac{|V||C|}{2} }$.
Proof.
 It must hold that the degree of each vertex $\displaystyle{ v\in V }$ is at least $\displaystyle{ |C| }$, or otherwise the set of edges incident to $\displaystyle{ v }$ forms a cut of size smaller than $\displaystyle{ |C| }$ which separates $\displaystyle{ \{v\} }$ from the rest of the graph, contradicting that $\displaystyle{ C }$ is a min-cut. And the bound $\displaystyle{ |E|\ge \frac{|V||C|}{2} }$ follows directly from applying the handshaking lemma to the fact that every vertex in $\displaystyle{ G }$ has degree at least $\displaystyle{ |C| }$.
$\displaystyle{ \square }$

Let $\displaystyle{ V_i }$ and $\displaystyle{ E_i }$ denote the vertex set and edge set of the multi-graph $\displaystyle{ G_i }$ respectively, and recall that $\displaystyle{ G_i }$ is the multi-graph obtained from applying first $\displaystyle{ (i-1) }$ contractions. Obviously $\displaystyle{ |V_{i}|=n-i+1 }$. And due to Proposition 2, $\displaystyle{ |E_i|\ge \frac{|V_i||C|}{2} }$ if $\displaystyle{ C }$ is still a min-cut in $\displaystyle{ G_i }$.

The probability $\displaystyle{ p_i=\Pr[e_i\not\in C\mid \forall j\lt i, e_j\not\in C] }$ can be computed as

\displaystyle{ \begin{align} p_i &=1-\frac{|C|}{|E_i|}\\ &\ge1-\frac{2}{|V_i|}\\ &=1-\frac{2}{n-i+1} \end{align}, }

where the inequality is due to Proposition 2.

We now can put everything together. We arbitrarily fix the input multi-graph $\displaystyle{ G }$ and any particular minimum cut $\displaystyle{ C }$ in $\displaystyle{ G }$.

\displaystyle{ \begin{align} p_{\text{correct}} &=\Pr[\,\text{a minimum cut is returned by }RandomContract\,]\\ &\ge \Pr[\,C\mbox{ is returned by }{RandomContract}\,]\\ &= \Pr[\,e_i\not\in C\mbox{ for all }i=1,2,\ldots,n-2\,]\\ &= \prod_{i=1}^{n-2}\Pr[e_i\not\in C\mid \forall j\lt i, e_j\not\in C]\\ &\ge \prod_{i=1}^{n-2}\left(1-\frac{2}{n-i+1}\right)\\ &= \prod_{k=3}^{n}\frac{k-2}{k}\\ &= \frac{2}{n(n-1)}. \end{align} }

This gives us the following theorem.

 Theorem For any multigraph with $\displaystyle{ n }$ vertices, the RandomContract algorithm returns a minimum cut with probability at least $\displaystyle{ \frac{2}{n(n-1)} }$.

At first glance this seems to be a quite slim chance of success. However, notice that there may be exponential many cuts in a graph (because potentially every nonempty subset $\displaystyle{ S\subset V }$ corresponds to a cut $\displaystyle{ C=E(S,\overline{S}) }$), and Karger's algorithm effectively reduce this exponential-sized space to quadratic-sized, an exponential improvement!

We can run RandomContract independently for $\displaystyle{ t=\left\lceil\frac{n(n-1)\ln n}{2}\right\rceil }$ times and return the smallest cut ever returned. The probability that a minimum cut is found is at least:

\displaystyle{ \begin{align} &\quad 1-\Pr[\,\mbox{all }t\mbox{ independent runnings of } RandomContract\mbox{ fails to find a min-cut}\,] \\ &= 1-\Pr[\,\mbox{a single running of }{RandomContract}\mbox{ fails}\,]^{t} \\ &\ge 1- \left(1-\frac{2}{n(n-1)}\right)^{\frac{n(n-1)\ln n}{2}} \\ &\ge 1-\frac{1}{n}. \end{align} }

## A Consequence of the Probabilistic Method

The analysis of Karger's algorithm implies the following combinatorial proposition for the number of distinct minimum cuts in a graph.

 Corollary For any graph $\displaystyle{ G(V,E) }$ of $\displaystyle{ n }$ vertices, the number of distinct minimum cuts in $\displaystyle{ G }$ is at most $\displaystyle{ \frac{n(n-1)}{2} }$.
Proof.
 Let $\displaystyle{ \mathcal{C} }$ denote the set of all minimum cuts in $\displaystyle{ G }$. For each min-cut $\displaystyle{ C\in\mathcal{C} }$, let $\displaystyle{ A_C }$ denote the event "$\displaystyle{ C }$ is returned by RandomContract", whose probability is given by $\displaystyle{ p_C=\Pr(A_C)\, }$. Clearly we have: for any distinct $\displaystyle{ C,D\in\mathcal{C} }$, $\displaystyle{ A_C\, }$ and $\displaystyle{ A_{D}\, }$ are disjoint events; and the union $\displaystyle{ \bigcup_{C\in\mathcal{C}}A_C }$ is precisely the event "a minimum cut is returned by RandomContract", whose probability is given by $\displaystyle{ p_{\text{correct}}=\Pr[\,\text{a minimum cut is returned by } RandomContract\,] }$. Due to the additivity of probability, it holds that $\displaystyle{ p_{\text{correct}}=\sum_{C\in\mathcal{C}}\Pr(A_C)=\sum_{C\in\mathcal{C}}p_C. }$ By the analysis of Karger's algorithm, we know $\displaystyle{ p_C\ge\frac{2}{n(n-1)} }$. And since $\displaystyle{ p_{\text{correct}} }$ is a well defined probability, due to the unitarity of probability, it must hold that $\displaystyle{ p_{\text{correct}}\le 1 }$. Therefore, $\displaystyle{ 1\ge p_{\text{correct}}=\sum_{C\in\mathcal{C}}p_C\ge|\mathcal{C}|\frac{2}{n(n-1)} }$, which means $\displaystyle{ |\mathcal{C}|\le\frac{n(n-1)}{2} }$.
$\displaystyle{ \square }$

Note that the statement of this theorem has no randomness at all, while the proof consists of a randomized procedure. This is an example of the probabilistic method.