Lecture 12: Prim's MST algorithm Flashcards
1
Q
Prim’s MST algorithm and underlying assumptions
Does it work on both directed and undirected graphs?
A
Prim’s algorithm is a greedy algorithm
- Pick any vertex to be the root of the tree
- While the tree does not contain all vertices
- find the lightest neighbor edge from either vertex in our current MST
- Add it to the MST - You have constructed the MST
O(V^2) currently
Assumptions
- graph is connected: if not connected, we adapt the algo to compute MSTs for connected components (minimum spanning forest)
- Edges are unique: guarantees unique MSTS, otherwise not
Prim’s algorithm assumes that all vertices are connected. But in a directed graph, every node is not reachable from every other node. So, Prim’s algorithm fails due to this reason
2
Q
- Draw a counter-example for prim’s showing why it doesn’t work on a directed graph
- Disapprove: since prim’s algo always chooses the minimum edge btn vertices, it also finds the shortest path btn any two vertices in the graph
Basically why prim’s doesn’t work when finding the shortest path
A
- Ans: Exam 1 revision on iPad
- Ans: Exam 1 revision on iPad