ArticleslgStudy

computer science

Karger's algorithm

Karger's algorithm is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Karger's algorithm rather than just read about it. In short: 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.

Karger's algorithm — main illustration
Karger's algorithm — illustration

Key takeaways

  • Karger's algorithm belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Karger's algorithm to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Karger's algorithm from memory before moving on to harder problems.

Reference excerpt

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. The idea of the algorithm is based on the concept of contraction of an edge (u,v) in an undirected graph G=(V,E). Informally, the contraction of an edge merges the nodes u and v into one, reducing the total number of nodes of the graph by one. All other edges connecting either u or v 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

A cut (S,T) in an undirected graph G=(V,E) is a partition of the vertices V into two non-empty, disjoint sets S∪T=V. The cutset of a cut consists of the edges {uv∈E:u∈S,v∈T} 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,

w(S,T)=|{uv∈E:u∈S,v∈T}|. There are 2|V| ways of choosing for each vertex whether it belongs to S or to T, but two of these choices make S or T empty and do not give rise to cuts. Among the remaining choices, swapping the roles of S and T does not change the cut, so each cut is counted twice; therefore, there are 2|V|−1−1 distinct cuts. The minimum cut problem is to find a cut of smallest size among these cuts. For weighted graphs with positive edge weights w:E→𝐑+ the weight of the cut is the sum of the weights of edges between vertices in each part

w(S,T)=∑uv∈E:u∈S,v∈Tw(uv), which agrees with the unweighted definition for w=1. A cut is sometimes called a “global cut” to distinguish it from an “s-t cut” for a given pair of vertices, which has the additional requirement that s∈S and t∈T. Every global cut is an s-t cut for some s,t∈V. Thus, the minimum cut problem can be solved in polynomial time by iterating over all choices of s,t∈V and solving the resulting minimum s-t 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 O(mn+n2log⁡n).

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

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(G=(V,E)): while |V|>2 choose e∈E uniformly at random G←G/e return the only cut in G

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 O(|V|2). 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 w(ei)=π(i) 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 O(|E|log⁡|E|).

The best known implementations use O(|E|) time and space, or O(|E|log⁡|E|) time and O(|V|) space, respectively.

Success probability of the contraction algorithm In a graph G=(V,E) with n=|V| vertices, the contraction algorithm returns a minimum cut with polynomially small probability (n2)−1. Recall that every graph has 2n−1−1 cuts (by the discussion in the previous section), among which at most (n2) 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 (n2)2n−1−1. For instance, the cycle graph on n vertices has exactly (n2) 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 C denote the edges of a specific minimum cut of size k. The contraction algorithm returns C if none of the random edges deleted by the algorithm belongs to the cutset C. In particular, the first edge contraction avoids C, which happens with probability 1−k/|E|. The minimum degree of G is at least k (otherwise a minimum degree vertex would induce a smaller cut where one of the two partitions contains only the minimum degree vertex), so |E|⩾nk/2. Thus, the probability that the contraction algorithm picks an edge from C is

k|E|⩽knk/2=2n. The probability pn that the contraction algorithm on an n-vertex graph avoids C satisfies the recurrence pn⩾(1−2n)pn−1, with p2=1, which can be expanded as

pn⩾∏i=0n−3(1−2n−i)=∏i=0n−3n−i−2n−i=n−2n⋅n−3n−1⋅n−4n−2⋯35⋅24⋅13=(n2)−1.

Repeating the contraction algorithm

By repeating the contraction algorithm T=(n2)ln⁡n times with independent random choices and returning the smallest cut, the probability of not finding a minimum cut is

[1−(n2)−1]T≤1eln⁡n=1n. The total running time for T repetitions for a graph with n vertices and m edges is O(Tm)=O(n2mlog⁡n).

Karger–Stein algorithm An extension of Karger’s algorithm due to David Karger and Clifford Stein achieves an order of magnitude improvement. The basic idea is to perform the contraction procedure until the graph reaches t vertices.

procedure contract(G=(V,E), t): while |V|>t choose e∈E uniformly at random G←G/e return G

… excerpt ends here. Continue reading the full article.

Illustrations

Karger's algorithm: 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.
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.
Karger's algorithm illustration
Karger's algorithm: Successful run of Karger’s algorithm on a 10-vertex graph. The minimum cut has size 3.
Successful run of Karger’s algorithm on a 10-vertex graph. The minimum cut has size 3.
Karger's algorithm: 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 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.
Karger's algorithm: 10 repetitions of the contraction procedure. The 5th repetition finds the minimum cut of size 3.
10 repetitions of the contraction procedure. The 5th repetition finds the minimum cut of size 3.

Worked examples

Example 1 — a first encounter with Karger's algorithm

Start with the simplest possible case. Write down what Karger's algorithm claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Karger's algorithm before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Karger's algorithm ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Karger's algorithm

In research
Karger's algorithm appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Karger's algorithm in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Karger's algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics Graph algorithms, Graph connectivity, so understanding it makes those chapters shorter.
In everyday life
Look for Karger's algorithm outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Karger's algorithm” →

How to study Karger's algorithm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Karger's algorithm means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Karger's algorithm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Karger's algorithm in simple terms?

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.

Why does Karger's algorithm matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Karger's algorithm?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Karger's algorithm.

Tags

  • Graph algorithms
  • Graph connectivity

Keep exploring