Resources For Teachers For Tutors For Students & Parents AI New Books Pricing
Year 12 Maths - General (Unit 3 & Unit 4) Flow and matching problems

Bipartite graphs and matching problems

20 practice questions 0 video lessons Theory + worked examples

Learn how to match people to jobs in the best possible way in Year 12 VCE General Mathematics. A lifesaving club rostering patrols to Mornington Peninsula beaches, a council sending crews to roadworks or a coach choosing relay legs all face the same puzzle: each person does one job, and the total time or cost should be as low as it can be.

You will show these problems as a bipartite graph, a table and a matrix, move between the three forms, and handle pairings that are not allowed. For small problems you will list every allocation and pick the minimum or maximum total, and see why grabbing the cheapest pairing first can fail, which sets up the Hungarian algorithm for larger problems.

Create a free accountTrack your progress and save your work as you go.
Create free account

Theory

Who should do which job? This Year 12 General Mathematics guide for students in Victoria shows how to set up a matching problem as a bipartite graph, a table or a matrix, and how to find the minimum-cost or maximum-profit allocation of a small problem by listing every allocation and comparing the totals.

A matching problem (also called an allocation or assignment problem) matches a group of workers to a group of tasks, one task each, so that the total cost, time or distance is as small as possible, or the total profit or score is as large as possible. Each way of matching them is called an allocation and is written as pairs, such as \(A\)–\(Z\), \(B\)–\(Y\), \(C\)–\(X\).

A bipartite graph shows the problem. Its vertices are split into two groups, workers on one side and tasks on the other, and every edge joins a worker to a task. An edge means that worker can do that task, and its weight is the cost (or profit) of that pairing. A missing edge means the pairing is not possible.

The same information can be written as a table or a matrix, with one row for each worker and one column for each task, in a stated order. A dash marks a pairing that cannot happen. With \(n\) workers and \(n\) tasks there are \(n \times (n - 1) \times \dots \times 1\) allocations, so a \(3 \times 3\) problem has \(6\), few enough to check by inspection.

Key idea. For a small problem, list every allocation with its total, then choose the smallest total for costs or times and the largest total for profits or scores. Each worker and each task must be used exactly once.
A weighted bipartite graphWorkers A, B, C on the left and tasks X, Y, Z on the right. Each edge joins a worker to a task with a cost: A-X 5, A-Y 8, A-Z 6, B-X 7, B-Y 4, B-Z 9, C-X 6, C-Y 7, C-Z 8. A B C X Y Z 5 8 6 7 4 9 6 7 8
A weighted bipartite graph: workers \(A\), \(B\), \(C\) (green) and tasks \(X\), \(Y\), \(Z\) (amber). Each weight, written near the worker, is the cost of that pairing.
The minimum-cost allocationThe allocation A-Z 6, B-Y 4, C-X 6, total 16, shown in red. A B C X Y Z 5 8 6 7 4 9 6 7 8
The cheapest allocation is \(A\)–\(Z\), \(B\)–\(Y\), \(C\)–\(X\), with total \(6 + 4 + 6 = 16\). Each worker and each task has exactly one red edge.

The same problem as a table (rows = workers \(A, B, C\); columns = tasks \(X, Y, Z\)) and as a matrix:

XYZ
A586
B749
C678
\[\begin{bmatrix}5 & 8 & 6\\ 7 & 4 & 9\\ 6 & 7 & 8\end{bmatrix}\]
cost matrix, rows A B C, columns X Y Z

Number of possible allocations for \(n\) workers and \(n\) tasks (no pairings ruled out):

\[n \times (n - 1) \times \dots \times 2 \times 1 \qquad 2 \times 2: 2 \qquad 3 \times 3: 6\]
n×(n-1)×…×1

Total of an allocation:

\[\text{total} = \text{sum of the chosen entries, one from each row and each column}\]
total=∑one entry from each row and column

Drawing the bipartite graph from a table

  1. Put the workers in a column on the left and the tasks in a column on the right.
  2. For each entry in the table that is not a dash, join that worker to that task and write the number on the edge.
  3. Check that no edge joins two workers or two tasks.

Finding the best allocation by inspection

  1. List every allocation. Fix the first worker’s task, then go through the ways of giving out the rest. Skip any pairing marked with a dash.
  2. Total each allocation using the table, one line each.
  3. Choose the optimum: the smallest total for cost, time or distance, the largest for profit or score.
  4. State the allocation as worker–task pairs and give the total with units.

When some pairings are not possible

  1. Start with a worker (or task) that has only one edge, a vertex of degree 1: that pairing is forced.
  2. Cross out that task and worker, then look again for anyone left with only one choice.
  3. If everyone left has two or more choices, try each one in turn and follow it through.
Example 1 — From a table to a bipartite graph
Three volunteers, \(K\), \(L\) and \(M\), at the Royal Melbourne Show are each to run one of three stalls, \(X\), \(Y\) and \(Z\). A tick shows a stall the volunteer is trained for.
XYZ
K✓✓–
L✓–✓
M–✓✓
(i) Draw a bipartite graph. (ii) List every possible allocation.
Solution

Join each volunteer to each stall with a tick. Then try each stall for \(K\).

Example 1 bipartite graphVolunteers K, L, M and stalls X, Y, Z. Edges K-X, K-Y, L-X, L-Z, M-Y, M-Z. K L M X Y Z
\(K\text{–}X\)\(:\)\(L \text{ must take } Z,\ M \text{ takes } Y\)
\(K\text{–}Y\)\(:\)\(M \text{ must take } Z,\ L \text{ takes } X\)
2 allocations

(i) The graph has six edges, one for each tick. (ii) There are only two allocations: \(K–X, L–Z, M–Y\) and \(K–Y, L–X, M–Z\). The dashes rule out the other four.

Example 2 — Minimum distance by inspection
A Dandenong bus depot sends buses \(P\), \(Q\) and \(R\) to the starts of routes \(1\), \(2\) and \(3\). The bipartite graph shows the empty running distance in km. Find the allocation with the smallest total distance.
Solution

A \(3 \times 3\) problem has \(6\) allocations. List and total them all.

Example 2 buses and routesBuses P, Q, R and routes 1, 2, 3 with distances in km: P-1 14, P-2 9, P-3 12, Q-1 11, Q-2 13, Q-3 8, R-1 10, R-2 15, R-3 16. P Q R 1 2 3 14 9 12 11 13 8 10 15 16
AllocationTotal
P–1, Q–2, R–3\(14 + 13 + 16 = 43\)
P–1, Q–3, R–2\(14 + 8 + 15 = 37\)
P–2, Q–1, R–3\(9 + 11 + 16 = 36\)
P–2, Q–3, R–1\(9 + 8 + 10 = 27\)
P–3, Q–1, R–2\(12 + 11 + 15 = 38\)
P–3, Q–2, R–1\(12 + 13 + 10 = 35\)
minimum=27km

The smallest total is 27 km, from \(P–2, Q–3, R–1\). Notice that \(R\) takes route \(1\) even though \(R\)–\(1\) is not the smallest number in the table.

Example 3 — Maximum sales
Three staff, \(D\), \(E\) and \(F\), are to work one each of three food vans, \(X\), \(Y\) and \(Z\), at the Queen Victoria Market. The table gives expected sales in hundreds of dollars. Find the allocation that gives the greatest total sales.
XYZ
D659
E783
F965
Solution

This time choose the largest total.

AllocationTotal
D–X, E–Y, F–Z\(6 + 8 + 5 = 19\)
D–X, E–Z, F–Y\(6 + 3 + 6 = 15\)
D–Y, E–X, F–Z\(5 + 7 + 5 = 17\)
D–Y, E–Z, F–X\(5 + 3 + 9 = 17\)
D–Z, E–X, F–Y\(9 + 7 + 6 = 22\)
D–Z, E–Y, F–X\(9 + 8 + 9 = 26\)
maximum=26

The largest total is \(26\) hundred dollars, from \(D–Z, E–Y, F–X\). Expected sales are $2600. (The smallest total, \(15\), would be the worst choice here.)

Example 4 — Why cheapest-first fails
Three plumbers, \(P\), \(Q\) and \(R\), are sent to three jobs, \(X\), \(Y\) and \(Z\), in Shepparton. The matrix gives travel times in minutes (rows \(P, Q, R\); columns \(X, Y, Z\)).
\[\begin{bmatrix}3 & 6 & 9\\ 4 & 10 & 14\\ 8 & 7 & 12\end{bmatrix}\]
(i) A dispatcher gives out the jobs by always taking the smallest time left. What total does this give? (ii) Find the true minimum total time.
Solution

(i) Take the smallest entry, cross out its row and column, and repeat.

\(\text{smallest left}\)\(:\)\(P\text{–}X = 3\)
\(\text{smallest left}\)\(:\)\(R\text{–}Y = 7\)
\(\text{smallest left}\)\(:\)\(Q\text{–}Z = 14\)
\(\text{total}\)\(=\)\(3 + 7 + 14\)
\(\)\(=\)\(24\ \text{min}\)

(ii) Now check all six allocations:

AllocationTotal
P–X, Q–Y, R–Z\(3 + 10 + 12 = 25\)
P–X, Q–Z, R–Y\(3 + 14 + 7 = 24\)
P–Y, Q–X, R–Z\(6 + 4 + 12 = 22\)
P–Y, Q–Z, R–X\(6 + 14 + 8 = 28\)
P–Z, Q–X, R–Y\(9 + 4 + 7 = 20\)
P–Z, Q–Y, R–X\(9 + 10 + 8 = 27\)
Example 4 optimum allocationThe minimum allocation P-Z 9, Q-X 4, R-Y 7, total 20, in red. P Q R X Y Z 3 6 9 4 10 14 8 7 12
24,20

(i) Cheapest-first gives \(24\) minutes. (ii) The minimum is 20 minutes, from \(P–Z, Q–X, R–Y\). Grabbing the \(3\) first forced \(Q\) into the \(14\)-minute job.

Common pitfalls

Using a worker or task twice. In an allocation every row and every column is used exactly once. Watch out for picking the smallest number in each row when two rows share a column.
Cheapest first. Taking the smallest entry and then the next smallest left does not always give the optimum. Watch out for skipping the full list of allocations.
Minimum or maximum? Costs, times and distances want the smallest total; profits, sales and scores want the largest. Watch out for choosing the wrong end of the list.

Frequently asked questions

What is a bipartite graph?

It is a graph whose vertices split into two groups so that every edge joins a vertex in one group to a vertex in the other. In allocation problems one group is the workers and the other is the tasks.

What is a matching or allocation problem?

It is the problem of matching each worker to exactly one task so that the total cost or time is as small as possible, or the total profit is as large as possible.

How many allocations are there for 3 workers and 3 tasks?

There are 3 x 2 x 1 = 6. The first worker has 3 choices, the second has 2 left and the last has 1. For 2 workers and 2 tasks there are only 2.

What does a dash mean in an allocation table?

It means that worker cannot do that task, so there is no edge between them in the bipartite graph and any allocation using that pairing is not allowed.

How do you find the optimum allocation by inspection?

List every possible allocation, add up the entries for each one, then choose the smallest total for costs or the largest total for profits.

What if two allocations give the same best total?

Then both are optimal and either one can be used. State both if the question asks for every optimum allocation.