Stoer–Wagner Algorithm
   HOME

TheInfoList



OR:

In
graph theory In mathematics, graph theory is the study of '' graphs'', which are mathematical structures used to model pairwise relations between objects. A graph in this context is made up of '' vertices'' (also called ''nodes'' or ''points'') which are conn ...
, the Stoer–Wagner algorithm is a
recursive algorithm In computer science, recursion is a method of solving a computational problem where the solution depends on solutions to smaller instances of the same problem. Recursion solves such recursive problems by using functions that call themselves ...
to solve the
minimum cut In graph theory, a minimum cut or min-cut of a graph is a cut (a partition of the vertices of a graph into two disjoint subsets) that is minimal in some metric. Variations of the minimum cut problem consider weighted graphs, directed graphs, te ...
problem in
undirected In discrete mathematics, and more specifically in graph theory, a graph is a structure amounting to a set of objects in which some pairs of the objects are in some sense "related". The objects correspond to mathematical abstractions called '' ...
weighted graphs with non-negative weights. It was proposed by Mechthild Stoer and Frank Wagner in 1995. The essential idea of this algorithm is to shrink the graph by merging the most intensive vertices, until the graph only contains two combined vertex sets. At each phase, the algorithm finds the minimum s-t cut for two vertices s and t chosen at its will. Then the algorithm shrinks the edge between s and t to search for non s-t cuts. The minimum cut found in all phases will be the minimum weighted cut of the graph. A
cut Cut may refer to: Common uses * The act of cutting, the separation of an object into two through acutely-directed force ** A type of wound ** Cut (archaeology), a hole dug in the past ** Cut (clothing), the style or shape of a garment ** Cut (ea ...
is a partition of the vertices of a graph into two non-empty, disjoint subsets. A
minimum cut In graph theory, a minimum cut or min-cut of a graph is a cut (a partition of the vertices of a graph into two disjoint subsets) that is minimal in some metric. Variations of the minimum cut problem consider weighted graphs, directed graphs, te ...
is a cut for which the size or weight of the cut is not larger than the size of any other cut. For an unweighted graph, the minimum cut would simply be the cut with the least edges. For a weighted graph, the sum of all edges' weight on the cut determines whether it is a minimum cut. In practice, the minimum cut problem is always discussed with the
maximum flow problem In optimization theory, maximum flow problems involve finding a feasible flow through a flow network that obtains the maximum possible flow rate. The maximum flow problem can be seen as a special case of more complex network flow problems, such ...
, to explore the maximum capacity of a
network Network, networking and networked may refer to: Science and technology * Network theory, the study of graphs as a representation of relations between discrete objects * Network science, an academic field that studies complex networks Mathematics ...
, since the minimum cut is a bottleneck in a graph or network.


Stoer–Wagner minimum cut algorithm

Let G=(V,E,w) be a weighted undirected graph. Suppose that s,t\in V. The cut is called an s-t cut if exactly one of s or t is in S. The minimal cut of G that is also an s-t cut is called the s-t min-cut of G. This algorithm starts by finding an s and a t in V, and an s-t min-cut (S,T) of G. For any pair \left\, there are two possible situations: either (S,T) is a global min-cut of G, or s and t belong to the same side of the global min-cut of G. Therefore, the global min-cut can be found by checking the graph G\cup\/\left\, which is the graph after merging vertices s and t into a new vertex st. During the merging, if s and t are connected by an edge then this edge disappears. If s and t both have edges to some vertex v, then the weight of the edge from the new vertex st to v is w(s,v)+w(t,v). The algorithm is described as: MinimumCutPhase(G,w,a) A\gets\left\ while \ A\ne V add to A the most tightly connected vertex end store the cut in which the last remaining vertex is by itself (the "cut-of-the-phase") shrink G by merging the two vertices (s, t) added last (the value of "cut-of-the-phase" is the value of minimum s, t cut.) MinimumCut(G,w,a) while , V, >1 MinimumCutPhase(G,w,a) if the cut-of-the-phase is lighter than the current minimum cut then store the cut-of-the-phase as the current minimum cut The algorithm works in phases. In the MinimumCutPhase, the subset A of the graphs vertices grows starting with an arbitrary single vertex until A is equal to V. In each step, the vertex which is outside of A, but most tightly connected with A is added to the set A. This procedure can be formally shown as: add vertex z\notin A such that w(A,z)=\max\, where w(A,y) is the sum of the weights of all the edges between A and y. So, in a single phase, a pair of vertices s and t , and a min s\textt cut C is determined. After one phase of the MinimumCutPhase, the two vertices are merged as a new vertex, and edges from the two vertices to a remaining vertex are replaced by an edge weighted by the sum of the weights of the previous two edges. Edges joining the merged nodes are removed. If there is a minimum cut of G separating s and t, the C is a minimum cut of G. If not, then the minimum cut of G must have s and t on a same side. Therefore, the algorithm would merge them as one node. In addition, the MinimumCut would record and update the global minimum cut after each MinimumCutPhase. After n-1 phases, the
minimum cut In graph theory, a minimum cut or min-cut of a graph is a cut (a partition of the vertices of a graph into two disjoint subsets) that is minimal in some metric. Variations of the minimum cut problem consider weighted graphs, directed graphs, te ...
can be determined.


Example

This section refers to Figs. 1–6 in the original paper. The graph in step 1 shows the original graph G and randomly selects node 2 as the starting node for this algorithm. In the MinimumCutPhase, set A only has node 2, the heaviest edge is edge (2,3), so node 3 is added into set A. Next, set A contains node 2 and node 3, the heaviest edge is (3,4), thus node 4 is added to set A. By following this procedure, the last two nodes are node 5 and node 1, which are s and t in this phase. By merging them into node 1+5, the new graph is as shown in step 2. In this phase, the weight of cut is 5, which is the summation of edges (1,2) and (1,5). Right now, the first loop of MinimumCut is completed. In step 2, starting from node 2, the heaviest edge is (2,1+5), thus node 1+5 is put in set A. The next heaviest edges is (2,3) or (1+5,6), we choose (1+5,6) thus node 6 is added to the set. Then we compare edge (2,3) and (6,7) and choose node 3 to put in set A. The last two nodes are node 7 and node 8. Therefore, merge edge (7,8). The minimum cut is 5, so remain the minimum as 5. The following steps repeat the same operations on the merged graph, until there is only one edge in the graph, as shown in step 7. The global minimum cut has edge (2,3) and edge (6,7), which is detected in step 5.


Proof of correctness

To prove the correctness of this algorithm, we need to prove that the cut given by MinimumCutPhase is in fact a minimum s\textt cut of the graph, where s and t are the two vertices last added in the phase. Therefore, a lemma is shown below:
Lemma 1: MinimumCutPhase returns a minimum s\textt-cut of G.
Let C=(X,\overline) be an arbitrary s\textt cut, and CP be the cut given by the phase. We must show that W(C)\ge W(CP). Observe that a single run of MinimumCutPhase gives us an ordering of all the vertices in the graph (where a is the first and s and t are the two vertices added last in the phase). We say the vertex v is active if v and the vertex added just before v are in opposite sides of the cut. We prove the lemma by induction on the set of active vertices. We define A_v as the set of vertices added to A before v, and C_v to be the set of edges in C with both of their ends in A_v \cup \, i.e. C_v \subseteq C is the cut induced by A_v \cup \. We prove, for each active vertex v,
w(A_v,v)\le w(C_v)
Let v_0 be the first active vertex. By the definition of these two quantities, w(A_,v_0) and w(C_) are equivalent. A_ is simply all vertices added to A before v_0, and the edges between these vertices and v_0 are the edges that cross the cut C. Therefore, as shown above, for active vertices v and u, with v added to A before u:
w(A_u,u)=w(A_v,u)+w(A_u-A_v,u)
w(A_u,u)\le w(C_v)+w(A_u-A_v,u) by induction, w(A_v,u)\le w(A_v,v)\le w(C_v)
w(A_,u)\le w(C_) since w(A_u-A_v,u) contributes to w(C_) but not to w(C_) (and other edges are of non-negative weights)
Thus, since t is always an active vertex since the last cut of the phase separates s from t by definition, for any active vertex t:
w(A_t,t)\le w(C_t)=w(C)
Therefore, the cut of the phase is at most as heavy as C.


Time complexity

The
running time In computer science, the time complexity is the computational complexity that describes the amount of computer time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by t ...
of the algorithm MinimumCut is equal to the added running time of the , V, -1 runs of MinimumCutPhase, which is called on graphs with decreasing number of vertices and edges. For the MinimumCutPhase, a single run of it needs at most O(, E, +, V, \log, V, ) time. Therefore, the overall running time should be the product of two phase complexity, which is O(, V, , E, +, V, ^2\log, V, ). For the further improvement, the key is to make it easy to select the next vertex to be added to the set A, the most tightly connected vertex. During execution of a phase, all vertices that are not in A reside in a priority queue based on a key field. The key of a vertex V is the sum of the weights of the edges connecting it to the current A, that is, w(A,v). Whenever a vertex v is added to A we have to perform an update of the queue. v has to be deleted from the queue, and the key of every vertex w not in A, connected to v has to be increased by the weight of the edge vw, if it exists. As this is done exactly once for every edge, overall we have to perform , V, ExtractMax and , E, IncreaseKey operations. By using the
Fibonacci heap In computer science, a Fibonacci heap is a data structure for priority queue operations, consisting of a collection of heap-ordered trees. It has a better amortized running time than many other priority queue data structures including the bina ...
we can perform an ExtractMax operation in O(\log, V, ) amortized time and an IncreaseKey operation in O(1) amortized time. Thus, the time we need for this key step that dominates the rest of the phase, is O(, E, +, V, \log, V, ).


Example code

Below is a concise
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significa ...
implementation of the Stoer–Wagner algorithm. // Adjacency matrix implementation of Stoer–Wagner min cut algorithm. // // Running time: // O(, V, ^3) #include using namespace std; pair> globalMinCut(vector> mat) const int maxn = 550; const int inf = 1000000000; int n, r; int edge
axn AXN is a pay television channel owned by Sony Pictures Television, which was first launched in September 1997 in Asia. Local versions have since been launched in several parts of the world, including Europe, Asia, and Latin America. Funded th ...
maxn], dist
axn AXN is a pay television channel owned by Sony Pictures Television, which was first launched in September 1997 in Asia. Local versions have since been launched in several parts of the world, including Europe, Asia, and Latin America. Funded th ...
bool vis
axn AXN is a pay television channel owned by Sony Pictures Television, which was first launched in September 1997 in Asia. Local versions have since been launched in several parts of the world, including Europe, Asia, and Latin America. Funded th ...
bin
axn AXN is a pay television channel owned by Sony Pictures Television, which was first launched in September 1997 in Asia. Local versions have since been launched in several parts of the world, including Europe, Asia, and Latin America. Funded th ...
void init() int contract( int &s, int &t ) // Find s,t int Stoer_Wagner()


References


External links


StoerWagnerMinCut.java
- a Java library that implements the Stoer–Wagner algorithm {{DEFAULTSORT:Stoer-Wagner algorithm Articles with example C++ code Graph algorithms Graph connectivity