- Asked 3/14
- 2068 Magh · 2 marks
Write Kruskal's algorithm
Short answer
Kruskal's algorithm: initialize each vertex as a separate set, sort edges by weight, and for each edge in order, if its endpoints are in different sets, add it to the MST and union the sets. Time O(E log E).
Write Kruskal's algorithm for minimum spanning tree.
KRUSKAL(G) // G = (V, E) connected, weighted, undirected
1. T = empty
2. for each vertex v: MAKE-SET(v)
3. sort E in non-decreasing order of weight
4. for each edge (u, v) in sorted order
5. if FIND-SET(u) != FIND-SET(v) // no cycle is formed
6. T = T + {(u, v)}
7. UNION(u, v)
8. return T // MST with V-1 edges
Time complexity: O(E log E), dominated by sorting.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Kruskal's algorithm with example · Data Structure and Algorithm, chapter 10 · asked 3×
- Spanning tree properties; Round Robin MST · Data Structure and Algorithm, chapter 10
- Kruskal's MST on 7-vertex graph · Data Structure and Algorithm, chapter 10 · asked 3×
- Kruskal's MST on graph A to G · Data Structure and Algorithm, chapter 10 · asked 3×
- Kruskal's MST on 9-vertex graph · Data Structure and Algorithm, chapter 10 · asked 3×
- MST definition; Kruskal's MST on 6-vertex graph · Data Structure and Algorithm, chapter 10
- TOH algorithm and recursion tree · Data Structure and Algorithm, chapter 5 · asked 2×
- Short note: Spanning tree and applications · Discrete Structure, chapter 4
- Short note: Spanning tree · Discrete Structure, chapter 4 · asked 3×
- Decision tree classifier and Hunt's algorithm · Data Mining, chapter 3