``````Minimum Spanning Trees
Applications of Kruskal’s Algorithm, Prim’s Algorithm, and the cut property.
Kevin Lin, with thanks to many others.
1

Kruskal’s Algorithm
In which order does Kruskal’s algorithm select edges in the MST?
2
Algorithms (Robert Sedgewick, Kevin Wayne/Princeton)
Q
9
1
2
8
3
6
5
7
4
Q1: In which order does Kruskal’s algorithm select edges in the MST?

Kruskal’s Algorithm
In which order does Kruskal’s algorithm select edges in the MST?
3
Algorithms (Robert Sedgewick, Kevin Wayne/Princeton)
A
9
1
2
8
3
6
5
7
4

Prim’s Algorithm
In which order does Prim’s algorithm select edges in the MST? Start from vertex s.
4
Algorithms (Robert Sedgewick, Kevin Wayne/Princeton)
Q
s
9
1
2
8
3
6
5
7
4
Q1: In which order does Prim’s algorithm select edges in the MST? Start from vertex s.

Prim’s Algorithm
In which order does Prim’s algorithm select edges in the MST? Start from vertex s.
5
Algorithms (Robert Sedgewick, Kevin Wayne/Princeton)
A
s
9
1
2
8
3
6
5
7
4

In a graph G with unique edge weights, do the edges of the (unique) MST change if we add 1000 to every edge weight?
6
Q
Q1: In a graph G with unique edge weights, do the edges of the (unique) MST change if we add 1000 to every edge weight?

In a graph G with unique edge weights, do the edges of the (unique) MST change if we add 1000 to every edge weight?
7
A

Multiplying by a Constant
In a graph G with unique edge weights, do the edges of the (unique) MST change if we multiply 1000 to every edge weight?
8
Q
Q1: In a graph G with unique edge weights, do the edges of the (unique) MST change if we multiply 1000 to every edge weight?

Multiplying by a Constant
In a graph G with unique edge weights, do the edges of the (unique) MST change if we multiply 1000 to every edge weight?
9
A

Secret Edge
Suppose the bold edges form a MST. Will the MST change as a result of introducing one new edge with weight w?
If w < 1, …
If 1 < w < 5, …
If 5 < w < 9, …
If 9 < w, …
10
Q
9
1
2
8
3
6
5
7
4
Suppose the bold edges form a MST. Will the MST change as a result of introducing one new edge with weight w?

Q1: If w < 1, …

Q2: If 1 < w < 5, …

Q3: If 5 < w < 9, …

Q4: If 9 < w, …

Secret Edge
Suppose the bold edges form a MST. Will the MST change as a result of introducing one new edge with weight w?
If w < 1, …
If 1 < w < 5, …
If 5 < w < 9, …
If 9 < w, …
11
A
9
1
2
8
3
6
5
7
4

Unknown Edge Weight
Suppose x is an unknown edge weight. Can the bold edges be a MST?
If so, for what values of x? If not, why not?
12
Q
9
1
2
8
3
6
x
7
4
Q1: Suppose x is an unknown edge weight. Can the bold edges be a MST? If so, for what values of x? If not, why not?

Unknown Edge Weight
Suppose x is an unknown edge weight. Can the bold edges be a MST?
If so, for what values of x? If not, why not?
13
A
9
1
2
8
3
6
x
7
4

Maximum Spanning Tree
Maximum spanning tree. Given an undirected graph G with positive edge weights, find a spanning tree that maximizes the sum of the edge weights.
Design an algorithm to find a maximum spanning tree in O(E log E) runtime.
14
Algorithms (Robert Sedgewick, Kevin Wayne/Princeton)
Q
9
1
2
8
3
6
5
7
4
Q1: Design an algorithm to find a maximum spanning tree in O(E log E) runtime.

Maximum Spanning Tree
Maximum spanning tree. Given an undirected graph G with positive edge weights, find a spanning tree that maximizes the sum of the edge weights.
Design an algorithm to find a maximum spanning tree in O(E log E) runtime.
15
Algorithms (Robert Sedgewick, Kevin Wayne/Princeton)
A
9
1
2
8
3
6
5
7
4

Min-Product Spanning Tree
Min-product spanning tree. Given an undirected graph G with positive edge weights, find a spanning tree that minimizes the product of the edge weights.
Design an algorithm to find a min-product spanning tree in O(E log E) runtime.
16
Algorithms (Robert Sedgewick, Kevin Wayne/Princeton)
Q
9
1
2
8
3
6
5
7
4
Q1: Design an algorithm to find a min-product spanning tree in O(E log E) runtime.

Min-Product Spanning Tree
Min-product spanning tree. Given an undirected graph G with positive edge weights, find a spanning tree that minimizes the product of the edge weights.
Design an algorithm to find a min-product spanning tree in O(E log E) runtime.
17
Algorithms (Robert Sedgewick, Kevin Wayne/Princeton)
A
9
1
2
8
3
6
5
7
4
``````