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

  1. Pick any vertex to be the root of the tree
  2. 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
  3. 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. Draw a counter-example for prim’s showing why it doesn’t work on a directed graph
  2. 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
  1. Ans: Exam 1 revision on iPad
  2. Ans: Exam 1 revision on iPad
How well did you know this?
1
Not at all
2
3
4
5
Perfectly