Purpose: Find a maximum cardinality matching in a general (non-bipartite) graph in — matching the bipartite bound of Hopcroft-Karp. The fastest known algorithm for general matching (1980).

The framework

Like Hopcroft-Karp, it works in phases, each finding a maximal set of vertex-disjoint shortest augmenting paths:

  1. After phases, every remaining augmenting path has length .
  2. At most such paths can be vertex-disjoint.
  3. So phases suffice in total. Each phase must run in .

For bipartite graphs a simple BFS/DFS achieves the phase. For general graphs, odd cycles (blossoms) break the layering, and handling them in linear time per phase is the entire difficulty.

The hard part: blossoms in linear time

Edmonds’ blossom algorithm contracts an odd cycle whenever it finds one, at cost per contraction — fine for one augmenting path, far too slow for a whole phase.

Micali and Vazirani replace contraction with a delicate bookkeeping of two distances per vertex:

  • evenlevel[v] — length of the shortest even-length alternating path from a free vertex to ;
  • oddlevel[v] — the same for odd length.

A vertex may be reachable at both parities, and the interplay of these two levels is what encodes blossom structure without explicitly contracting anything. Blossoms are detected as bridges — edges whose endpoints’ levels are inconsistent with a simple layering — and are processed by a “double depth-first search” that finds two disjoint paths through the blossom simultaneously.

Complexity

  • Time:
  • Space:
  • Reputation: one of the hardest correct algorithms to implement. The original paper’s proof was incomplete; a full correctness proof took until 1994 (Vazirani), and few correct implementations exist.

Matching algorithms in practice

GraphAlgorithmTime
Bipartite, smallKuhn
BipartiteHopcroft-Karp or Dinic
Bipartite, weightedHungarian
GeneralBlossom or
GeneralMicali-Vazirani
General, weightedBlossom V (Kolmogorov) practical
Existence of perfect matching onlyTutte matrix + random determinant randomized

What to write

For general matching, use a randomised Blossom implementation () — it handles comfortably, which covers essentially every contest problem. If you only need to decide whether a perfect matching exists, the Tutte matrix trick (fill a skew-symmetric matrix with random values and test whether its determinant is nonzero) is 15 lines and .

Variants / Use Cases

  • General Matching — the topic page
  • Blossom algorithm — the implementable general matcher
  • Hopcroft-Karp — the bipartite version of the same phase structure
  • Tutte-Berge formula — the max-matching analogue of König’s theorem for general graphs