A matroid is exactly the structure on which the sorted greedy is always optimal. Recognising one is a proof of the greedy for free, and matroid intersection solves a class of problems greedy can’t.

Definition

with:

  1. ;
  2. hereditary: subsets of independent sets are independent;
  3. exchange: if and , some has .

Maximal independent sets (bases) all have the same size, the rank. A minimal dependent set is a circuit.

Rado-Edmonds: for a hereditary family, “sort by weight descending and add if still independent” finds a maximum-weight independent set for every weight function iff the family is a matroid. For a maximum-weight basis with negative weights allowed, keep adding even negative elements; for a maximum-weight independent set, stop at the first negative.

Common matroids

MatroidIndependent setsOracle
uniform sets of size count
partitionat most from each groupcounters
graphicforestsDSU
cographic (bond)edge sets whose removal keeps the graph connectedbridges / DSU on the complement
linearlinearly independent vectors (over any field)Gaussian elimination; XOR basis over
transversalsubsets of the left side matchable into the right sidebipartite matching
scheduling (unit jobs)job sets that can all meet their deadlinessort by deadline, check the -th job has deadline
gammoidsets linked by vertex-disjoint paths to a fixed setmax flow

Consequences:

  • graphic + DSU is Kruskal;
  • linear over : “choose numbers with linearly independent XORs maximising total weight”: sort by weight, insert into an XOR basis, keep the ones that insert (XOR Basis);
  • scheduling: unit jobs with deadlines and profits, sorted by profit, kept if still feasible (check with a DSU “latest free slot”).

Not matroids: knapsack (weights), matchings in a general graph as edge sets, independent sets of vertices in a graph, paths. If greedy fails on a small example, the structure isn’t a matroid.

Strong basis exchange / bottleneck facts. In a matroid with weights, the greedy basis is simultaneously min-sum and min-max (bottleneck). For MSTs this is “the MST minimises the maximum edge”.

Operations

  • Restriction / deletion / contraction keep matroids. Contracting an element in a graphic matroid contracts the edge.
  • Dual : bases are complements of bases. The dual of graphic is cographic. .
  • Truncation (keep only sets of size ) and union (sets splittable into one independent set of each) are matroids. The union has rank (Nash-Williams). That gives: edge-disjoint spanning trees exist iff for every partition of the vertices, the number of edges between parts is (Nash-Williams-Tutte).

Matroid intersection

Find a maximum common independent set of two matroids on the same ground set. Greedy fails, but augmenting paths in an exchange graph solve it in oracle calls for the unweighted version, and the weighted version uses shortest augmenting paths with potentials.

Problems that are matroid intersections:

  • bipartite matching (two partition matroids), which is why it isn’t a matroid itself;
  • rainbow / colourful spanning tree: graphic ∩ partition by colour;
  • spanning tree with at most edges of each type;
  • arborescences with degree constraints (graphic ∩ partition by head);
  • “pick a basis of vectors, at most one from each group”: linear ∩ partition.

Min-max formula: .

Algorithm details and code: Matroid Intersection. Intersection of three matroids is NP-hard (it includes Hamiltonian path), so problems needing three constraints aren’t solved this way.

Recognising a matroid

Ask: “If can’t be added now, can adding more elements ever make it addable?” Then try the exchange axiom on small examples by brute force. If both hold, the greedy is optimal. A quick check is to run the greedy against a brute force on random small instances: a matroid passes every time.