Hungarian Algorithm¶
Definition¶
The Hungarian algorithm solves the square minimum-cost assignment problem. Subtract each row minimum, then each column minimum. Cover all zeros of the resulting matrix with a minimum number of rows and columns. If lines are needed, select independent zeros, one per row and column. Otherwise let be the smallest uncovered entry, subtract from uncovered entries, add to doubly covered entries, leave singly covered entries unchanged, and repeat the covering step.
Interpretation¶
The Hungarian algorithm changes the cost table, without changing which assignment is best, until it contains a complete assignment made of zeros. Since all entries stay nonnegative, such a zero assignment is optimal.
Subtracting the row minima and then the column minima gives the third table, whose zeros can be covered by two lines. Two lines are fewer than three, so no complete zero assignment exists yet. The adjustment by the smallest uncovered entry creates the fourth table, where the three green zeros form the optimal assignment with original cost .
Each step is an assignment cost transformation. The adjustment equals subtracting from every uncovered row and adding to every covered column: uncovered entries lose , doubly covered entries gain , and singly covered entries are unchanged. The constants subtracted in the figure add up to , exactly the optimal cost: every complete assignment costs at least that total, and the zero assignment attains it.
The number of lines must be the minimum, found by a minimum zero cover: it equals the largest number of zeros with no two in the same row or column, so lines mean that a complete zero assignment exists. That largest set of zeros is a largest matching on the zero entries, which can be found as a maximum flow.
Key Results¶
- The zero cover must use the minimum number of lines.
- A set of independent zeros has no two in the same row or column.
- The minimum line-cover size equals the maximum number of independent zero assignments in this construction.
- Do not add together transformed zero costs to report the original objective value.
Examples¶
In the figure, the smallest uncovered entry is 1: subtract 1 from uncovered entries, add 1 at double intersections, and leave singly covered entries unchanged. The final zero assignment has original cost .
- The worked four-machine matrix initially needs three covering lines; an adjustment with enables a complete assignment.
- The final original cost is .
Prerequisites¶
Related Concepts¶
Sources¶
- OR Modelling · Week 5
Aliases: Hungarian method, Kuhn-Munkres algorithm, Munkres algorithm, Kuhn-Munkres method
Last updated: 20 October 2026 03:02
Hungarian AlgorithmMinimum Zero CoverAssignment ProblemAssignment Cost TransformationZero-Cost Matching via Maximum Flow