Minimum Spanning Trees
Slides: https://github.com/neu-pdi/cs2100-public-resources/blob/main/docs/slides/26sp/l30-mst/l30-mst.pdf
Minimum Spanning Trees
Poll: A tree is a type of graph. What are the differences between a tree and a graph?
- Each node in a tree must have exactly one parent (unless it is the root)
- Each node in a tree must have at least one child
- Trees are required to have at least one cycle
- Trees are not allowed to have cycles
- Edges in a tree must be weighted
- Edges in a tree cannot be weighted
(See slides)
Kruskals algorithm
(See slides)
Poll: How can we get the edge with the smallest weight at each step?
- Store the edges in a Priority Queue, and remove the front item one by one
- Store the edges in a regular list, and search for and remove the smallest item one by one
- Store the edges in a Binary Search Tree (SortedSet) and remove the leftmost node one by one
- Store the edges in a Hash Table and remove the leftmost node one by on
Poll: How can we tell if an edge (between node1 and node2) would cause a cycle?
- Union-find: If the find operation returns the same root for both node1 and node2, then that edge would cause a cycle
- Union-find: If the find operation for node1 returns node2, or vice versa, then that edge would cause a cycle
- Recursive backtracking: starting at node1, search for all nodes that can be reached. If node2 is in that set, then that edge would cause a cycle
(See slides)
Poll: Which of the following are true?
- To iterate through the edges, smallest to largest, we can store them in a Priority Queue
- To determine whether adding an edge would cause a cycle, we can use union-find to see if they are already in the same tree
- We complete Kruskal's Algorithm when each node has at least one edge connected to it in the tree
- The weighted graph edges chosen for the MST are different from the directed parent edges used for union-fin -->