L17 (MST, Kruksal's Algorithm) Flashcards
What’s the definition of a MST (Minimum Spanning Tree)? How many edges does an MST have in it?
A minimum spanning tree is a tree that spans all vertices in an undirected, connected, and weighted graph, such that the sum of the edge weights is minimized.
An MST has exactly |V| - 1 edges, where |V| is the number of vertices in the graph. There can be multiple MSTs for a given graph, but they will always have the same total weight.
What is the Unique Edge Weights property of an MST?
Unique Edge Weights:
If all edge weights in the graph are distinct (no two edges have the same value), then the MST is unique (there is only one possible MST).
What is Kruksal’s algorithm?
Kruskal’s algorithm is a greedy algorithm for finding the MST of an undirected, connected, and weighted graph. The algorithm sorts the edges by weight and iteratively adds edges to the MST while ensuring that no cycles are formed.
What is the cycle property of an MST?
Cycle Property: The heaviest edge in any cycle of the graph cannot be part of the MST.
What is the cut property of an MST?
Cut Property: Given a cut (partition) of the graph’s vertices into two sepatate non-empty sets, the lightest edge crossing the cut (the two sets) must be part of the MST
Describe Kruksal’s Algorithm step-by-step. Input is a weighted graph G=(V,E,L)
- Sort all edges by their weights in non-decreasing order.
- Initialize an empty set for the MST and a disjoint set data structure for cycle detection.
- For each edge (u, v) in the sorted list, perform the following steps:
a. Check if the edge (u, v) would create a cycle using the disjoint set data structure.
b. If no cycle is formed, add the edge (u, v) to the MST and union the sets containing u and v in the disjoint set data structure. - Continue until the MST contains exactly |V| - 1 edges.
What’s the time complexity of Kruksal’s algorithm?
Kruskal’s Algorithm: O(|E| * log(|E|)) with a binary heap or O(|E| * log(|V|)) with a Fibonacci heap, where |E| is the number of edges and |V| is the number of vertices.
The dominating factor is the sorting of edges, while the disjoint set data structure operations contribute a nearly constant time factor (amortized) per edge.
Kruskal’s algorithm uses the disjoint set data structure (also known as union-find). Describe this data structure.
What does it ensure in terms of time complexity with kruksal’s algorithm?
Union find is used in kruskal’s algorithm to efficiently detect cycles and maintain vertex connectivity.
In addition to “makeset”, this data structure enables two main operations: “find”, which identifies the set containing a specific element, and “union”, which merges two sets containing different elements.
The disjoint set data structure ensures that the cycle detection step in Kruskal’s algorithm runs in nearly constant time (amortized).
What does a vertex’s “rank” mean in union find? what is the maximum rank of a given vertex?
- The “rank” of a vertex is the height of the subtree below that vertex
- The maximum rank of a vertex is O(log V )