Minimum Cut (Stoer-Wagner) - Problem

Given an undirected weighted graph, find the minimum cut using the Stoer-Wagner algorithm. A minimum cut is the smallest sum of edge weights that, when removed, disconnects the graph into two components.

The graph is represented as an adjacency matrix where graph[i][j] represents the weight of the edge between vertices i and j. If there's no edge, the value is 0.

Return the weight of the minimum cut.

Input & Output

Example 1 — Simple Triangle Graph
$ Input: graph = [[0,2,1],[2,0,1],[1,1,0]]
Output: 1
💡 Note: The graph forms a triangle with edges: 0-1 (weight 2), 0-2 (weight 1), 1-2 (weight 1). The minimum cut is 1, achieved by removing edge 0-2 or edge 1-2, separating one vertex from the other two.
Example 2 — Linear Chain
$ Input: graph = [[0,3,0,0],[3,0,2,0],[0,2,0,1],[0,0,1,0]]
Output: 1
💡 Note: The graph forms a chain: 0-1-2-3 with weights 3,2,1. The minimum cut is 1 (edge 2-3), which separates vertex 3 from the rest of the graph.
Example 3 — Complete Graph
$ Input: graph = [[0,1,1],[1,0,1],[1,1,0]]
Output: 2
💡 Note: Complete graph with all edge weights 1. To disconnect any vertex requires cutting 2 edges, so minimum cut is 2.

Constraints

  • 1 ≤ graph.length ≤ 15
  • graph[i][j] = graph[j][i] (undirected graph)
  • graph[i][i] = 0 (no self-loops)
  • 0 ≤ graph[i][j] ≤ 100

Visualization

Tap to expand
Minimum Cut Problem: Stoer-Wagner AlgorithmINPUT GRAPHALGORITHM STEPSRESULT012211Triangle: edges 0-1(2), 0-2(1), 1-2(1)1Max Adjacency Search2Find tightly connected pairs3Identify cut candidates4Contract vertices & repeatSystematic O(n³) approachMin Cut = 1Cut edge 0-2 or 1-2✓ Disconnects graph✓ Minimum weightKey Insight:The Stoer-Wagner algorithm systematically finds the most connected vertex pairs,naturally revealing minimum cut candidates without checking all possible partitions.TutorialsPoint - Minimum Cut (Stoer-Wagner) | Stoer-Wagner Algorithm
Asked in
Google 15 Meta 12 Microsoft 10 Amazon 8
8.8K Views
Medium Frequency
~35 min Avg. Time
342 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen