The Hungarian Algorithm (Kuhn 1955, Munkres 1957) finds a maximum-weight perfect matching in a bipartite graph. Unlike Gale-Shapley which optimizes stability with ordinal preferences, Hungarian optimizes total social welfare with cardinal utilities.
1. ROW REDUCTION: Subtract the minimum of each row from all elements in that row 2. COLUMN REDUCTION: Subtract the minimum of each column from all elements in that column 3. COVER ZEROS: Find minimum number of lines (rows/cols) to cover all zeros 4. CHECK: If #lines = n, optimal assignment exists among zeros. Done! 5. UPDATE: Find minimum uncovered value. Subtract from uncovered elements, add to doubly-covered. Go to step 3. Time complexity: O(n^3)
Click any cell in the matrix to edit values, then run the algorithm.
Gale-Shapley optimizes STABILITY (no blocking pairs) using ordinal preferences.
Hungarian Algorithm optimizes TOTAL WELFARE (maximum social utility) using cardinal values.
These are fundamentally different objectives. A stable matching may not maximize total welfare, and a welfare-maximizing matching may not be stable.
Kuhn (1955) / Munkres (1957) — Maximum Weight Perfect Matching in O(n^3)