Let be a graph. A matching is a set of edges, no two of which share an endpoint. A vertex is covered (or saturated) by if it lies on an edge of . is maximum if no matching has more edges and perfect if it covers every vertex, so a perfect matching has edges and requires even.
Given , an augmenting path is a path whose end vertices are both uncovered and whose edges alternate between and ; exchanging the matched and unmatched edges along it gives a matching with one more edge. A matching is maximum if and only if it has no augmenting path (Berge's theorem).
With a weight function , a minimum-weight perfect matching is a perfect matching minimising . Edmonds gave a polynomial-time algorithm for maximum matching in general (not necessarily bipartite) graphs by contracting odd cycles, "blossoms"; its weighted extension solves the minimum-weight perfect matching problem in polynomial time. In surface-code decoding the vertices are syndrome defects (plus boundary vertices), the weights are of error probabilities along shortest paths, and a minimum-weight perfect matching pairs the defects according to a most likely error consistent with the syndrome; see the matching decoder. Matching terminology follows chapter 2 of Diestel.