Karger's algorithm: Difference between revisions
→Analysis: slightly tighter math (still needs editing) |
m Moving Category:Algorithms in graph theory to Category:Graph algorithms per Wikipedia:Categories for discussion/Log/2024 October 4 |
||
(93 intermediate revisions by 55 users not shown) | |||
Line 1: | Line 1: | ||
{{Short description|Randomized algorithm for minimum cuts}} |
|||
[[File:Min cut.jpg|thumb|A graph with two cuts. The dotted line in red is a cut with three crossing edges. The dashed line in green is the min-cut of this graph, crossing only two edges.]] |
|||
[[File:Min cut example.svg|thumb|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 the [[minimum cut]] of a connected [[graph (mathematics)|graph]]. It was invented by [[David Karger]] and first published in 1993.<ref name="karger1993">{{cite conference |
|||
In [[computer science]] and [[graph theory]], '''Karger's algorithm''' is a [[randomized algorithm]] to compute a [[minimum cut]] of a connected [[Graph (discrete mathematics)|graph]]. It was invented by [[David Karger]] and first published in 1993.<ref name="karger1993">{{cite conference |
|||
|last=Karger |
|last=Karger |
||
|first=David |
|first=David |
||
|title=Global Min-cuts in RNC and Other Ramifications of a Simple Mincut Algorithm |
|title=Global Min-cuts in RNC and Other Ramifications of a Simple Mincut Algorithm |
||
|url=http://people.csail.mit.edu/karger/Papers/mincut.ps |
|url=http://people.csail.mit.edu/karger/Papers/mincut.ps |
||
| |
|book-title=Proc. 4th Annual ACM-SIAM Symposium on Discrete Algorithms |
||
|date=1993 |
|date=1993 |
||
}}</ref> |
}}</ref> |
||
The idea of the algorithm is based on the concept of [[Edge contraction|contraction of an edge]] <math>(u, v)</math> in an undirected graph <math>G = (V, E)</math>. Informally speaking, the contraction of an edge merges the nodes <math>u</math> and <math>v</math> into one, reducing the total number of nodes of the graph by one. All other edges connecting either <math>u</math> or <math>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 (graph theory)|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 idea of the algorithm is based on the concept of [[Edge contraction|contraction of an edge]] <math>(u, v)</math> in an undirected graph <math>G = (V, E)</math>. Informally speaking, the contraction of an edge merges the nodes <math>u</math> and <math>v</math> into one, reducing the total number of nodes of the graph by one. All other edges connecting either <math>u</math> or <math>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 (graph theory)|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|Minimum cut}} |
{{main|Minimum cut}} |
||
A ''cut'' <math>(S,T)</math> in an undirected graph <math>G = (V, E)</math> is a partition of the vertices <math>V</math> into two non-empty, disjoint sets <math>S\cup T= V</math>. The ''cutset'' of a cut consists of the edges <math>\{\, 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>w(S,T) = |\{\, uv \in E \colon u\in S, v\in T\,\}|\,.</math> |
|||
There are <math>2^{|V|}</math> ways of choosing for each vertex whether it belongs to <math>S</math> or to <math>T</math>, but two of these choices make <math>S</math> or <math>T</math> empty and do not give rise to cuts. Among the remaining choices, swapping the roles of <math>S</math> and <math>T</math> does not change the cut, so each cut is counted twice; therefore, there are <math>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>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>\text{minimize }\sum_{(u,v) \isin E} {\mathbf{1}_{S \times T}(u,v)}.</math> |
|||
:: <math>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>w=1</math>. |
|||
A cut is sometimes called a “global cut” to distinguish it from an “<math>s</math>-<math>t</math> cut” for a given pair of vertices, which has the additional requirement that <math>s\in S</math> and <math>t\in T</math>. Every global cut is an <math>s</math>-<math>t</math> cut for some <math>s,t\in V</math>. Thus, the minimum cut problem can be solved in [[polynomial time]] by iterating over all choices of <math>s,t\in V</math> and solving the resulting minimum <math>s</math>-<math>t</math> cut problem using the [[max-flow min-cut theorem]] and a polynomial time algorithm for [[maximum flow]], such as the [[push–relabel maximum flow algorithm|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>O(mn+n^2\log n)</math>.<ref name="simplemincut">{{Cite journal | last1 = Stoer | first1 = M. | last2 = Wagner | first2 = F. | doi = 10.1145/263867.263872 | title = A simple min-cut algorithm | journal = Journal of the ACM | volume = 44 | issue = 4 | pages = 585 | year = 1997 | s2cid = 15220291 | doi-access = free }}</ref> |
|||
== Algorithm description == |
|||
==Contraction algorithm== |
|||
[[File:Single_run_of_Karger’s_Mincut_algorithm.svg|thumb|Successful run of Karger’s algorithm on a 10-vertex graph. The minimum cut has size 3 and is indicated by the vertex colours.]] |
|||
The fundamental operation of Karger’s algorithm is a form of [[edge contraction]]. The result of contracting the edge <math>e=\{u,v\}</math> is new node <math>uv</math>. Every edge <math>\{w,u\}</math> or <math>\{w,v\}</math> for <math>w\notin\{u, |
The fundamental operation of Karger’s algorithm is a form of [[edge contraction]]. The result of contracting the edge <math>e=\{u,v\}</math> is a new node <math>uv</math>. Every edge <math>\{w,u\}</math> or <math>\{w,v\}</math> for <math>w\notin\{u,v\}</math> to the endpoints of the contracted edge is replaced by an edge <math>\{w,uv\}</math> to the new node. Finally, the contracted nodes <math>u</math> and <math>v</math> with all their incident edges are removed. In particular, the resulting graph contains no self-loops. The result of contracting edge <math>e</math> is denoted <math>G/e</math>. |
||
[[File: |
[[File:Edge contraction in a multigraph.svg|150px|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. |
|||
[[File:Single run of Karger’s Mincut algorithm.svg|frame|center|Successful run of Karger’s algorithm on a 10-vertex graph. The minimum cut has size 3.]] |
|||
'''procedure''' contract(<math>G=(V,E)</math>): |
'''procedure''' contract(<math>G=(V,E)</math>): |
||
Line 33: | Line 43: | ||
'''return''' the only cut in <math>G</math> |
'''return''' the only cut in <math>G</math> |
||
When the graph is represented using [[adjacency list]]s 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>O(|V|^2)</math>. Alternatively, the procedure can be viewed as |
When the graph is represented using [[adjacency list]]s 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>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>w(e_i)=\pi(i)</math> according to a random permutation <math>\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>O(|E|\log |E|)</math>. |
||
[[File:Spanning tree interpretation of Karger’s algorithm.svg|frame|center|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.]] |
|||
== Analysis == |
|||
=== Proof of correctness === |
|||
'''Lemma 1:''' let ''k'' denote the actual result of the min-cut of ''G'', every node in the graph has a degree that is equal or larger than ''k''.<br /> |
|||
The best known implementations use <math>O(|E|)</math> time and space, or <math>O(|E|\log |E|)</math> time and <math>O(|V|)</math> space, respectively.<ref name=karger1993/> |
|||
'''Proof:''' If there exists a node N in '''G''', whose degree is smaller than ''k'', then select N as on one side and the other nodes on the other side. As a result we get a min-cut which is smaller than ''k''. This is a contradiction. ∎ |
|||
===Success probability of the contraction algorithm=== |
|||
In a graph <math>G=(V,E)</math> with <math>n=|V|</math> vertices, the contraction algorithm returns a minimum cut with polynomially small probability <math>\binom{n}{2}^{-1}</math>. Recall that every graph has <math>2^{n-1} -1 </math> cuts (by the discussion in the previous section), among which at most <math>\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>\frac{\tbinom{n}{2}}{2^{n-1} -1}</math>. |
|||
'''Proof:''' Let ''C'' denote the edge set of minimum ''k''-cut. At each stage. we have ''n'' − ''i'' node and by Lemma 1 there are at least {{math| {{Fraction |(''n'' − ''i'')''k''|2 }}}} edges. As such, the probability of selecting an edge in ''C'' to make a contraction is |
|||
:::<math>Pr[(u,v) \isin C]\le \frac{k}{(n-i) k/2} = \frac{2}{n-i} </math> |
|||
For instance, the [[cycle graph]] on <math>n</math> vertices has exactly <math>\binom{n}{2}</math> minimum cuts, given by every choice of 2 edges. The contraction procedure finds each of these with equal probability. |
|||
In this manner, we have to run ''n'' − 2 iterations to reduce a graph of ''n'' nodes to a graph of only two nodes with i from 0 to ''n'' − 3. Thus, the probability of ''C'' surviving after ''n'' − 2 iterations is |
|||
To further establish the lower bound on the success probability, let <math>C</math> denote the edges of a specific minimum cut of size <math>k</math>. The contraction algorithm returns <math>C</math> if none of the random edges deleted by the algorithm belongs to the cutset <math>C</math>. In particular, the first edge contraction avoids <math>C</math>, which happens with probability <math>1-k/|E|</math>. The minimum [[Degree (graph theory)|degree]] of <math>G</math> is at least <math>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>|E|\geqslant nk/2</math>. Thus, the probability that the contraction algorithm picks an edge from <math>C</math> is |
|||
::::<math>\frac{k}{|E|} \leqslant \frac{k}{nk/2} = \frac{2}{n}.</math> |
|||
The probability <math>p_n</math> that the contraction algorithm on an <math>n</math>-vertex graph avoids <math>C</math> satisfies the recurrence <math>p_n \geqslant \left( 1 - \frac{2}{n} \right) p_{n-1}</math>, with <math>p_2 = 1</math>, which can be expanded as |
|||
:::<math> |
:::<math> |
||
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} |
= \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> |
</math> |
||
Therefore, we have at least <math>\Omega(n^{-2})</math> chances to find the min-cut <math>C</math> in one execution of procedure contract(<math>G</math>). Let <math>p=(1-2/n(n-1))</math> denote that the probability of failing to find the min-cut in a single run of the contraction procedure. If we repeat the procedure <math> T = cn(n-1)/2 = O(n^2)</math> times, the probability of successfully returning <math>C</math> is |
|||
===Repeating the contraction algorithm=== |
|||
[[File:10 repetitions of Karger’s contraction procedure.svg|thumb|10 repetitions of the contraction procedure. The 5th repetition finds the minimum cut of size 3.]] |
|||
By repeating the contraction algorithm <math> 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> |
:::<math> |
||
\left[1-\binom{n}{2}^{-1}\right]^T |
|||
\Pr[\text{Final Success}] \geq 1-p^T |
|||
\leq \frac{1}{e^{\ln n}} = \frac{1}{n}\,. |
|||
= 1- (1-\frac{2}{n(n-1)})^{\frac {cn(n-1)}{2}} |
|||
= 1-\frac{1}{e^c} > 99%\text{ when }c = 10. |
|||
</math> |
</math> |
||
The total running time for <math>T</math> repetitions for a graph with <math>n</math> vertices and <math>m</math> edges is <math> O(Tm) = O(n^2 m \log n)</math>. |
|||
=== Running time === |
|||
Karger's algorithm is the fastest known minimum cut algorithm, is randomized, and computes a minimum cut with high probability in time ''O''(|''V''|<sup>2</sup> log<sup>3</sup>|''V''|). To prove this authors at first mention that contraction of <math>G</math> to <math> \left\lceil n / \sqrt{2} + 1 \right\rceil </math> vertices can be implemented in <math>O(n^2)</math> time. And the running time is <math> T(n) = 2 \left( n^2 + T\left( \left\lceil n / \sqrt{2} + 1 \right\rceil \right) \right) </math>. This recurrence is solved by <math> O( n^2 log(n) ) </math>. One run of an algorithm finds a particular minimum cut with probability <math>\Omega( 1/ log(n) )</math>. Running algorithm <math>log^2(n)</math> times reduce the chance of missing any particular minimum cut to ''O''(1/''n''<sup>2</sup>). |
|||
== Karger–Stein algorithm == |
|||
: '''Lemma 2:''' For each execution of the inner while loop (Line 3–5) of Karger's Basic Algorithm, it takes <math>O(n^2)</math> running time. |
|||
An extension of Karger’s algorithm due to [[David Karger]] and [[Clifford Stein]] achieves an order of magnitude improvement.<ref name= "faster">{{Cite journal | last1 = Karger | first1 = David R. | author-link1 = David Karger| last2 = Stein | first2 = Clifford| author-link2 = Clifford Stein | doi = 10.1145/234533.234534 | title = A new approach to the minimum cut problem | journal = Journal of the ACM | volume = 43 | issue = 4 | pages = 601 | year = 1996 | s2cid = 5385337 | url = http://www.columbia.edu/~cs2035/courses/ieor6614.S09/Contraction.pdf}}</ref> |
|||
'''Proof:''' We can represent this graph '''G''' by maintaining an adjacency list, which means all edges incident to node ''v'' are in a linked list. What is more, we have to construct pointers between the two copies the same edge (''u'', ''w'') and (''w'', ''u''). When ''v'' and ''w'' are contracted, we traverse the adjacency list of ''v'', and for each edge (''v'', ''u'') find the corresponding edge''(u, v)'' by the pointer and rename it to (''u'', ''w''). As such, each contraction costs {{math|''O''(n)}} time and we have to contract ''n'' − 2 times, which in total is {{math|''O''(''n''<sup>2</sup>)}}.∎ |
|||
The basic idea is to perform the contraction procedure until the graph reaches <math>t</math> vertices. |
|||
According to the algorithm, we have to repeat the inner while loop of Karger's Basic Algorithm {{math|''O''(''n''<sup>2</sup>)}} times. Hence, with the correctness of Lemma 2, the overall running time is {{math|''O''(''n''<sup>4</sup>)}}. |
|||
'''procedure''' contract(<math>G=(V,E)</math>, <math>t</math>): |
|||
== The Karger–Stein's algorithm == |
|||
'''while''' <math>|V| > t</math> |
|||
This algorithm is developed by [[David Karger]] and [[Clifford Stein]]. And it is an order of magnitude improvement of the running time compared with Karger's Basic Algorithm.<ref name= "faster"> |
|||
choose <math>e\in E</math> uniformly at random |
|||
{{cite journal |
|||
<math>G \leftarrow G/e</math> |
|||
|last=Karger |
|||
'''return''' <math>G</math> |
|||
|first=David |
|||
|coauthors=[[Clifford Stein]] |
|||
|title=A New Approach to the Minimum Cut Problem |
|||
|journal=Journal of the ACM |
|||
|year=1996 |
|||
|volume=43 |
|||
|issue=4 |
|||
|pages=601–640 |
|||
|url=http://people.csail.mit.edu/karger/Papers/contract.ps |
|||
}}</ref><br /> |
|||
Before we move forwards to the detailed description, we notice that when we do the contractions until ''i'' vertices are left, the probability that ''C'' survives is |
|||
:::<math> |
|||
\begin{align} |
|||
\Pr[C] &\ge \prod_{j=0}^{n-i} {(1-\frac{2}{n-j})}\\ |
|||
&= \frac{n-2}{n}\cdot \frac{n-3}{n-1} \cdot \frac{n-4}{n-2}\cdots \frac{n-i}{n-i+2}\cdot \frac{n-i-1}{n-i+1} \cdot \frac{n-i-2}{n-i}\\ |
|||
&= \frac{(n-i-1)(n-i-2)}{n(n-1)} \\ |
|||
& \isin O\left(\frac{i^2}{n^2}\right) |
|||
\end{align}</math> |
|||
The probability <math>p_{n,t}</math> that this contraction procedure avoids a specific cut <math>C</math> in an <math>n</math>-vertex graph is |
|||
=== Algorithm description === |
|||
::: |
|||
Inspired by the formula above, we can find that the less edges that left in this graph, the less chance that ''C'' survives. We, therefore, improve the basic algorithm that |
|||
<math> |
|||
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>t^2/n^2</math> and becomes less than <math>\frac{1}{2}</math> around <math> t= n/\sqrt 2 </math>. In particular, the probability that an edge from <math>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. |
|||
'''INPUT:''' An undirected graph ''G'' = (''V'', ''E'')<br /> |
|||
'''OUTPUT:''' find the min-cut of '''''G''''' |
|||
'''function''' Karger–Stein's Min-Cut('''''G'''''): |
|||
1, run the '''Karger's Basic Algorithm''' to ''i'' = {{math|{{Fraction |n|√2 }}}} twice getting {{math|G<sub>1</sub>}} and {{math|G<sub>2</sub>}}, |
|||
2, recursively run the '''Karger–Stein's Min-Cut Algorithm''' on {{math|G<sub>1</sub>}} and {{math|G<sub>2</sub>}} |
|||
'''end function''' |
|||
'''procedure''' fastmincut(<math>G= (V,E)</math>): |
|||
=== Running time === |
|||
'''if''' <math>|V| \le 6</math>: |
|||
Then we can get the probability of min cut survive ''P''(''n'') (n is the number of vertices) meets this recurrence relation: |
|||
'''return''' contract(<math>G</math>, <math>2</math>) |
|||
:::<math>P(n)= 1-\left(1-\frac{1}{2} P\left(\frac{n}{\sqrt{2}}\right)\right)^2</math> |
|||
'''else''': |
|||
Also, we can prove that <math>P(n) = O\left(\frac{1}{\ln n}\right)</math>. and the recurrence relation of running time is |
|||
<math>t\leftarrow \lceil 1 + |V|/\sqrt 2\rceil</math> |
|||
:::<math>T(n)= 2T\left(\frac{n}{\sqrt{2}}\right)+O(n^2)\text{ and }T(n) = O(1)\text{ when }n \le 2.</math> |
|||
<math>G_1 \leftarrow </math> contract(<math>G</math>, <math>t</math>) |
|||
According to the [[Master theorem|Master Theorem]], <math>T(n)=O(n^2\ln n)</math>. Therefore the overall running time is <math>T(n) \cdot \frac{1}{P(n)} = O(n^2\ln ^2 n)</math>, which is an order of magnitude improvement. |
|||
<math>G_2 \leftarrow </math> contract(<math>G</math>, <math>t</math>) |
|||
'''return''' min{fastmincut(<math>G_1</math>), fastmincut(<math>G_2</math>)} |
|||
=== |
=== Analysis === |
||
'''Theorem:''' With high probability we can find all min cuts in the running time of <math>O(n^2\ln ^3 n)</math>. |
|||
The contraction parameter <math>t</math> is chosen so that each call to contract has probability at least 1/2 of success (that is, of avoiding the contraction of an edge from a specific cutset <math>C</math>). This allows the successful part of the recursion tree to be modeled as a [[random binary tree]] generated by a critical [[Galton–Watson process]], and to be analyzed accordingly.<ref name= "faster"/> |
|||
'''Proof:''' Since we know that <math>P(n) = O\left(\frac{1}{\ln n}\right)</math>, therefore after running this algorithm <math>O(\ln ^2 n)</math> times The probability of missing a specific min-cut is |
|||
::::<math>\Pr[\text{miss a specific min-cut}] = (1-P(n))^{O(\ln ^2 n)} \le \left(1-\frac{c}{\ln n}\right)^{\frac{3\ln ^2 n}{c}} \le e^{-3\ln n} = \frac{1}{n^3}</math>. |
|||
The probability <math>P(n)</math> that this random tree of successful calls contains a long-enough path to reach the base of the recursion and find <math>C</math> is given by the recurrence relation |
|||
And there are at most <math>\binom{n}{2}</math> min-cuts, hence the probability of missing ant min-cut is |
|||
:::<math> |
:::<math>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>P(n) = \Omega\left(\frac{1}{\log n}\right)</math>. The running time of fastmincut satisfies |
|||
The probability of failures is considerably small when ''n'' is large enough.∎ |
|||
:::<math>T(n)= 2T\left(\Bigl\lceil 1+\frac{n}{\sqrt{2}}\Bigr\rceil\right)+O(n^2)</math> |
|||
with solution <math>T(n)=O(n^2\log n)</math>. To achieve error probability <math>O(1/n)</math>, the algorithm can be repeated <math>O(\log n/P(n))</math> times, for an overall running time of <math>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.<ref name= "faster"/> |
|||
=== Improvement bound === |
=== Improvement bound === |
||
To determine a min-cut, one has to touch every edge in the graph at least once, which is <math> |
To determine a min-cut, one has to touch every edge in the graph at least once, which is <math>\Theta(n^2)</math> time in a [[dense graph]]. The Karger–Stein's min-cut algorithm takes the running time of <math>O(n^2\ln ^{O(1)} n)</math>, which is very close to that. |
||
==References== |
==References== |
||
Line 125: | Line 123: | ||
[[Category:Graph algorithms]] |
[[Category:Graph algorithms]] |
||
[[Category:Graph connectivity]] |
[[Category:Graph connectivity]] |
||
[[th:ขั้นตอนวิธีของคาร์เกอร์]] |
|||
[[vi:Thuật toán Karger]] |
Latest revision as of 19:56, 12 October 2024
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 in an undirected graph . Informally speaking, the contraction of an edge merges the nodes and into one, reducing the total number of nodes of the graph by one. All other edges connecting either or 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
[edit]A cut in an undirected graph is a partition of the vertices into two non-empty, disjoint sets . The cutset of a cut consists of the edges 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,
There are ways of choosing for each vertex whether it belongs to or to , but two of these choices make or empty and do not give rise to cuts. Among the remaining choices, swapping the roles of and does not change the cut, so each cut is counted twice; therefore, there are distinct cuts. The minimum cut problem is to find a cut of smallest size among these cuts.
For weighted graphs with positive edge weights the weight of the cut is the sum of the weights of edges between vertices in each part
which agrees with the unweighted definition for .
A cut is sometimes called a “global cut” to distinguish it from an “- cut” for a given pair of vertices, which has the additional requirement that and . Every global cut is an - cut for some . Thus, the minimum cut problem can be solved in polynomial time by iterating over all choices of and solving the resulting minimum - 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 .[2]
Contraction algorithm
[edit]The fundamental operation of Karger’s algorithm is a form of edge contraction. The result of contracting the edge is a new node . Every edge or for to the endpoints of the contracted edge is replaced by an edge to the new node. Finally, the contracted nodes and with all their incident edges are removed. In particular, the resulting graph contains no self-loops. The result of contracting edge is denoted .
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.
procedure contract(): while choose uniformly at random return the only cut in
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 . 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 according to a random permutation . 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 .
The best known implementations use time and space, or time and space, respectively.[1]
Success probability of the contraction algorithm
[edit]In a graph with vertices, the contraction algorithm returns a minimum cut with polynomially small probability . Recall that every graph has cuts (by the discussion in the previous section), among which at most 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 .
For instance, the cycle graph on vertices has exactly 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 denote the edges of a specific minimum cut of size . The contraction algorithm returns if none of the random edges deleted by the algorithm belongs to the cutset . In particular, the first edge contraction avoids , which happens with probability . The minimum degree of is at least (otherwise a minimum degree vertex would induce a smaller cut where one of the two partitions contains only the minimum degree vertex), so . Thus, the probability that the contraction algorithm picks an edge from is
The probability that the contraction algorithm on an -vertex graph avoids satisfies the recurrence , with , which can be expanded as
Repeating the contraction algorithm
[edit]By repeating the contraction algorithm times with independent random choices and returning the smallest cut, the probability of not finding a minimum cut is
The total running time for repetitions for a graph with vertices and edges is .
Karger–Stein algorithm
[edit]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 vertices.
procedure contract(, ): while choose uniformly at random return
The probability that this contraction procedure avoids a specific cut in an -vertex graph is
This expression is approximately and becomes less than around . In particular, the probability that an edge from 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(): if : return contract(, ) else: contract(, ) contract(, ) return min{fastmincut(), fastmincut()}
Analysis
[edit]The contraction parameter is chosen so that each call to contract has probability at least 1/2 of success (that is, of avoiding the contraction of an edge from a specific cutset ). This allows the successful part of the recursion tree to be modeled as a random binary tree generated by a critical Galton–Watson process, and to be analyzed accordingly.[3]
The probability that this random tree of successful calls contains a long-enough path to reach the base of the recursion and find is given by the recurrence relation
with solution . The running time of fastmincut satisfies
with solution . To achieve error probability , the algorithm can be repeated times, for an overall running time of . This is an order of magnitude improvement over Karger’s original algorithm.[3]
Improvement bound
[edit]To determine a min-cut, one has to touch every edge in the graph at least once, which is time in a dense graph. The Karger–Stein's min-cut algorithm takes the running time of , which is very close to that.
References
[edit]- ^ a b Karger, David (1993). "Global Min-cuts in RNC and Other Ramifications of a Simple Mincut Algorithm". Proc. 4th Annual ACM-SIAM Symposium on Discrete Algorithms.
- ^ Stoer, M.; Wagner, F. (1997). "A simple min-cut algorithm". Journal of the ACM. 44 (4): 585. doi:10.1145/263867.263872. S2CID 15220291.
- ^ a b c Karger, David R.; Stein, Clifford (1996). "A new approach to the minimum cut problem" (PDF). Journal of the ACM. 43 (4): 601. doi:10.1145/234533.234534. S2CID 5385337.