ArticleslgStudy

computer science

Hungarian algorithm

Hungarian algorithm is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Hungarian algorithm rather than just read about it. In short: The Hungarian algorithm or Hungarian method is a combinatorial optimization algorithm 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 it 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.

Key takeaways

  • Hungarian algorithm belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Hungarian algorithm to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Hungarian algorithm from memory before moving on to harder problems.

Reference excerpt

The Hungarian algorithm or Hungarian method is a combinatorial optimization algorithm 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 it 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. However, 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. James Munkres reviewed the algorithm in 1957 and observed that it is (strongly) polynomial. 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 O ( n 4 ) {\displaystyle O(n^{4})} , however Edmonds and Karp, and independently Tomizawa, noticed that it can be modified to achieve an O ( n 3 ) {\displaystyle O(n^{3})} running time. Ford and Fulkerson extended the method to general maximum flow problems in the form of the Ford–Fulkerson algorithm.

The problem

Example In this simple example, there are three workers: Alice, Bob and Carol. 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:

The Hungarian method, when applied to the above table, would give the minimum cost: this is $15, achieved by having Alice clean the bathroom, Carol sweep the floors, and Bob wash the windows. This can be confirmed using brute force:

(the unassigned person washes the windows)

Matrix formulation In the matrix formulation, we are given an n×n matrix, 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, such that each job is assigned to one worker and each worker is assigned one job, such that the total cost of assignment is minimum. This can be expressed as permuting the rows of a cost matrix C to minimize the trace of a matrix,

min P Tr ⁡ ( P C ) , {\displaystyle \min _{P}\operatorname {Tr} (PC)\;,}

where P is a permutation matrix. (Equivalently, the columns can be permuted using CP.) If the goal is to find the assignment that yields the maximum cost, the problem can be solved by negating the cost matrix C.

Bipartite graph formulation The algorithm can equivalently be described by formulating the problem using a bipartite graph. We have a complete bipartite graph G = ( S , T ; E ) {\displaystyle G=(S,T;E)} with n worker vertices (S) and n job vertices (T), and the edges (E) each have a cost c ( i , j ) {\displaystyle c(i,j)} . We want to find a perfect matching with a minimum total cost.

The algorithm in terms of bipartite graphs Let us call a function y : ( S ∪ T ) → R {\displaystyle y:(S\cup T)\to \mathbb {R} } a potential if y ( i ) + y ( j ) ≤ c ( i , j ) {\displaystyle y(i)+y(j)\leq c(i,j)} for each i ∈ S , j ∈ T {\displaystyle i\in S,j\in T} . The value of potential y is the sum of the potential over all vertices:

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Hungarian algorithm

Start with the simplest possible case. Write down what Hungarian algorithm claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Hungarian algorithm before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Hungarian algorithm ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Hungarian algorithm

In research
Hungarian algorithm appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Hungarian algorithm in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Hungarian algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics Combinatorial optimization, Matching (graph theory), so understanding it makes those chapters shorter.
In everyday life
Look for Hungarian algorithm outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Hungarian algorithm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Hungarian algorithm means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Hungarian algorithm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Hungarian algorithm in simple terms?

The Hungarian algorithm or Hungarian method is a combinatorial optimization algorithm 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 it the name "Hungarian method" because the alg…

Why does Hungarian algorithm matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Hungarian algorithm?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Hungarian algorithm.

Tags

  • Combinatorial optimization
  • Matching (graph theory)

Keep exploring