Minimum Spanning Tree Flashcards

1
Q

Define a spanning tree

A

A spanning tree is an acyclic subset of edges that connects all nodes in a graph.

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

Define a minimum spanning tree

A

A spanning tree with the minimum weight.

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

Proof that a minimum spanning tree is acyclic.

A

If an MST is cyclic, that means there is an edge which we can remove to make the MST lighter. Thus, this proves the contradiction that the original cyclic spanning tree is an MST.

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

Is MST and shortest path the same? Explain.

A

MST and shortest path are not the same. An MST gives you a tree which traverse through all the nodes with the least weight. Shortest path does not need to traverse through all the nodes, it just gives the shortest path between two given nodes in the graph.

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

Basic properties of an MST.

A
  1. No cycles
  2. Cutting an MST produces two separate MSTs
  3. Cycle property: for every cycle, the maximum weight edge is NOT in the MST.
  4. Cut property: for every partition of the nodes, the minimum weight edge across the cut IS in the MST.
  5. For every vertex, the minimum outgoing edge is in the MST.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain the generic MST algorithm.

A

Red rule: if C is a cycle with no red arcs, color the max weight edge in C red.
Blue rule: if D is a cut with no blue arcs, color the min weight edge in D blue.
On termination, all edges will be colored either red or blue. All the blue edges will be our MST (otherwise there is a cut with no blue edge) and all cycles will have a red edge (there can not be a blue cycle).

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

Explain Prim’s algorithm.

A
  1. Start with a root node. Call this node R.
  2. Look at all the edges going out from this node, take the minimum one. Store the rest in a priority queue. These edges are the edges that crosses the cut which separates our R from the rest of the graph.
  3. The minimum edge connects R to another node, call this A. Now recurse the whole process in step 2 where the edges now are the edges that crosses the cut which separates our R and A from the rest of the graph.
  4. Recurse until we have covered all nodes. The edges we obtain forms our desired MST.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why is Prim’s algorithm called the “blue” algorithm?

A

It’s because the basic idea stems from the blue rule, in which all the edges added during the recursion are each the lightest edge on some cut in the graph.

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

Explain Kruskal’s algorithm.

A
  1. Sort all the edges by their weight.
  2. From lightest to heaviest, check each edge and see if it connects two nodes which are a part of the same connected component (blue tree). If yes, color this edge red. If no, color this edge blue.
    We also use Union-Find to find the nodes and check if they are in the same connected component and to merge two connected components.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Analyse the running time of Prim’s algorithm.

A

Constructing the priority queue takes O(VlogV) for V nodes. We will perform the decreaseKey at most E times which takes O(ElogV). Total: O(VlogV) + O(ElogV) and since E = O(V^2), the total is O(ElogV).

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

Analyse the running time of Kruskal’s algorithm.

A

Sorting all the edges by their weight will take O(ElogE) time. For each edge, using Union-Find will take O(α(V)).
Total: O(ElogE) + O(Eα(V)) and since E = O(V^2) and O(Eα(V)) is basically O(E), we can also rewrite this as O(ElogV).

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

Explain Boruvka’s algorithm.

A

One Boruvka’s step does:

  1. For each connected component. search for the minimum weight outgoing edge. This can be done using BFS or DFS which takes O(V + E).
  2. Add these selected edges.
  3. Merge the components which are connected by these edges.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Analyse the running time of Boruvka’s algorithm.

A

At most we have to perform logV Boruvka steps. This only happens when each merge only connected component to another. Thus, the worst case runtime is O((V+E)logV) = O(ElogV). But most of the time it will run much faster than this.

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

What if all the edges have the same weights?

A

We can just perform a DFS or BFS to find the shortest path which will also be our MST.

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

If the edges are all of cost X, what is the cost of the MST?

A

(V-1)X

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

What if all the edges have weights ranging from {1…10}?Solve using Kruskal’s algorithm.

A
  1. Use an array of size 10 where each slot holds a linked list.
  2. Put the edges in the corresponding linked list (by weight of the edge).
  3. Iterate over all the edges in ascending order. For each edge, using Union-Find allows us to find and union in O(α(V)).
    Total runtime: O(Eα(V)).
17
Q

What if all the edges have weights ranging from {1…10}? Solve using Prim’s algorithm.

A
  1. Use an array of size 10 where each slot holds a linked list. This acts as our priority queue.
  2. Put the nodes in the corresponding linked list (by priority of the node).
    It takes O(V) to build the array and inserting or deleting from the array. It takes O(E) to decreaseKey.
    Total runtime: O(V + E).
18
Q

How do we find the MST for a directed acyclic graph with one root?

A
  1. Start at a root with no incoming edge to it.
  2. For every node except the root, add the minimum weight incoming edge to that node.
  3. The edges will form our MST.
19
Q

Does adding a constant k to all the weights of the edges matter?

A

Nope! Only relative weights matter.

20
Q

Are negative edge weights allowed in our MST algorithm?

A

Yup! Negative edge weights does not provide any problems.

21
Q

How do we find the Maximum Spanning Tree?

A

We can multiply all the edges’ weights by -1 and perform our MST on the new graph. The MST we obtain in this new graph is the Maximum Spanning Tree of our original graph.

22
Q

Explain the Steiner Tree problem and the problems we face when trying to solve it. Provide the algorithm which gives us a close estimate to the actual MST.

A

The Steiner Tree problem is when we would like to find the MST of only some of the nodes in a given graph. Some problems we face when trying to solve this is:
1. We can try to get the MST of just the required nodes in the graph. However, there may be a lighter MST which involves traversing through some Steiner nodes.
2. We can try to get the MST of all the nodes in the graph. However, there may be a lighter MST which doesn’t involve traversing through all the Steiner nodes.
SteinerMST algorithm:
1. For every pair of required vertices (v, w), calculate the shortest path between them using Dijkstra’s algorithm.
2. Construct a new graph of the required nodes where the edges connecting the required nodes are the shortest paths between them which was obtained in step 1.
3. Run MST on this new graph.
4. Map back the new edges to the original graph.