Minimum Spanning Tree Flashcards

1
Q

What DS does Prim’s algorithm work?

A

Priority Queue to store the edges and Array to track if a vertex has been visited.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does Prim’s algorithm work?

A
  1. Start from a vertex and mark it as visited
  2. Queue all of its edges into PQ that’s sorted by edge weight
  3. Dequeue the edge that has the minimum weight
  4. If the vertex has already been visited, skip and poll the next edge
  5. Else, add that vertex to the tree
  6. Queue all of that vertex’s edges into PQ
  7. Repeat until all vertices have been added
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Time Complexity of Prim’s

A

O(ElogV)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What DS does Kruskal’s algorithm use?

A

UFDS and Edge List

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does Kruskal’s algorithm work?

A

Keep picking the edge of lowest weight to be part of the MST, with the condition that the edge must be connecting our current tree to a previously connected vertex, until all vertices are connected to the tree.

  1. Sort the set of edges by increasing weight
  2. While there are unprocessed edges left, pick an unprocessed edge e with min cost
  3. If adding e to T does not form a cycle, add e to T
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Time Complexity of Kruskal’s

A

O(ElogV)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to find the minimax path from a to b?

A

Find the MST and find the path between a and b. This is the minimax path between a and b.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Properties of a graph where you’d find MST

A

Connected, undirected, weighted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly