Solving An Assignment Problem Using Hungarian Method Assignment

Now we will examine a few highly simplified illustrations of Hungarian Method for solving an assignment problem.

Later in the chapter, you will find more practical versions of assignment models like Crew assignment problem, Travelling salesman problem, etc.

Example 1: Hungarian Method

The Funny Toys Company has four men available for work on four separate jobs. Only one man can work on any one job. The cost of assigning each man to each job is given in the following table. The objective is to assign men to jobs in such a way that the total cost of assignment is minimum.

Person 1 2 3 4
A 20 25 22 28
B 15 18 23 17
C 19 17 21 24
D 25 23 24 24


This is a minimization example of assignment problem. We will use the Hungarian Algorithm to solve this problem.

Step 1

Identify the minimum element in each row and subtract it from every element of that row. The result is shown in the following table.

"A man has one hundred dollars and you leave him with two dollars, that's subtraction." -Mae West


On small screens, scroll horizontally to view full calculation

Person 1 2 3 4
A 0 5 2 8
B 0 3 8 2
C 2 0 4 7
D 2 0 1 1

Step 2

Identify the minimum element in each column and subtract it from every element of that column.


Person 1 2 3 4
A 0 5 1 7
B 0 3 7 1
C 2 0 3 6
D 2 0 0 0

Step 3

Make the assignments for the reduced matrix obtained from steps 1 and 2 in the following way:

  1. For each row or column with a single zero value cell that has not be assigned or eliminated, box that zero value as an assigned cell.
  2. For every zero that becomes assigned, cross out (X) all other zeros in the same row and the same column.
  3. If for a row and a column, there are two or more zeros and one cannot be chosen by inspection, choose the cell arbitrarily for assignment.
  4. The above process may be continued until every zero cell is either assigned or crossed (X).

Step 4

An optimal assignment is found, if the number of assigned cells equals the number of rows (and columns). In case you have chosen a zero cell arbitrarily, there may be alternate optimal solutions. If no optimal solution is found, go to step 5.


Use Horizontal Scrollbar to View Full Table Calculation

Step 5

Draw the minimum number of vertical and horizontal lines necessary to cover all the zeros in the reduced matrix obtained from step 3 by adopting the following procedure:

  1. Mark all the rows that do not have assignments.
  2. Mark all the columns (not already marked) which have zeros in the marked rows.
  3. Mark all the rows (not already marked) that have assignments in marked columns.
  4. Repeat steps 5 (ii) and (iii) until no more rows or columns can be marked.
  5. Draw straight lines through all unmarked rows and marked columns.

You can also draw the minimum number of lines by inspection.


Step 6

Select the smallest element (i.e., 1) from all the uncovered elements. Subtract this smallest element from all the uncovered elements and add it to the elements, which lie at the intersection of two lines. Thus, we obtain another reduced matrix for fresh assignment.


Person 1 2 3 4
A 0 4 0 6
B 0 2 6 0
C 3 0 3 6
D 3 0 0 0

Now again make the assignments for the reduced matrix.

Final Table: Hungarian Method

Since the number of assignments is equal to the number of rows (& columns), this is the optimal solution.

The total cost of assignment = A1 + B4 + C2 + D3

Substituting values from original table:
20 + 17 + 17 + 24 = Rs. 78.

The Hungarian method is a combinatorial optimizationalgorithm that solves the assignment problem in polynomial time and which anticipated later primal-dual methods. It was developed and published in 1955 by Harold Kuhn, who gave the name "Hungarian method" because the algorithm was largely based on the earlier works of two Hungarian mathematicians: Dénes Kőnig and Jenő Egerváry.[1][2]

James Munkres reviewed the algorithm in 1957 and observed that it is (strongly) polynomial.[3] Since then the algorithm has been known also as the Kuhn–Munkres algorithm or Munkres assignment algorithm. The time complexity of the original algorithm was , however Edmonds and Karp, and independently Tomizawa noticed that it can be modified to achieve an running time. Ford and Fulkerson extended the method to general transportation problems.[citation needed] In 2006, it was discovered that Carl Gustav Jacobi had solved the assignment problem in the 19th century, and the solution had been published posthumously in 1890 in Latin.[4]

Simple explanation of the assignment problem[edit]

In this simple example there are three workers: Armond, Francine, and Herbert. One of them has to clean the bathroom, another sweep the floors and the third washes the windows, but they each demand different pay for the various tasks. The problem is to find the lowest-cost way to assign the jobs. The problem can be represented in a matrix of the costs of the workers doing the jobs. For example:

Clean bathroomSweep floorsWash windows

The Hungarian method, when applied to the above table, would give the minimum cost: this is $6, achieved by having Armond clean the bathroom, Francine sweep the floors, and Herbert wash the windows.


We are given a nonnegative n×nmatrix, where the element in the i-th row and j-th column represents the cost of assigning the j-th job to the i-th worker. We have to find an assignment of the jobs to the workers that has minimum cost. If the goal is to find the assignment that yields the maximum cost, the problem can be altered to fit the setting by replacing each cost with the maximum cost subtracted by the cost.

The algorithm is easier to describe if we formulate the problem using a bipartite graph. We have a complete bipartite graph with worker vertices () and job vertices (), and each edge has a nonnegative cost . We want to find a perfect matching with minimum cost.

Let us call a function a potential if for each . The value of potential is . It can be seen that the cost of each perfect matching is at least the value of each potential. The Hungarian method finds a perfect matching and a potential with equal cost/value which proves the optimality of both. In fact it finds a perfect matching of tight edges: an edge is called tight for a potential if . Let us denote the subgraph of tight edges by . The cost of a perfect matching in (if there is one) equals the value of .

The algorithm in terms of bipartite graphs[edit]

During the algorithm we maintain a potential y and an orientation of (denoted by ) which has the property that the edges oriented from T to S form a matching M. Initially, y is 0 everywhere, and all edges are oriented from S to T (so M is empty). In each step, either we modify y so that its value increases, or modify the orientation to obtain a matching with more edges. We maintain the invariant that all the edges of M are tight. We are done if M is a perfect matching.

In a general step, let and be the vertices not covered by M (so consists of the vertices in S with no incoming edge and consists of the vertices in T with no outgoing edge). Let be the set of vertices reachable in from by a directed path only following edges that are tight. This can be computed by breadth-first search.

If is nonempty, then reverse the orientation of a directed path in from to . Thus the size of the corresponding matching increases by 1.

If is empty, then let . is positive because there are no tight edges between and . Increase y by on the vertices of and decrease y by on the vertices of . The resulting y is still a potential. The graph changes, but it still contains M. We orient the new edges from S to T. By the definition of the set Z of vertices reachable from increases (note that the number of tight edges does not necessarily increase).

We repeat these steps until M is a perfect matching, in which case it gives a minimum cost assignment. The running time of this version of the method is : M is augmented n times, and in a phase where M is unchanged, there are at most n potential changes (since Z increases every time). The time needed for a potential change is .

Matrix interpretation[edit]

Given workers and tasks, and an n×n matrix containing the cost of assigning each worker to a task, find the cost minimizing assignment.

First the problem is written in the form of a matrix as given below


where a, b, c and d are the workers who have to perform tasks 1, 2, 3 and 4. a1, a2, a3, a4 denote the penalties incurred when worker "a" does task 1, 2, 3, 4 respectively. The same holds true for the other symbols as well. The matrix is square, so each worker can perform only one task.

Step 1

Then we perform row operations on the matrix. To do this, the lowest of all ai (i belonging to 1-4) is taken and is subtracted from each element in that row. This will lead to at least one zero in that row (We get multiple zeros when there are two equal elements which also happen to be the lowest in that row). This procedure is repeated for all rows. We now have a matrix with at least one zero per row. Now we try to assign tasks to agents such that each agent is doing only one task and the penalty incurred in each case is zero. This is illustrated below.


The zeros that are indicated as 0' are the assigned tasks.

Step 2

Sometimes it may turn out that the matrix at this stage cannot be used for assigning, as is the case for the matrix below.


In the above case, no assignment can be made. Note that task 1 is done efficiently by both agent a and c. Both can't be assigned the same task. Also note that no one does task 3 efficiently. To overcome this, we repeat the above procedure for all columns (i.e. the minimum element in each column is subtracted from all the elements in that column) and then check if an assignment is possible.

In most situations this will give the result, but if it is still not possible then we need to keep going.

Step 3

All zeros in the matrix must be covered by marking as few rows and/or columns as possible. The following procedure is one way to accomplish this:

First, assign as many tasks as possible.

  • Row 1 has one zero, so it is assigned. The 0 in row 3 is crossed out because it is in the same column.
  • Row 2 has one zero, so it is assigned.
  • Row 3's only zero has been crossed out, so nothing is assigned.
  • Row 4 has two uncrossed zeros. Either one can be assigned (both are optimum), and the other zero would be crossed out.

Alternatively, the 0 in row 3 may be assigned, causing the 0 in row 1 to be crossed instead.


Now to the drawing part.

  • Mark all rows having no assignments (row 3).
  • Mark all (unmarked) columns having zeros in newly marked row(s) (column 1).
  • Mark all rows having assignments in newly marked columns (row 1).
  • Repeat for all non-assigned rows.

Now draw lines through all marked columns and unmarked rows.


The aforementioned detailed description is just one way to draw the minimum number of lines to cover all the 0s. Other methods work as well.

Step 4

From the elements that are left, find the lowest value. Subtract this from every unmarked element and add it to every element covered by two lines.

Repeat steps 3–4 until an assignment is possible; this is when the minimum number of lines used to cover all the 0s is equal to max(number of people, number of assignments), assuming dummy variables (usually the max cost) are used to fill in when the number of people is greater than the number of assignments.

Basically you find the second minimum cost among the remaining choices. The procedure is repeated until you are able to distinguish among the workers in terms of least cost.


  • R.E. Burkard, M. Dell'Amico, S. Martello: Assignment Problems (Revised reprint). SIAM, Philadelphia (PA.) 2012. ISBN 978-1-61197-222-1
  • M. Fischetti, "Lezioni di Ricerca Operativa", Edizioni Libreria Progetto Padova, Italia, 1995.
  • R. Ahuja, T. Magnanti, J. Orlin, "Network Flows", Prentice Hall, 1993.
  • S. Martello, "Jeno Egerváry: from the origins of the Hungarian algorithm to satellite communication". Central European Journal of Operations Research 18, 47–58, 2010


External links[edit]

  • Bruff, Derek, "The Assignment Problem and the Hungarian Method", [1]
  • Mordecai J. Golin, Bipartite Matching and the Hungarian Method, Course Notes, Hong Kong University of Science and Technology.
  • R. A. Pilgrim, Munkres' Assignment Algorithm. Modified for Rectangular Matrices, Course notes, Murray State University.
  • Mike Dawes, The Optimal Assignment Problem, Course notes, University of Western Ontario.
  • On Kuhn's Hungarian Method – A tribute from Hungary, András Frank, Egervary Research Group, Pazmany P. setany 1/C, H1117, Budapest, Hungary.
  • Lecture: Fundamentals of Operations Research - Assignment Problem - Hungarian Algorithm, Prof. G. Srinivasan, Department of Management Studies, IIT Madras.
  • Extension: Assignment sensitivity analysis (with O(n^4) time complexity), Liu, Shell.
  • Solve any Assignment Problem online, provides a step by step explanation of the Hungarian Algorithm.
  1. ^Harold W. Kuhn, "The Hungarian Method for the assignment problem", Naval Research Logistics Quarterly, 2: 83–97, 1955. Kuhn's original publication.
  2. ^Harold W. Kuhn, "Variants of the Hungarian method for assignment problems", Naval Research Logistics Quarterly, 3: 253–258, 1956.
  3. ^J. Munkres, "Algorithms for the Assignment and Transportation Problems", Journal of the Society for Industrial and Applied Mathematics, 5(1):32–38, 1957 March.
  4. ^

0 thoughts on “Solving An Assignment Problem Using Hungarian Method Assignment

Leave a Reply

Your email address will not be published. Required fields are marked *