Coconote
AI notes
AI voice & video notes
Try for free
🌳
Kruskal's Algorithm Lecture Notes
Jul 7, 2024
Kruskal's Algorithm
Introduction
Purpose
: To find the minimum cost spanning tree (MCST).
Usage
: Utilized in competitive exams, college, and university exams.
Alternatives
: Prim's Algorithm.
Spanning Tree Basics
Spanning Tree Properties
:
The number of vertices is the same as the original graph.
Number of edges = N - 1 (vertices - 1).
No cycles (loops) and must be connected.
Steps in Kruskal's Algorithm
List edges by increasing weight
: Arrange edges in ascending order of their weights.
Include minimum weight edges
: Start including edges from the smallest weight without forming a cycle.
Check for cycles
: Make sure that addition of a new edge does not form a cycle.
Repeat until N - 1 edges are included
: Continue adding edges until the graph has N - 1 edges.
Example Walkthrough
Initial Setup
: Graph with vertices 1-7, arrange edges by weights.
Edge Selection
: Add edges one by one (e.g., B-E, A-C, E-F, B-C, E-G), avoid cycles such as F-G.
Result
: Sum of edge weights for MCST is 21.
Comparison to Prim's Algorithm
Connection
: Kruskal’s algorithm can have disconnected intermediate steps, Prim's always remains connected.
Result
: Both algorithms yield the same MCST but operate differently.
Time Complexity
MinHeap Construction
: For E edges, use MinHeap requiring O(E) or E log E time.
Edge Extraction & Union-Find
:
Extract MinEdge and add to the spanning tree. Ensure no cycle formation.
Best Case
: O((N-1) log E) where N is vertices.
Worst Case
: O(E log E) for considering all edges.
Key Points to Remember
Avoid cycles while adding edges even if they have minimum weight.
Properly handle disconnections in intermediate stages in Kruskal’s method.
Be cautious with graphs designed to create confusion.
Complexity Analysis
Construction
: Using heapify - O(E), without heapify - E log E.
Insertion
: Each insertion - log E,
Best Case
: N-1 insertions.
Worst Case
: E insertions (All edges might need to be checked).
Conclusion
Relevance
: Widely asked in exams.
Difficulty
: Easy to understand but care needed in avoiding cycles and managing heap operations.
Thank You
📄
Full transcript