Quiz 2

Matroid Theory — Definition, Examples, Greedy Algorithm on Matroids

1549 words
8 min read
Python Week 1: the first filter for runtime behavior
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)M = (S, \mathcal{I}) consists of:
  • S: A finite ground set
  • I\mathcal{I}: A family of subsets of S called independent sets Satisfying three axioms:
  1. Non-emptiness: I\emptyset \in \mathcal{I}
  2. Hereditary property: If AIA \in \mathcal{I} and BAB \subseteq A, then BIB \in \mathcal{I}
  3. Exchange property: If A,BIA, B \in \mathcal{I} and A<B|A| < |B|, then xBA\exists x \in B \setminus A such that A{x}IA \cup \{x\} \in \mathcal{I}

1.3 Axiom Intuition

AxiomMeaning
Non-emptinessThe empty set is always independent
HereditarySubsets of independent sets are independent
ExchangeYou can grow a smaller independent set using an element from a larger one

2. Examples of Matroids

2.1 Uniform Matroid Uk,nU_{k,n}

  • S={1,2,...,n}S = \{1, 2, ..., n\}
  • I={AS:Ak}\mathcal{I} = \{A \subseteq S : |A| \leq 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)M(G)

  • S=S = edges of graph GG
  • I=\mathcal{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

  • SS partitioned into groups S1,S2,...,SkS_1, S_2, ..., S_k
  • I={A:ASici for each group}\mathcal{I} = \{A : |A \cap S_i| \leq c_i \text{ for each group}\} Example: Selecting at most 1 person from each department.

2.4 Linear (Vector) Matroid

  • S=S = columns of a matrix over a field
  • I=\mathcal{I} = linearly independent columns

3. Greedy Algorithm on Matroids

3.1 Generic Greedy Algorithm

Problem: Given a matroid M=(S,I)M = (S, \mathcal{I}) with weight function w:SR+w: S \to \mathbb{R}^+, find the maximum weight independent set.
pseudo
Greedy-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):
  1. Let A={a1,a2,...,ak}A = \{a_1, a_2, ..., a_k\} be the greedy solution (in order chosen)
  2. Let O={o1,o2,...,om}O = \{o_1, o_2, ..., o_m\} be any optimal solution (sorted by weight)
  3. Show k=mk = m and w(A)w(O)w(A) \geq w(O):
    • If A<O|A| < |O|, exchange property would let greedy add an element
    • If w(aj)<w(oj)w(a_j) < w(o_j) 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!
text
Kruskal'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 did_i and profits pip_i
  • 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

text
1. 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

JobDeadlineProfit
J12100
J2150
J3225
J4120
Greedy (sort by profit):
StepJobDeadlineSlots [1,2]Action
1J12[_, _]Schedule at slot 2
2J21[_, J1]Schedule at slot 1
3J32[J2, J1]Slot 2 taken, slot 1 taken → skip
4J41[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

Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.