Skip to content

Business Mathematics and Statistics · Ch 10 — Operations Research (Transportation Problem, Assignment Problems, Decision Theory)

The Hungarian Method

7

The Hungarian Method

The Hungarian Method

The Hungarian Method finds the optimal one-to-one assignment in a square cost matrix without checking every possible permutation (which grows as n!n! and quickly becomes impractical).

Steps of the algorithm

  1. Row reduction: In every row, subtract that row's smallest entry from every entry in the row.
  2. Column reduction: In every column of the row-reduced matrix, subtract that column's smallest entry from every entry in the column.
  3. Cover all zeros in the resulting matrix using the minimum possible number of horizontal and vertical lines.
  4. Test optimality: If the number of lines used equals nn (the size of the matrix), an optimal assignment exists among the zeros — go to Step 6. If fewer than nn lines are needed, go to Step 5.
  5. Adjust the matrix: Find the smallest uncovered entry. Subtract it from every uncovered entry, and add it to every entry lying at the intersection of two covering lines; leave entries covered by only one line unchanged. Return to Step 3.
  6. Make the assignment: Select a set of independent zeros — one per row, one per column — from the final matrix. Compute the total cost by summing the corresponding entries in the original (pre-reduction) cost matrix.

Worked example

A company must assign three workers W1,W2,W3W_1,W_2,W_3 to three jobs J1,J2,J3J_1,J_2,J_3 at minimum total cost (₹ per job):

J1J_1J2J_2J3J_3
W1W_111178
W2W_29712
W3W_313169

Step 1 — Row reduction (row minimums: W1→8W_1\to8, W2→7W_2\to7, W3→9W_3\to9):

J1J_1J2J_2J3J_3
W1W_1390
W2W_2205
W3W_3470

Step 2 — Column reduction (column minimums: J1→2J_1\to2, J2→0J_2\to0, J3→0J_3\to0):

J1J_1J2J_2J3J_3
W1W_1190
W2W_2005
W3W_3270

Step 3 — Cover the zeros: row W2W_2 covers its two zeros (W2J1,W2J2W_2J_1,W_2J_2); column J3J_3 covers its two zeros (W1J3,W3J3W_1J_3,W_3J_3) — all zeros covered using 2 lines.

Step 4 — Test: 2<n=32<n=3 → not yet optimal.

Step 5 — Adjust: the smallest uncovered entry is W1J1=1W_1J_1=1. Subtract 1 from every uncovered cell (W1J1,W1J2,W3J1,W3J2W_1J_1,W_1J_2,W_3J_1,W_3J_2) and add 1 to the intersection cell (W2J3W_2J_3, covered by both lines):

J1J_1J2J_2J3J_3
W1W_1080
W2W_2006
W3W_3160

Step 3 (repeat): column J1J_1 (covers W1J1,W2J1W_1J_1,W_2J_1), column J3J_3 (covers W1J3,W3J3W_1J_3,W_3J_3), row W2W_2 (covers W2J1,W2J2W_2J_1,W_2J_2) — all five zeros covered using 3 lines.

Step 4 (repeat): 3=n=33=n=3 → optimal. …

Definition 1Independent Zeros

A set of zero-cost cells in the reduced matrix chosen so that no two lie in the same row or the same column — exactly one per row and one per column — giving a …