ALGORITHMS/Student Engineering Notebook
Page 06·notes
GREEDY STRATEGIES & DYNAMIC PROGRAMMING—~34 MIN READ

Minimum Spanning Trees: Kruskal, Prim & Cut Properties

“Cut Property, Cycle Property, Kruskal with DSU, Prim with priority queues, and uniqueness theorems.”

1.Spanning Tree Axioms & Fundamental Cut/Cycle Theorems

For a connected, undirected weighted graph G = (V, E, w):

A Spanning Tree is an acyclic subgraph connecting all |V| vertices, having exactly |V| - 1 edges. An MST minimizes w(T) = sum_{e in T} w(e).

Theorem 1 (The Cut Property):

Let (S, V setminus S) be any cut of G. If edge e = (u, v) is the strictly minimum-weight edge crossing the cut (u in S, v in V setminus S), then e belongs to every MST of G.

Proof: Suppose an MST T does not contain e. Adding e to T creates a cycle C. This cycle must cross the cut at least once more via another edge e'. Since w(e) < w(e'), replacing e' with e creates a new spanning tree T' = T cup {e} setminus {e'} with w(T') < w(T), contradicting the optimality of T.

Theorem 2 (The Cycle Property):

Let C be any cycle in G. If edge e is the strictly heaviest edge on C, then e cannot belong to any MST of G.

2.Kruskal vs Prim: Algorithmic Mechanics & Complexities

Kruskal's Algorithm (Edge-Centric):

1. Sort all edges in non-decreasing order of weight.

2. Maintain a Disjoint Set Union (DSU) of vertices.

3. For each edge (u, v): if Find(u) != Find(v), union the sets and add (u, v) to the MST.

Union-by-rank with path compression achieves O(alpha(V)) amortized time per operation. Total time: O(E log E) = O(E log V).

Prim's Algorithm (Vertex-Centric):

1. Start with an arbitrary root vertex s. Set key[s] = 0, key[v] = inf for all v != s.

2. Extract min vertex u from priority queue.

3. For each adjacent edge (u, v): if v is in the queue and w(u, v) < key[v], update key[v] = w(u, v) and parent[v] = u (Decrease-Key).

Complexity with Binary Min-Heap: O(V log V + E log V) = O(E log V).

WORKED EXAM ANALYSIS · STEP-BY-STEP DERIVATION

3. Worked Problem: Minimum Weight Spanning Tree Edge Inclusion

⚠️ Pitfall Warning:

Always verify whether the cut property isolates a subset. If multiple edges share the minimum weight across a cut, any of them may appear in some MST, but not necessarily all.

Problem: Graph G has 5 vertices {A, B, C, D, E} and edges with weights: (A, B)=1, (B, C)=2, (C, D)=3, (D, E)=4, (E, A)=5, (A, C)=2, (B, D)=3, (C, E)=4. Find the total weight of the MST and check whether it is unique.

Step 1: Sort edges in non-decreasing order:

(A, B): 1

(A, C): 2, (B, C): 2

(C, D): 3, (B, D): 3

(D, E): 4, (C, E): 4

(E, A): 5

Step 2: Execute Kruskal's algorithm:

- Add (A, B) wt 1. Components: {A, B}, {C}, {D}, {E}. MST wt = 1.

- Consider wt 2: (A, C) connects {A, B} and {C}. Add (A, C) wt 2. Components: {A, B, C}, {D}, {E}. MST wt = 3.

- Consider (B, C) wt 2: Both B and C are already in {A, B, C}. Forms cycle (A-B-C-A). Discard.

- Consider wt 3: (C, D) connects {A, B, C} and {D}. Add (C, D) wt 3. Components: {A, B, C, D}, {E}. MST wt = 6.

- Consider (B, D) wt 3: Both B and D are in {A, B, C, D}. Forms cycle. Discard.

- Consider wt 4: (D, E) connects {A, B, C, D} and {E}. Add (D, E) wt 4. Components: {A, B, C, D, E}. MST wt = 10.

Step 3: Verification:

Edges selected: (A, B)=1, (A, C)=2, (C, D)=3, (D, E)=4.

Total MST weight = 1 + 2 + 3 + 4 = 10.

Alternative tie: if at wt 2 we picked (B, C)=2 instead of (A, C)=2, we get edges (A, B)=1, (B, C)=2, (C, D)=3, (D, E)=4 with total weight 10. Hence MST is NOT unique, but the minimum weight 10 is unique.

WORKED NUMERICAL · STUDENT DERIVATION✎ Key Takeaway: Kruskal needs a union-find structure to test cycles; with it the algorithm runs in O(E log E).

Worked example: Kruskal's algorithm

Problem Statement:
Find the minimum spanning tree weight of the graph with edges AB = 1, BC = 2, AC = 3, CD = 4, BD = 5, DE = 6, CE = 7.
Step 1: Sort the edges

1 (AB), 2 (BC), 3 (AC), 4 (CD), 5 (BD), 6 (DE), 7 (CE).

Step 2: Take AB = 1 and BC = 2

Neither makes a cycle.

↳ Result: Components: {A, B, C}, {D}, {E}
Step 3: Reject AC = 3

A and C are already connected, so AC would close a cycle.

Step 4: Take CD = 4, reject BD = 5

CD joins D; BD would then close a cycle.

↳ Result: {A, B, C, D}, {E}
Step 5: Take DE = 6

That's 4 edges for 5 vertices: the tree is complete.

1 + 2 + 4 + 6
Final Answer:MST weight = 13
STUDENT PRACTICE · CONCEPT DRILL

Practice: test yourself

Original practice questions in the GATE style, with worked explanations. Not past-paper questions.

Problem 1 · FOUNDATION

If every edge weight in a connected graph is distinct, the minimum spanning tree is:

Problem 2 · GATE-LEVEL

The unique heaviest edge of some cycle in a graph:

Problem 3 · FOUNDATION

A connected graph has 12 vertices and 30 edges. How many edges does its minimum spanning tree have?

SOURCE TRANSPARENCY & CITATIONS

Primary Academic References & Exam Sources

Every concept in Notes From a B.Tech Brain is synthesized from authoritative academic texts, seminal peer-reviewed research, verified exam archives, and renowned university lectures.

Curated University Lecture Series
Introduction to Algorithms (4th Edition) ·
LECTURE SERIES
RECOMMENDED YOUTUBE EDUCATORS & FULL-COURSE PLAYLISTS

Curated for clarity, rigorous numerical solving, and semester excellence:

Abdul Bari · Algorithms↗Instructor: Abdul Bari · Covers: Sorting, graph algorithms, dynamic programming, greedy, backtracking

Best visual explanations of algorithm design and complexity analysis.

Open YouTube↗
Gate Smashers · Algorithms for GATE↗Instructor: Varun Singla · Covers: Asymptotic analysis, Master Theorem, DP, Dijkstra, Bellman-Ford

Exam-focused with GATE PYQ numericals on every major algorithm.

Open YouTube↗