Kruskal’s Greedy Algorithm

Context: FIT1058_MOC · finds a minimum-cost spanning tree · adds cheapest cycle-free edge each step · a rare case where greedy is optimal

Quick Revision

  • 🎯 Objective: build a minimum-cost spanning tree ➔ add cheapest cycle-free edge each step.
  • 📦 Core Components: greedy choice ➔ acyclic (Forest) invariant ➔ stop at edges.
  • ⚡ Key Constraint: greedy is provably optimal here — a rare exception (matroid theory).

📝 Core

1. The Algorithm

  • Input ➔ connected weighted graph, costs .
  • Rule ➔ repeatedly add the cheapest edge creating no cycle; stop when none remain.
  • Output ➔ minimum-cost Spanning Tree minimising .

2. Why a Spanning Tree

  • No redundant edge ➔ if still connects, drop to save .
  • Optimum ➔ a minimal connected vertex-spanning subgraph = a spanning tree, of least cost.

3. Greedy Optimality

  • Theorem ➔ Kruskal always finds a minimum-cost spanning tree.
  • Surprising ➔ greedy usually fails (e.g. shortest paths); matroid theory explains the exceptions.

Key identities:

When It Flips: the partial is always a forest; the cheapest-edge rule among cycle-free options attains the global minimum. Recognising the structures where greedy provably works (matroids) is the deeper lesson.

📊 Exam Execution Trace

Manual Execution Trace

Costs :

Step / StateEdge ()Cycle?Add?
0 (Init)0
1 (1)no1
2 (2)no3
3 (2)no5
4(3),(4)yes

⚠️ Common Mistakes

  • 💡 Greedy ≠ optimal in general ➔ Kruskal is a celebrated exception; for most problems “maximise short-term gain” misses the global optimum.

🧠 Active Recall

极速同步

  • 核心干货:按权重从小到大排序所有边,只要不形成环就无脑加边,直到加满 条。
  • 关键底层:并查集(Union-Find)判环。
  • 复杂度 (瓶颈在排序)。