Trisha Shetty (Editor)

Stoer–Wagner algorithm

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Stoer–Wagner algorithm

In graph theory, the Stoer–Wagner algorithm is a recursive algorithm to solve the minimum cut problem in undirected 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. After each shrinking, the weight of the merged cut would be stored in a list. Finally, the minimum weight cut in the list will be the minimum of the graph.

Contents

A cut is a partition of the vertices of a graph into two disjoint subsets. A minimum cut 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, to explore the maximum capacity of a network, 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. Let ( S , T ) be a global min-cut of G . Suppose that s , t V . If exactly one of s or t is in S , then ( S , T ) is also a s - t min-cut of G .

This algorithm starts by finding a s-t min-cut ( S , T ) of G , for the two vertices { s , t } V . For the pair of ( S , T ) , it has two different situations: ( S , T ) is a global min-cut of G ; or they 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 / { s , t } , which is the graph after the merging of vertices s and t . 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 { a } while   A V add to A the most tightly connected vertex store the cut-of-the-phase and shrink G by merging the two vertices added last
  • 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 A such that w ( A , z ) = max { w ( A , y y A ) } , 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 - t 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 can be determined.

    Example

    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, 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,15), thus node 15 is put in set A . The next heaviest edges is (2,3) or (15,6), we choose (15,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 MinimumCutPhase is in fact a minimum s - t 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 - t -cut of G .

    We prove this by induction on the set of active vertices. Let C = ( X , X ¯ ) be an arbitrary s - t cut, and C P be the cut of the phase. We must show that W ( C ) W ( C P ) . Observe that a single run of MinimumCutPhase gives us a permutation 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). So, we say that the vertex v is active if v X , the vertex before v in the ordering of vertices produced by MinimumCutPhase is in X ¯ or vice versa, which is to say, they’re on opposite sides of the cut. We define A v as the set of vertices added to A before v and C v to be the cut of the set A v { v } induced by C . For all the active vertex v :

    w ( A v , v ) w ( C v )

    Let v 0 be the first active vertex. By the definition of these two quantities, the w ( A v 0 , v 0 ) and w ( C v 0 ) are equivalent. A v 0 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 the active vertex u and v ( v is added to A before u ):

    w ( A u , u ) = w ( A v , u ) + w ( A u A v , u )

    w ( A u , u ) w ( C v ) + w ( A u A v , u ) by induction, w ( A v , u ) w ( A v , v ) w ( C v )

    w ( A u , u ) w ( C u ) since w ( A u A v , u ) contributes to w ( C u ) but not to w ( C v ) (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 ) w ( C t ) = w ( C )

    Therefore, the cut of the phase is at most as heavy as C .

    Time complexity

    The running time 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 | ) [2].

    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 v w , 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 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 | ) .

    References

    Stoer–Wagner algorithm Wikipedia