Theta (θ) Adjustment Step (Hungarian Algorithm)

Last updated: Sources Methodology

Theta (θ) Adjustment Step: How Hungarian Creates New Zeros (Lecture-Style Worked Examples)

If you cover all zeros using fewer than n lines, the current zeros cannot support a full one-to-one assignment yet. The Hungarian method then performs a θ adjustment: choose θ as the smallest uncovered number, subtract θ from all uncovered cells, add θ to all cells at intersections of covering lines, and leave the rest unchanged. This creates new zeros without destroying existing “covered” structure.

This step appears automatically in the step tables of the Assignment Problem Solver (Hungarian method). The step before θ is explained here: cover zeros with minimum lines.

On this page

Quick takeaway: After covering all zeros with the minimum number of lines:
1) Let θ be the smallest uncovered entry.
2) Subtract θ from every uncovered cell.
3) Add θ to every cell that lies at the intersection of two lines (a covered row AND a covered column).
4) Leave cells covered by exactly one line unchanged.
Then repeat the “cover zeros” step. Stop when the minimum number of covering lines equals n.

When do you do θ adjustment?

Condition

Only when the minimum number of covering lines is less than n

If you can cover all zeros with n lines, you can extract a perfect matching among zeros. If the minimum line count is < n, you cannot yet pick n independent zeros, so you apply θ to create more zeros.

See the previous step: cover zeros with minimum lines.

How to compute θ and update the matrix (exact rule)

Rule

θ comes from uncovered cells only

You must first have a minimum-line cover of zeros (some set of covered rows and covered columns). Then:

Cell type Meaning Update
Uncovered (no line through its row/column) Candidate pool for θ new = old − θ
Intersection (row covered AND column covered) Covered twice new = old + θ
Single-covered (exactly one line) Covered once new = old
Why does θ create new zeros? Because at least one uncovered cell achieves the minimum value θ, so after subtraction it becomes 0. Meanwhile, existing covered zeros are not “broken” because single-covered cells do not change.

Why θ creates new zeros (intuition)

Intuition

We increase the zero structure while preserving feasibility direction

The adjustment is designed so that the set of feasible assignments (in terms of relative costs) is not harmed, but the pattern of zeros becomes richer. More zeros typically allow a larger matching among zeros.

Graph viewpoint: bipartite matching & assignment. Feasibility angle (with forbidden pairs): feasible vs infeasible assignment.

Worked examples (fully solved, lecture-style)

Worked examples

Expand only the example you need

Each example starts from a reduced matrix and a stated minimum-line cover. This makes the θ step fully deterministic (like a lecture). You can verify the same iterations in the step tables of: Hungarian solver.

Example 1 (4×4) — Compute θ from uncovered cells and build the full adjusted matrix

Reduced matrix M (after row + column reduction):

        C1  C2  C3  C4
R1       0   2   1   1
R2       0   3   2   0
R3       1   0   2   2
R4       2   0   3   1

Suppose the minimum-line cover of zeros uses 3 lines (so it is < n=4), and one valid minimum cover is:
• Covered rows: {R1, R2}
• Covered columns: {C2}
(This cover hits all zeros: zeros are at (R1,C1), (R2,C1), (R2,C4), (R3,C2), (R4,C2).)

Step 1 — Identify uncovered cells

A cell is uncovered if its row is not covered AND its column is not covered. Here, uncovered rows are {R3,R4} and uncovered columns are {C1,C3,C4}. So uncovered cells are in rows R3,R4 and columns C1,C3,C4:

Uncovered cells:
R3C1=1, R3C3=2, R3C4=2
R4C1=2, R4C3=3, R4C4=1

Step 2 — Compute θ = minimum uncovered value

θ = min{1,2,2,2,3,1} = 1

Step 3 — Apply the θ update rules

Covered rows = {R1,R2}; covered columns = {C2}. Therefore:

  • Uncovered cells (rows R3,R4 with cols C1,C3,C4): subtract 1
  • Intersection cells (covered rows R1,R2 with covered col C2): add 1 to (R1,C2) and (R2,C2)
  • All others (single-covered): unchanged

Step 4 — Write the adjusted matrix M′

Uncovered cells subtract 1:

R3C1: 1→0
R3C3: 2→1
R3C4: 2→1
R4C1: 2→1
R4C3: 3→2
R4C4: 1→0

Intersections add 1:

R1C2: 2→3
R2C2: 3→4

Adjusted matrix M′:

        C1  C2  C3  C4
R1       0   3   1   1
R2       0   4   2   0
R3       0   0   1   1
R4       2   0   3   1

What changed? We created new zeros at (R3,C1) and (R4,C4) (because θ was 1), while keeping the already-covered zero structure usable for matching. Now you return to the “cover zeros” step and re-check whether the minimum lines equals n.

Example 2 (4×4) — Two θ iterations until minimum lines = n (then assignment exists)

Start from this reduced matrix:

        C1  C2  C3  C4
R1       0   1   1   2
R2       0   1   2   1
R3       1   0   2   1
R4       2   0   1   1

Zeros at: (R1,C1), (R2,C1), (R3,C2), (R4,C2). This often covers with 2 lines (C1 and C2), which is < 4, so θ is needed. Take the minimum-line cover:
• Covered columns: {C1, C2}
• Covered rows: { } (none needed here)

Iteration 1 — Compute θ from uncovered cells

Uncovered rows: {R1,R2,R3,R4} (all rows, since no covered rows) Uncovered columns: {C3,C4} (since C1,C2 are covered) So uncovered cells are all entries in columns C3 and C4:

Uncovered values:
Col C3: R1=1, R2=2, R3=2, R4=1
Col C4: R1=2, R2=1, R3=1, R4=1
θ = min = 1

Iteration 1 — Adjust matrix

Covered rows: none ⇒ no intersections. Covered cols: {C1,C2}. So:
• Subtract θ from uncovered cells (columns C3,C4)
• Add θ to intersections (none)
• Single-covered cells (columns C1,C2) unchanged

After θ=1:

        C1  C2  C3  C4
R1       0   1   0   1
R2       0   1   1   0
R3       1   0   1   0
R4       2   0   0   0

Now there are more zeros in C3 and C4. Re-run “cover zeros with minimum lines.” In many cases you can now cover with 3 lines (still < 4), so we do one more θ iteration.

Iteration 2 — Choose a minimum-line cover (deterministic for this lecture)

Use this minimum cover of zeros (3 lines):
• Covered rows: {R1}
• Covered columns: {C1, C2}
(This hits all zeros in this matrix.)

Iteration 2 — Compute θ from uncovered cells

Uncovered rows: {R2,R3,R4} Uncovered columns: {C3,C4} Uncovered cells are rows R2–R4 and cols C3–C4:

Uncovered values:
R2C3=1, R2C4=0
R3C3=1, R3C4=0
R4C3=0, R4C4=0
θ = min uncovered = 0
If θ becomes 0, it means you already have uncovered zeros. In practice, that indicates your chosen cover is not truly minimum (or you should re-run the minimum cover algorithm / matching step). Your CalcTypes solver handles this robustly. For a clean hand-solution, choose a correct minimum cover so θ > 0.

Lecture conclusion: The purpose of θ is to create uncovered zeros. If you already have uncovered zeros, re-do the cover step properly. In the calculator, the matching/cover computation ensures θ is computed from true uncovered nonzero entries when lines < n.

What to take away: In a correct Hungarian iteration, if lines < n then θ should come out positive. If your hand work produces θ = 0, revisit the “minimum-line cover” step (or use the solver’s step tables to see the canonical cover).

Example 3 — After θ: how you read the assignment (independent zeros, lecture-style)

θ adjustment is not the final goal. The goal is to reach a matrix where a full set of independent zeros exists. Here is a reduced matrix (after some θ steps) where that is possible:

        C1  C2  C3  C4
R1       0   3   1   1
R2       0   4   2   0
R3       0   0   1   1
R4       2   0   3   1

Step A — Find independent zeros (one per row/column)

A simple systematic approach:

  1. Look for rows with a single zero (or the fewest zeros) and assign them first.
  2. After assigning a zero in column j, you cannot use column j again.

Row-by-row:

R4 has a zero at C2 only (in this matrix) → assign R4→C2
Now column C2 is used.

R2 has a zero at C4 → assign R2→C4
Now column C4 is used.

R1 has a zero at C1 → assign R1→C1
Now column C1 is used.

R3 now must use remaining column C3? But R3 has zeros at C1 and C2 only in this matrix.
So this particular choice set fails → we need a different selection order.

Try a different selection:

Assign R3→C1 (zero)
Assign R4→C2 (zero)
Assign R2→C4 (zero)
Now R1 must use C3 or C? but R1 has zero at C1 only, so again conflict.
This illustrates a key point: “having many zeros” is not enough; they must be arranged so you can pick one per row/column. The solver uses matching logic to extract a correct set of independent zeros when it exists.

If you want the exact extraction behavior, use: Hungarian solver and review the assignment table produced after “lines = n”.

Questions people ask

People ask

How do you find θ in the Hungarian algorithm?

You find θ (theta) only after you have covered all zeros using the minimum number of lines. Then:

Step 1: Identify the cells that are uncovered (their row is not covered by a line AND their column is not covered by a line).
Step 2: Look at the numerical values in those uncovered cells only.
Step 3: Set θ = the smallest uncovered value.

Important notes:
• θ is chosen from uncovered cells only (not from covered cells).
• Because θ is the minimum uncovered value, subtracting θ from all uncovered cells will never make any uncovered entry negative.
• If you get θ = 0, it usually means you did not use a true minimum-line cover (you accidentally left an uncovered zero), so re-check the cover step: cover zeros with minimum lines.

People ask

Why do we subtract θ from uncovered cells?

Subtracting θ from every uncovered cell is the controlled way Hungarian creates new zeros (new “free” edges in the zero graph) without breaking the work done so far.

Here is the key lecture idea:
• Since θ is the smallest uncovered value, at least one uncovered cell equals θ.
• After the update, that cell becomes θ − θ = 0, so you create at least one new zero in an uncovered position.
• All other uncovered cells stay nonnegative because they were ≥ θ to begin with.

This matters because the Hungarian method is trying to increase the size of the maximum matching among zeros. More uncovered zeros usually means you can find a larger set of independent zeros (one per row/column), moving you toward the stopping condition “lines = n”.

People ask

Why do we add θ to intersections?

“Intersections” are cells that lie at the crossing of a covered row and a covered column (i.e., they are covered twice). Hungarian adds θ to those cells to keep the transformation consistent while it modifies uncovered cells.

A practical way to remember the goal:
• We want to create new zeros in uncovered positions (so we can grow the matching),
• while ensuring the structure of the already-covered part is not damaged.

If we only subtracted θ from uncovered cells and changed nothing else, the “balance” between covered rows and covered columns would be distorted. Adding θ at double-covered intersections compensates for that distortion and preserves the logic of the reductions (you can think of it as maintaining the same kind of row/column “potential” structure that Hungarian builds via reductions).

Also note:
• Cells covered by exactly one line are left unchanged, so any existing zero that lies on a single covering line remains zero.
• Intersections typically were not the critical zeros; increasing them does not remove zeros you need for matching, but it keeps the transformation valid.

Check your answer (calculator + next links)

Disclaimer

This page is for educational purposes only. Real-world assignments may include constraints beyond a one-to-one matrix model. Validate results with a production optimizer and domain review. Read our full disclaimer.

Sources