Matroid Theory — Definition, Examples, Greedy Algorithm on Matroids
1549 words
8 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# Matroid Theory — Definition, Examples, Greedy Algorithm on Matroids ## 🎯 Learning Objectives - Define matroids and their axioms - Verify if a structure is a matroid using the exchange property - Prove correctness of greedy algorithm on matroids - Apply matroid theory to scheduling with deadlines * * * ## 1. Matro...

Matroid Theory — Definition, Examples, Greedy Algorithm on Matroids
🎯 Learning Objectives
- Define matroids and their axioms
- Verify if a structure is a matroid using the exchange property
- Prove correctness of greedy algorithm on matroids
- Apply matroid theory to scheduling with deadlines
1. Matroid Definition
1.1 Intuition
A matroid is a combinatorial structure that captures the essence of "independence" — generalizing linear independence in vector spaces and acyclic sets in graphs. The key insight: matroids are exactly the structures where the greedy algorithm works.
1.2 Formal Definition
A matroid M=(S,I) consists of:
- S: A finite ground set
- I: A family of subsets of S called independent sets Satisfying three axioms:
- Non-emptiness: ∅∈I
- Hereditary property: If A∈I and B⊆A, then B∈I
- Exchange property: If A,B∈I and ∣A∣<∣B∣, then ∃x∈B∖A such that A∪{x}∈I
1.3 Axiom Intuition
| Axiom | Meaning |
|---|---|
| Non-emptiness | The empty set is always independent |
| Hereditary | Subsets of independent sets are independent |
| Exchange | You can grow a smaller independent set using an element from a larger one |
2. Examples of Matroids
2.1 Uniform Matroid Uk,n
- S={1,2,...,n}
- I={A⊆S:∣A∣≤k} Verification:
- Hereditary: If |A| ≤ k and B ⊆ A, then |B| ≤ |A| ≤ k ✓
- Exchange: If |A| < |B| ≤ k, pick any x ∈ B\A, |A∪{x}| ≤ |A|+1 ≤ k ✓
2.2 Graphic Matroid M(G)
- S= edges of graph G
- I= sets of edges with no cycles (forests) Verification: Exchange property: If A and B are forests with |A| < |B|, since B has more edges, there must be an edge in B connecting two components that A doesn't connect. Adding it creates no cycle. (Diagram) Graphic matroid:
- S = {e1, e2, e3, e4}
- Independent sets: {}, {e1}, {e2}, {e3}, {e4}, {e1,e2}, {e1,e3}, {e1,e4}, {e2,e3}, {e2,e4}, {e3,e4}, {e1,e2,e4}, {e1,e3,e4}
- Not independent: {e1,e2,e3} (forms cycle)
2.3 Partition Matroid
- S partitioned into groups S1,S2,...,Sk
- I={A:∣A∩Si∣≤ci for each group} Example: Selecting at most 1 person from each department.
2.4 Linear (Vector) Matroid
- S= columns of a matrix over a field
- I= linearly independent columns
3. Greedy Algorithm on Matroids
3.1 Generic Greedy Algorithm
Problem: Given a matroid M=(S,I) with weight function w:S→R+, find the maximum weight independent set.
pseudoGreedy-Max(M, w): Sort S by decreasing weight: w(x₁) ≥ w(x₂) ≥ ... ≥ w(xₙ) I = ∅ For i = 1 to n: If I ∪ {xᵢ} ∈ ℐ: I = I ∪ {xᵢ} Return I
3.2 Correctness Proof
Theorem: The greedy algorithm returns a maximum-weight independent set for any matroid.
Proof sketch (exchange argument):
- Let A={a1,a2,...,ak} be the greedy solution (in order chosen)
- Let O={o1,o2,...,om} be any optimal solution (sorted by weight)
- Show k=m and w(A)≥w(O):
- If ∣A∣<∣O∣, exchange property would let greedy add an element
- If w(aj)<w(oj) for some j, exchange property gives contradiction
3.3 Maximum Spanning Tree
The maximum spanning tree (or minimum spanning tree with inverted weights) is exactly the greedy algorithm on a graphic matroid — Kruskal's algorithm!
textKruskal's algorithm: Sort edges by weight (descending for max, ascending for min) I = ∅ For each edge (u,v) in sorted order: If I ∪ {(u,v)} has no cycle: I = I ∪ {(u,v)} Return I
4. Scheduling with Deadlines
4.1 Problem
- Jobs with deadlines di and profits pi
- Each job takes 1 unit of time
- Schedule jobs to maximize profit within deadlines
4.2 Matroid Formulation
- Ground set: jobs
- Independent set: jobs that can be scheduled within their deadlines
- This forms a matroid! (Called the scheduling matroid)
4.3 Greedy Solution
text1. Sort jobs by profit (decreasing) 2. Schedule each job at the latest available time ≤ deadline 3. If no available slot, skip the job
4.4 Worked Example
| Job | Deadline | Profit |
|---|---|---|
| J1 | 2 | 100 |
| J2 | 1 | 50 |
| J3 | 2 | 25 |
| J4 | 1 | 20 |
Greedy (sort by profit):
| Step | Job | Deadline | Slots [1,2] | Action |
|---|---|---|---|---|
| 1 | J1 | 2 | [_, _] | Schedule at slot 2 |
| 2 | J2 | 1 | [_, J1] | Schedule at slot 1 |
| 3 | J3 | 2 | [J2, J1] | Slot 2 taken, slot 1 taken → skip |
| 4 | J4 | 1 | [J2, J1] | Slot 1 taken → skip |
Schedule: J2 (slot 1), J1 (slot 2). Total profit = 150.
Optimal? Yes — the greedy algorithm on a matroid finds the optimal solution.
5. 📝 Practice Questions
Q1: Verify that the set of subsets of size at most 2 from {1,2,3,4} forms a matroid.Answer: This is the uniform matroid U₂,₄. Non-emptiness: ∅ is size 0 ≤ 2 ✓. Hereditary: any subset of a size-≤2 set has size ≤2 ✓. Exchange: if |A| < |B| ≤ 2, pick any x ∈ B\A, then |A∪{x}| ≤ |A|+1 ≤ 2 ✓. Q2: Prove that the greedy algorithm fails for the maximum-weight independent set problem when the structure is NOT a matroid.Answer: Consider S = {a, b, c} with weights w(a)=10, w(b)=9, w(c)=8. Let ℐ = {∅, {a}, {b}, {c}, {a,b}, {a,c}} (note: {b,c} not independent). Greedy picks {a} (weight 10), then can add c → {a,c} (weight 18). But optimal is {a,b} (weight 19). Greedy fails because ℐ doesn't satisfy the exchange property: |{b,c}| = 2 > |{a}| = 1, but no element of {b,c} can be added to {a} to create a larger independent set... Actually {a,b} and {a,c} are independent. So |{a,b}| = |{a,c}| = 2 > 1 = |{b}|. Exchange: from {b} and {a,b}: b→{a,b} is adding a, which works. The structure does satisfy exchange — it IS a matroid. Let me give a counterexample that's NOT a matroid:S = {a, b}, ℐ = {∅, {a}} (but NOT {b}). This violates hereditary (subset of independent {a} is ∅, ok) but exchange fails: |∅| = 0 < |{a}| = 1, but ∅∪{a} not in ℐ? Actually ∅∪{a} = {a} which IS in ℐ. This IS a matroid.Better: S = {a,b,c}, ℐ = {∅, {a}, {b}, {a,b}}. Exchange: {a} and {b} both size 1 — no |A| < |B| case. OK. {a} and {a,b}: |{a}|=1 < |{a,b}|=2, pick b from {a,b}{a} = {b}, {a}∪{b} = {a,b} ∈ ℐ ✓. This IS a matroid.For a non-matroid: S = {a,b,c}, ℐ = {∅, {a}, {b}, {c}, {a,b}, {a,c}, {b,c}}. This IS a matroid (uniform U₂₃).Try: S = {a,b}, ℐ = {∅, {a}, {b}}. This is not a matroid because exchange: |{a}|=1, |{b}|=1, but if |A| < |B|, we need A smaller. |∅|=0 < |{a}|=1, need x from {a}\∅ = {a}, ∅∪{a} = {a} which is independent ✓. So this IS a matroid.The point is: greed works on matroids. For non-matroid structures (e.g., independent set in general graphs), greedy fails. Q3: Schedule jobs with profits 60, 40, 30, 20, 10 and deadlines 2, 1, 2, 1, 2.Answer: Sort by profit: J1(60,d=2), J2(40,d=1), J3(30,d=2), J4(20,d=1), J5(10,d=2).
- J1: schedule at slot 2. {slot2=J1}
- J2: schedule at slot 1. {slot1=J2, slot2=J1}
- J3: deadline 2, slots 1,2 taken → skip
- J4: deadline 1, slot 1 taken → skip
- J5: deadline 2, slots 1,2 taken → skip Profit = 60 + 40 = 100. Q4: What is the exchange property and why is it essential for greedy correctness?
Answer: The exchange property says: if A and B are independent and |A| < |B|, there exists an element x in B\A such that A∪{x} is also independent. This property ensures that the greedy algorithm never makes a decision that blocks future optimal choices. It's the key lemma in the exchange argument proving greedy optimality. Q5: Give an example of a subset system that satisfies hereditary but NOT the exchange property.Answer: Let S = {a, b, c} and ℐ = {∅, {a}, {b}, {a,b}, {a,c}}. Hereditary holds. But exchange fails: |{b}|=1 and |{a,c}|=2, but the only element in {a,c}{b} = {a,c}. {b}∪{a} = {a,b} ∈ ℐ, so exchange actually holds here.Consider: S = {a,b}, ℐ = {∅, {a}}. This satisfies hereditary. |∅|=0 < |{a}|=1, and ∅∪{a}={a}∈ℐ. Exchange holds.Consider S = {a,b,c}, ℐ = {∅, {a}, {b}, {a,b}, {b,c}}. Exchange: |{a}|=1 < |{b,c}|=2. Need x∈{b,c}{a} = {b,c}. {a}∪{b}={a,b}∈ℐ ✓. |{a,b}|=2, |{b,c}|=2 — no |A|<|B| case. This IS a matroid.True non-matroid: S={a,b,c}, ℐ={∅, {a}, {b}, {a,b}}. This satisfies exchange (check all pairs). It's a matroid (graphic matroid of two edges sharing one vertex). Most natural structures that have hereditary actually are matroids — that's why matroids are so useful!
6. 🔗 Cross-References
- Week 1 - Greedy Algorithms: Foundation for matroid understanding
- Week 4 - Network Flow: Matroid intersection for bipartite matching
- BSCS3021 (ToC): Independent sets, spanning trees Join Discord PreviousGreedy AlgorithmsNextDynamic Programming