Graph Theory37 sections · 1633 units
Open in Course

Kuhn's Algorithm - Pseudocode

(Try to match left node)

Here is Kuhn's algorithm for maximum bipartite matching:

match = array of size |R|, all -1
result = 0

function dfs(u, visited):
    for v in adj[u]:
        if visited[v]:
            continue
        visited[v] = true

        if match[v] == -1 or dfs(match[v], visited):
            match[v] = u
            return true

    return false

for u in L:
    visited = array of size |R|, all false
    if dfs(u, visited):
        result = result + 1

return result

The match[v] array tracks which vertex in LL is matched to vertex vv in RR. For each uLu \in L, we try to find an augmenting path using DFS.