Jump to content

Stoer–Wagner algorithm

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Shuaiqicao (talk | contribs) at 06:58, 7 December 2015 (v1). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Stoer-Wagner Minimum Cut Algorithm

The Stoer Wanger algorithm is a recursive algorithm to solve the minimum cut problem in undirected weighted graphs. This algorithm 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.[1] Let  be a weighted undirected graph. Let  be a global min-cut of . Suppose that . If , then the  is obviously a s-t min-cut of .[2]

This algorithm starts by finding a s-t min-cut  of , for the two vertices . For the pair of , it has two different situations:  is a global min-cut of ; or they belong to the same side of the global min-cut of . Therefore, the global min-cut can be found by checking the graph , 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 +.[2] The algorithm is described as:[1]

  • MinimumCutPhase

while 

add to  the most tightly connected vertex

store the cut-of-the-phase and shrink  by merging the two vertices added last(Contract  and )

  • MinimumCut

while 

MinimumCutPhase

If the cut-of-the-phase is lighter than the current minimum cut

store the cut-of-the-phase as the current minimum cut

The algorithm works in phases. In the MinimumCutPhase, the subset  of the graphs vertices grows starting with an arbitrary single vertex until  is equal to  . In each step, the vertex which is outside of , but most tightly connected with  is added. This procedure can be formally shown as:[1] add vertex  such that . Where the  is the sum of the weights of all the edges between  and . So, in a single phase, a pair of vertices  and  , and a min  cut  is determined.[3] After one phase of the MinimumCutPhase, the two vertices are replaced by 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  separating  and , the  is a minimum cut of . If not, then the minimum cut of  must has  and  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  phases, the minimum cut must be determined.[3]

Stoer-wagner algorithm
The diagram show seven steps (MinimumCutPhase) to shrink the graph and find the minimum cut in the graph. In each step, the s and t are found then merged. Finally, The minimum cut of the graph G is the fifth cut-of-the-phase and the weight is w=4.

Proof of Correctness 

To prove the correctness of this algorithm, We need to prove that MinCutPhase is in fact a minimum  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: MinCutPhase returns a min s-t-cut of G.

We prove this by induction on the set of active vertices. Let  be an arbitrary  cut, and  be the cut of the phase. We must show that . Observe that single run of MinimumCutPhase gives us a permutation of all the vertices in the graph (where  is the first and  and  are the two vertices added last in the phase). So, we say that the vertex  is active if , the vertex before  in the ordering of vertices produced by MinimumCutPhase is in  or vice versa, which is to say, they’re on opposite sides of the cut. We define  as the set of vertices added to  before  and  to be the cut of the set induced by . For all the active vertex :

Let  be the first active vertex. By the definition of these two quantities, the  and  are equivalent.  is simply all vertices added to  before , and the edges between these vertices and  are the edges that cross the cut . Therefore, as shown above, For the active vertex  and  ( is added to  before ).

 by introduction, 

   contributes to  but not 

Thus, since  is always an active vertex since the last cut of the phase separates  from  by definition, for any active vertex :

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

Time Complexity 

The running time of the algorithm MinimumCut is equal to the added running time of the  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  time.

Therefore, the overall runtime is .[1]

Example Code[4]

const int maxn = 550;  
const int inf = 1000000000;  
int n, r;  
int edge[maxn][maxn], dist[maxn];  
bool vis[maxn], bin[maxn];  
void init()  
{  
    memset(edge, 0, sizeof(edge));  
    memset(bin, false, sizeof(bin));  
}  
int contract( int &s, int &t )          // Find s,t  
{  
    memset(dist, 0, sizeof(dist));  
    memset(vis, false, sizeof(vis));  
    int i, j, k, mincut, maxc;  
    for(i = 1; i <= n; i++)  
    {  
        k = -1; maxc = -1;  
        for(j = 1; j <= n; j++)if(!bin[j] && !vis[j] && dist[j] > maxc)  
        {  
            k = j;  maxc = dist[j];  
        }  
        if(k == -1)return mincut;  
        s = t;  t = k;  
        mincut = maxc;  
        vis[k] = true;  
        for(j = 1; j <= n; j++)if(!bin[j] && !vis[j])  
            dist[j] += edge[k][j];  
    }  
    return mincut;  
}  
int Stoer_Wagner()  
{  
    int mincut, i, j, s, t, ans;  
    for(mincut = inf, i = 1; i < n; i++)  
    {  
        ans = contract( s, t );  
        bin[t] = true;  
        if(mincut > ans)mincut = ans;  
        if(mincut == 0)return 0;  
        for(j = 1; j <= n; j++)if(!bin[j])  
            edge[s][j] = (edge[j][s] += edge[j][t]);  
    }  
    return mincut;  
}
  1. ^ a b c d "A Simple Min-Cut Algorithm" (PDF).
  2. ^ a b "Lecture notes for Analysis of Algorithms": Global minimum cuts" (PDF).
  3. ^ a b "The minimum cut algorithm of Stoer and Wagner" (PDF).
  4. ^ "Store-Wagner Algorithm Analysis".