Hungarian Method
The Hungarian method is a computational optimization technique that addresses the assignment problem in polynomial time and foreshadows following primal-dual alternatives. In 1955, Harold Kuhn used the term “Hungarian method” to honour two Hungarian mathematicians, Dénes Kőnig and Jenő Egerváry. Let’s go through the steps of the Hungarian method with the help of a solved example.

Hungarian Method to Solve Assignment Problems
The Hungarian method is a simple way to solve assignment problems. Let us first discuss the assignment problems before moving on to learning the Hungarian method.
What is an Assignment Problem?
A transportation problem is a type of assignment problem. The goal is to allocate an equal amount of resources to the same number of activities. As a result, the overall cost of allocation is minimised or the total profit is maximised.
Because available resources such as workers, machines, and other resources have varying degrees of efficiency for executing different activities, and hence the cost, profit, or loss of conducting such activities varies.
Assume we have ‘n’ jobs to do on ‘m’ machines (i.e., one job to one machine). Our goal is to assign jobs to machines for the least amount of money possible (or maximum profit). Based on the notion that each machine can accomplish each task, but at variable levels of efficiency.
Hungarian Method Steps
Check to see if the number of rows and columns are equal; if they are, the assignment problem is considered to be balanced. Then go to step 1. If it is not balanced, it should be balanced before the algorithm is applied.
Step 1 – In the given cost matrix, subtract the least cost element of each row from all the entries in that row. Make sure that each row has at least one zero.
Step 2 – In the resultant cost matrix produced in step 1, subtract the least cost element in each column from all the components in that column, ensuring that each column contains at least one zero.
Step 3 – Assign zeros
- Analyse the rows one by one until you find a row with precisely one unmarked zero. Encircle this lonely unmarked zero and assign it a task. All other zeros in the column of this circular zero should be crossed out because they will not be used in any future assignments. Continue in this manner until you’ve gone through all of the rows.
- Examine the columns one by one until you find one with precisely one unmarked zero. Encircle this single unmarked zero and cross any other zero in its row to make an assignment to it. Continue until you’ve gone through all of the columns.
Step 4 – Perform the Optimal Test
- The present assignment is optimal if each row and column has exactly one encircled zero.
- The present assignment is not optimal if at least one row or column is missing an assignment (i.e., if at least one row or column is missing one encircled zero). Continue to step 5. Subtract the least cost element from all the entries in each column of the final cost matrix created in step 1 and ensure that each column has at least one zero.
Step 5 – Draw the least number of straight lines to cover all of the zeros as follows:
(a) Highlight the rows that aren’t assigned.
(b) Label the columns with zeros in marked rows (if they haven’t already been marked).
(c) Highlight the rows that have assignments in indicated columns (if they haven’t previously been marked).
(d) Continue with (b) and (c) until no further marking is needed.
(f) Simply draw the lines through all rows and columns that are not marked. If the number of these lines equals the order of the matrix, then the solution is optimal; otherwise, it is not.
Step 6 – Find the lowest cost factor that is not covered by the straight lines. Subtract this least-cost component from all the uncovered elements and add it to all the elements that are at the intersection of these straight lines, but leave the rest of the elements alone.
Step 7 – Continue with steps 1 – 6 until you’ve found the highest suitable assignment.
Hungarian Method Example
Use the Hungarian method to solve the given assignment problem stated in the table. The entries in the matrix represent each man’s processing time in hours.
\(\begin{array}{l}\begin{bmatrix} & I & II & III & IV & V \\1 & 20 & 15 & 18 & 20 & 25 \\2 & 18 & 20 & 12 & 14 & 15 \\3 & 21 & 23 & 25 & 27 & 25 \\4 & 17 & 18 & 21 & 23 & 20 \\5 & 18 & 18 & 16 & 19 & 20 \\\end{bmatrix}\end{array} \)
With 5 jobs and 5 men, the stated problem is balanced.
\(\begin{array}{l}A = \begin{bmatrix}20 & 15 & 18 & 20 & 25 \\18 & 20 & 12 & 14 & 15 \\21 & 23 & 25 & 27 & 25 \\17 & 18 & 21 & 23 & 20 \\18 & 18 & 16 & 19 & 20 \\\end{bmatrix}\end{array} \)
Subtract the lowest cost element in each row from all of the elements in the given cost matrix’s row. Make sure that each row has at least one zero.
\(\begin{array}{l}A = \begin{bmatrix}5 & 0 & 3 & 5 & 10 \\6 & 8 & 0 & 2 & 3 \\0 & 2 & 4 & 6 & 4 \\0 & 1 & 4 & 6 & 3 \\2 & 2 & 0 & 3 & 4 \\\end{bmatrix}\end{array} \)
Subtract the least cost element in each Column from all of the components in the given cost matrix’s Column. Check to see if each column has at least one zero.
\(\begin{array}{l}A = \begin{bmatrix}5 & 0 & 3 & 3 & 7 \\6 & 8 & 0 & 0 & 0 \\0 & 2 & 4 & 4 & 1 \\0 & 1 & 4 & 4 & 0 \\2 & 2 & 0 & 1 & 1 \\\end{bmatrix}\end{array} \)
When the zeros are assigned, we get the following:

The present assignment is optimal because each row and column contain precisely one encircled zero.
Where 1 to II, 2 to IV, 3 to I, 4 to V, and 5 to III are the best assignments.
Hence, z = 15 + 14 + 21 + 20 + 16 = 86 hours is the optimal time.
Practice Question on Hungarian Method
Use the Hungarian method to solve the following assignment problem shown in table. The matrix entries represent the time it takes for each job to be processed by each machine in hours.
\(\begin{array}{l}\begin{bmatrix}J/M & I & II & III & IV & V \\1 & 9 & 22 & 58 & 11 & 19 \\2 & 43 & 78 & 72 & 50 & 63 \\3 & 41 & 28 & 91 & 37 & 45 \\4 & 74 & 42 & 27 & 49 & 39 \\5 & 36 & 11 & 57 & 22 & 25 \\\end{bmatrix}\end{array} \)
Stay tuned to BYJU’S – The Learning App and download the app to explore all Maths-related topics.
Frequently Asked Questions on Hungarian Method
What is hungarian method.
The Hungarian method is defined as a combinatorial optimization technique that solves the assignment problems in polynomial time and foreshadowed subsequent primal–dual approaches.
What are the steps involved in Hungarian method?
The following is a quick overview of the Hungarian method: Step 1: Subtract the row minima. Step 2: Subtract the column minimums. Step 3: Use a limited number of lines to cover all zeros. Step 4: Add some more zeros to the equation.
What is the purpose of the Hungarian method?
When workers are assigned to certain activities based on cost, the Hungarian method is beneficial for identifying minimum costs.
Leave a Comment Cancel reply
Your Mobile number and Email id will not be published. Required fields are marked *
Request OTP on Voice Call
Post My Comment

- Share Share
Register with BYJU'S & Download Free PDFs
Register with byju's & watch live videos.


Hungarian Method Examples
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, Example-2

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.
This is a minimization example of assignment problem . We will use the Hungarian Algorithm to solve this problem.
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
Identify the minimum element in each column and subtract it from every element of that column.
Make the assignments for the reduced matrix obtained from steps 1 and 2 in the following way:
- For every zero that becomes assigned, cross out (X) all other zeros in the same row and the same column.
- 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.
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
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:
- Mark all the rows that do not have assignments.
- Mark all the columns (not already marked) which have zeros in the marked rows.
- Mark all the rows (not already marked) that have assignments in marked columns.
- Repeat steps 5 (ii) and (iii) until no more rows or columns can be marked.
- Draw straight lines through all unmarked rows and marked columns.
You can also draw the minimum number of lines by inspection.
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.
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.
Share This Article
Operations Research Simplified Back Next
Goal programming Linear programming Simplex Method Transportation Problem
- DSA for Beginners
- DSA Tutorial
- Data Structures
- Linked List
- Dynamic Programming
- Binary Tree
- Binary Search Tree
- Divide & Conquer
- Mathematical
- Backtracking
- Branch and Bound
- Pattern Searching

- Explore Our Geeks Community
- Hungarian Algorithm for Assignment Problem | Set 1 (Introduction)
- Clustering Coefficient in Graph Theory
- Erdos Renyl Model (for generating Random Graphs)
- Count of nodes with maximum connection in an undirected graph
- Types of Graphs with Examples
- Maximum number of edges in Bipartite graph
- Program to find the number of region in Planar Graph
- Number of Simple Graph with N Vertices and M Edges
- Count of Disjoint Groups by grouping points that are at most K distance apart
- Convert the undirected graph into directed graph such that there is no path of length greater than 1
- Maximize count of nodes disconnected from all other nodes in a Graph
- Cost of painting n * m grid
- Find node having maximum number of common nodes with a given node K
- Ways to Remove Edges from a Complete Graph to make Odd Edges
- Find the sum of the first Nth Centered Pentadecagonal Number
- Check if incoming edges in a vertex of directed graph is equal to vertex itself or not
- Find the sum of the first Nth Centered Hexadecagonal Number
- Horner's Method for Polynomial Evaluation
- Check whether the structure of given Graph is same as the game of Rock-Paper-Scissor
Hungarian Algorithm for Assignment Problem | Set 2 (Implementation)
Given a 2D array , arr of size N*N where arr[i][j] denotes the cost to complete the j th job by the i th worker. Any worker can be assigned to perform any job. The task is to assign the jobs such that exactly one worker can perform exactly one job in such a way that the total cost of the assignment is minimized.
Input: arr[][] = {{3, 5}, {10, 1}} Output: 4 Explanation: The optimal assignment is to assign job 1 to the 1st worker, job 2 to the 2nd worker. Hence, the optimal cost is 3 + 1 = 4. Input: arr[][] = {{2500, 4000, 3500}, {4000, 6000, 3500}, {2000, 4000, 2500}} Output: 4 Explanation: The optimal assignment is to assign job 2 to the 1st worker, job 3 to the 2nd worker and job 1 to the 3rd worker. Hence, the optimal cost is 4000 + 3500 + 2000 = 9500.
Different approaches to solve this problem are discussed in this article .
Approach: The idea is to use the Hungarian Algorithm to solve this problem. The algorithm is as follows:
- For each row of the matrix, find the smallest element and subtract it from every element in its row.
- Repeat the step 1 for all columns.
- Cover all zeros in the matrix using the minimum number of horizontal and vertical lines.
- Test for Optimality : If the minimum number of covering lines is N , an optimal assignment is possible. Else if lines are lesser than N , an optimal assignment is not found and must proceed to step 5.
- Determine the smallest entry not covered by any line. Subtract this entry from each uncovered row, and then add it to each covered column. Return to step 3.
Consider an example to understand the approach:
Let the 2D array be: 2500 4000 3500 4000 6000 3500 2000 4000 2500 Step 1: Subtract minimum of every row. 2500, 3500 and 2000 are subtracted from rows 1, 2 and 3 respectively. 0 1500 1000 500 2500 0 0 2000 500 Step 2: Subtract minimum of every column. 0, 1500 and 0 are subtracted from columns 1, 2 and 3 respectively. 0 0 1000 500 1000 0 0 500 500 Step 3: Cover all zeroes with minimum number of horizontal and vertical lines. Step 4: Since we need 3 lines to cover all zeroes, the optimal assignment is found. 2500 4000 3500 4000 6000 3500 2000 4000 2500 So the optimal cost is 4000 + 3500 + 2000 = 9500
For implementing the above algorithm, the idea is to use the max_cost_assignment() function defined in the dlib library . This function is an implementation of the Hungarian algorithm (also known as the Kuhn-Munkres algorithm) which runs in O(N 3 ) time. It solves the optimal assignment problem.
Below is the implementation of the above approach:
Time Complexity: O(N 3 ) Auxiliary Space: O(N 2 )
- DSA in Java
- DSA in Python
- DSA in JavaScript
Please Login to comment...

- rahulchauhan2020model
Please write us at contrib[email protected] to report any issue with the above content
Improve your Coding Skills with Practice
Procedure, Example Solved Problem | Operations Research - Solution of assignment problems (Hungarian Method) | 12th Business Maths and Statistics : Chapter 10 : Operations Research
Chapter: 12th business maths and statistics : chapter 10 : operations research.
Solution of assignment problems (Hungarian Method)
First check whether the number of rows is equal to the numbers of columns, if it is so, the assignment problem is said to be balanced.
Step :1 Choose the least element in each row and subtract it from all the elements of that row.
Step :2 Choose the least element in each column and subtract it from all the elements of that column. Step 2 has to be performed from the table obtained in step 1.
Step:3 Check whether there is atleast one zero in each row and each column and make an assignment as follows.

Step :4 If each row and each column contains exactly one assignment, then the solution is optimal.
Example 10.7
Solve the following assignment problem. Cell values represent cost of assigning job A, B, C and D to the machines I, II, III and IV.

Here the number of rows and columns are equal.
∴ The given assignment problem is balanced. Now let us find the solution.
Step 1: Select a smallest element in each row and subtract this from all the elements in its row.

Look for atleast one zero in each row and each column.Otherwise go to step 2.
Step 2: Select the smallest element in each column and subtract this from all the elements in its column.

Since each row and column contains atleast one zero, assignments can be made.
Step 3 (Assignment):

Thus all the four assignments have been made. The optimal assignment schedule and total cost is

The optimal assignment (minimum) cost
Example 10.8
Consider the problem of assigning five jobs to five persons. The assignment costs are given as follows. Determine the optimum assignment schedule.

∴ The given assignment problem is balanced.
Now let us find the solution.
The cost matrix of the given assignment problem is

Column 3 contains no zero. Go to Step 2.

Thus all the five assignments have been made. The Optimal assignment schedule and total cost is

The optimal assignment (minimum) cost = ` 9
Example 10.9
Solve the following assignment problem.

Since the number of columns is less than the number of rows, given assignment problem is unbalanced one. To balance it , introduce a dummy column with all the entries zero. The revised assignment problem is

Here only 3 tasks can be assigned to 3 men.
Step 1: is not necessary, since each row contains zero entry. Go to Step 2.

Step 3 (Assignment) :

Since each row and each columncontains exactly one assignment,all the three men have been assigned a task. But task S is not assigned to any Man. The optimal assignment schedule and total cost is

The optimal assignment (minimum) cost = ₹ 35
Related Topics
Privacy Policy , Terms and Conditions , DMCA Policy and Compliant
Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.

Index Assignment problem Hungarian algorithm Solve online
The Hungarian algorithm: An example
We consider an example where four jobs (J1, J2, J3, and J4) need to be executed by four workers (W1, W2, W3, and W4), one job per worker. The matrix below shows the cost of assigning a certain worker to a certain job. The objective is to minimize the total cost of the assignment.
Below we will explain the Hungarian algorithm using this example. Note that a general description of the algorithm can be found here .
Step 1: Subtract row minima
We start with subtracting the row minimum from each row. The smallest element in the first row is, for example, 69. Therefore, we substract 69 from each element in the first row. The resulting matrix is:
Step 2: Subtract column minima
Similarly, we subtract the column minimum from each column, giving the following matrix:
Step 3: Cover all zeros with a minimum number of lines
We will now determine the minimum number of lines (horizontal or vertical) that are required to cover all zeros in the matrix. All zeros can be covered using 3 lines:
Step 4: Create additional zeros
First, we find that the smallest uncovered number is 6. We subtract this number from all uncovered elements and add it to all elements that are covered twice. This results in the following matrix:
Now we return to Step 3.
Again, We determine the minimum number of lines required to cover all zeros in the matrix. Now there are 4 lines required:
Because the number of lines required (4) equals the size of the matrix ( n =4), an optimal assignment exists among the zeros in the matrix. Therefore, the algorithm stops.
The optimal assignment
The following zeros cover an optimal assignment:
This corresponds to the following optimal assignment in the original cost matrix:
Thus, worker 1 should perform job 3, worker 2 job 2, worker 3 job 1, and worker 4 should perform job 4. The total cost of this optimal assignment is to 69 + 37 + 11 + 23 = 140.
Solve your own problem online

HungarianAlgorithm.com © 2013-2023
HungarianAlgorithm.com uses cookies to provide you with an optimal user experience.
Yes, I accept cookies.

The Hungarian method for solving an assignment problem can also be...
The Hungarian method for solving an assignment problem can also be used to solve.
A. A transportation problem
B. A travelling salesman problem
C. A LP problem
D. Both a & b
Answer: Option B
Solution(By Examveda Team)
This Question Belongs to Management >> Operations Research
Join The Discussion
Related Questions on Operations Research
The use of decision models.
A. Is possible when the variables value is known
B. Reduces the scope of judgement & intuition known with certainty in decision-making
C. Require the use of computer software
D. None of the above
Every mathematical model.
A. Must be deterministic
B. Requires computer aid for its solution
C. Represents data in numerical form
D. All of the above
A physical model is example of.
A. An iconic model
B. An analogue model
C. A verbal model
D. A mathematical model
The qualitative approach to decision analysis relies on.
A. Experience
B. Judgement
C. Intuition
More Related Questions on Operations Research
Read More: MCQ Type Questions and Answers
- Arithmetic Ability
- Competitive Reasoning
- Competitive English
- Data Interpretation
- General Knowledge
- State GK
- History
- Geography
- Current Affairs
- Banking Awareness
- Computer Fundamentals
- Networking
- C Program
- Java Program
- Database
- HTML
- Javascript
- Computer Science
- Electronics and Communications Engineering
- Electrical Engineering
- Mechanical Engineering
- Civil Engineering
- Chemical Engineering
- Automobile Engineering
- Biotechnology Engineering
- Mining Engineering
- Commerce
- Management
- Philosophy
- Agriculture
- Sociology
- Political Science
- Pharmacy

IMAGES
VIDEO
COMMENTS
The Hungarian method is a simple way to solve assignment problems. Let us first discuss the assignment problems before moving on to learning the Hungarian method. What is an Assignment Problem? A transportation problem is a type of assignment problem. The goal is to allocate an equal amount of resources to the same number of activities.
Hungarian method calculator . Operation Research - Assignment problem calculator - Find solution of Assignment Problem Hungarian method, step-by-step online
The Hungarian method is a combinatorial optimization algorithm that solves the assignment problem in polynomial time and which anticipated later primal-dual methods.
Solution. 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."
How to Solve an Assignment Problem Using the Hungarian Method Shokoufeh Mirzaei 16.5K subscribers 217K views 5 years ago Linear Programming In this lesson we learn what is an assignment...
The Hungarian algorithm, aka Munkres assignment algorithm, utilizes the following theorem for polynomial runtime complexity ( worst case O (n3)) and guaranteed optimality: If a number is added to or subtracted from all of the entries of any one row or column of a cost matrix, then an optimal assignment for the resulting cost matrix is also an op...
Fill in the cost matrix of an assignment problem and click on 'Solve'. The optimal assignment will be determined and a step by step explanation of the hungarian algorithm will be given. Fill in the cost matrix ( random cost matrix ): Don't show the steps of the Hungarian algorithm Maximize the total cost
The Hungarian algorithm is useful to identify minimum costs when people are assigned to specific activities based on cost. Practice using this algorithm in example equations of real-world...
Different approaches to solve this problem are discussed in this article.. Approach: The idea is to use the Hungarian Algorithm to solve this problem. The algorithm is as follows: For each row of the matrix, find the smallest element and subtract it from every element in its row. Repeat the step 1 for all columns.
Assignment problem using Hungarian method Asked 4 years, 4 months ago Modified 4 years, 4 months ago Viewed 525 times 8 There are five jobs to be assigned to five machines and associated cost matrix is as follows
Solution: Here the number of rows and columns are equal. ∴ The given assignment problem is balanced. Now let us find the solution. Step 1: Select a smallest element in each row and subtract this from all the elements in its row. Look for atleast one zero in each row and each column.Otherwise go to step 2.
4. For finding the best solution in the assignment problem it's easy to use the Hungarian Algorithm. For example: A | 3 4 2 B | 8 9 1 C | 7 9 5. When using the Hungarian Algorithm on this you become: A | 0 0 1 B | 5 5 0 C | 0 1 0. Which means A gets assigned to 'job' 2, B to job 3 and C to job 1. However, I want to find the second best solution ...
An Assignment Problem solved using the Hungarian Algorithm - HungarianAlgorithm.com The Hungarian algorithm: An example We consider an example where four jobs (J1, J2, J3, and J4) need to be executed by four workers (W1, W2, W3, and W4), one job per worker. The matrix below shows the cost of assigning a certain worker to a certain job.
In this section an algorithm to solve assignment problem with generalized interval arithmetic using Hungarian method: Step 1: Find out the mid values of each interval in the cost matrix.
Although the assignment problem can be solved as an ordinary transportation problem or as Linear programming problem, its unique structure can be exploited, resulting in special purpose...
1 Answer Sorted by: 7 The main differences probably are that there is a somewhat large overhead you have to pay when solving the AP as a linear program: You have to build an LP model and ship it to a solver. In addition, an LP solver is a generalist.
Assignment problem (AP) is an entrenched tool for solving engineering and management problems. The Hungarian method is always used to fathom the AP in crisp cases. This paper presents an algorithm of finding the optimum solution of the fuzzy AP by using the modified Hungarian method. This method is utilized to get a minimum assignment cost in the fuzzy environment for a fuzzy AP. Firstly, we ...
Here is the video about assignment problem - Hungarian method with algorithm.NOTE: After row and column scanning, If you stuck with more than one zero in th...
dummy row contains the amount equal 50, and then use the VAM method as usual. First: the solution using the VAM method. The total cost of transportation is equal to 65500. Second: the solution using the Hungarian method. Now, the Hungarian method is applied to solve this problem and find the total cost matrix after adding dummy row in
Question: Qs: solve the following assignment problem using Hungarian method. The matrix entries represent the processing time in hours. A B C D E 5918 19 12 18 11 9 6 ...
Many practitioners and researchers used the Hungarian method in the past to solve assignment problems (Kuhn 1955) ; (Chopra et al. 2017). The existing Hungarian method for solving unbalanced assignment problems is based on the assumption that some jobs should be assigned to dummy or pseudo machines, but those jobs are left unexecuted by
We examine a numerical example by using Hungarian method .The Hungarian method is a systematic procedure, easy to apply for solving assignment problem. Discover the world's research 25+ million ...
The Hungarian method for solving an assignment problem can also be used to solve a travelling salesman problem. The Hungarian method is a combinatorial optimization algorithm that solves the assignment problem in polynomial time and which anticipated later primal-dual methods. This Question Belongs to Management >> Operations Research.