Definition
Matroid Intersection Algorithm
Given two finite matroids and on the same ground set, the matroid intersection algorithm finds a largest set independent in both:
Starting with , it repeatedly finds a shortest augmenting path in a directed exchange graph and exchanges the elements along that path. Each augmentation preserves common independence and increases by one. If no augmenting path exists, has maximum cardinality.
The intersection need not itself be a matroid. This algorithm uses independence tests in and separately.
Build the exchange graph
Fix the current common independent set . The directed bipartite graph has vertex classes and : selected elements on one side, unselected elements on the other.
Arcs represent permitted single exchanges
For each and , test the set obtained by removing and adding :
The diagram shows a pair for which both tests succeed. In general, either arc, both arcs, or neither arc may be present. An arc records an exchange test; its direction does not mean that its starting vertex is always removed.
Mark possible entry and exit elements
Among the unselected elements, mark those that can already be added without removing anything:
An augmenting path starts in and ends in . Both endpoints lie outside ; the sets and may overlap.
Find a shortest augmenting path
Run a multi-source breadth-first search in , starting from every vertex in . Stop when a vertex in is reached. Shortest means the fewest arcs, over all choices of starting and ending vertices.
A path alternates between unselected and selected elements
If a path exists, take a shortest one:
Shown for : only the path vertices and path arcs are drawn, not the whole graph . Each arc colour identifies the matroid whose exchange test succeeded.
A shortest path has no internal unselected vertex in or : such a vertex would allow a later start or an earlier finish. Thus
Exchange along the path
Toggle membership simultaneously
Remove the selected path vertices and add the unselected path vertices:
Here means selected and means unselected. The elements illustrate elements of outside the path; all elements outside retain their membership.
In general, the path removes elements and adds :
For a shortest augmenting path, . This guarantee concerns the simultaneous update, not a sequence of individually feasible intermediate sets. The correctness proof is omitted here.
Direct addition
If , the shortest path consists of the single vertex and has zero arcs. Then and : no removal is needed.
Stop or repeat
If breadth-first search reaches no vertex of , there is no augmenting path and the current set has maximum cardinality. Otherwise replace by and rebuild the graph and endpoint sets for the new .
MatroidIntersection(M₁, M₂):
S := ∅
loop:
Build H(S), E₁, E₂ using independence tests
P := a shortest directed path from E₁ to E₂
(multi-source BFS; allow a zero-arc path)
if no such P exists:
return S
S := (S \ V(P)) ∪ (V(P) \ S)Here is the set of path vertices, and the update uses the old value of on both sides. Each successful iteration increases by one, so there are at most augmentations.
Independence tests and running time
With and , one iteration uses at most
independence tests. The graph has vertices and at most arcs, so breadth-first search takes time. Rebuilding everything each iteration gives independence tests overall, or time if each independence test costs at most .