Week 4
Week 4
Note that two branches placed end-to-end are equivalent to a single branch,
which means for example, that there is only one tree of order 3. The number
t(n) of nonisomorphic trees of order n=1, 2, ... (where trees of orders 1, 2, ...,
6 are illustrated above), are 1, 1, 1, 2, 3, 6, 11, 23, 47, 106, 235, 551, 1301,
3159, ... (OEIS A000055).
Spanning Tree
Spanning tree and Enumeration (pg 75 wilson)
Trees were first studied by Cayley (1857). McKay maintains a database of trees
up to 18 vertices, and Royle maintains one up to 20 vertices.
• THEOREM 3.3 (Cayley, 1889) The complete graph K n for n>0
n2
contains exactly n distinct spanning trees (pg 67: Wilson)
n2
• COROLLARY 3.4 The number of spanning trees of Kn is .n
Optimization and Trees
Definition
• A Minimum Spanning Tree (MST) is a subgraph of an undirected graph
such that the subgraph spans (includes) all nodes, is connected, is
acyclic, and has minimum total edge weight
Algorithm Characteristics
• Both Prim’s and Kruskal’s Algorithms work with
undirected graphs
• Both work with weighted and unweighted graphs but
are more interesting when edges are weighted
• Both are greedy algorithms that produce optimal
solutions
Prim’s Algorithm
Brinleigh 5 Cornwell
3
6 4
8
8
Avonford Fingley Donster
7
5
4 2
Edan
We model the situation as a network, then the
problem is to find the minimum connector for the
network
B 5 C
3
6 4
8
8
A F D
7
5
4 2
E
Kruskal’s Algorithm
List the edges in
order of size:
B 5 C ED 2
AB 3
3 AE 4
4
8 6 CD 4
BC 5
8 EF 5
A F D CF 6
7 AF 7
5 BF 8
4 CF 8
2
E
Kruskal’s Algorithm
E
Kruskal’s Algorithm
Select the next shortest
edge which does not
B 5 C
create a cycle
ED 2
3 AB 3
4
8 6
8
A F D
7
5
4 2
E
Kruskal’s Algorithm
Select the next shortest
edge which does not
B 5 C
create a cycle
ED 2
3 AB 3
4
8 6 CD 4 (or AE 4)
8
A F D
7
5
4 2
E
Kruskal’s Algorithm
Select the next shortest
edge which does not
B 5 C
create a cycle
ED 2
3 AB 3
4
8 6 CD 4
AE 4
8
A F D
7
5
4 2
E
Kruskal’s Algorithm
Select the next shortest
edge which does not
B 5 C
create a cycle
ED 2
3 AB 3
4
8 6 CD 4
AE 4
8 BC 5 – forms a cycle
A F D EF 5
7
5
4 2
E
Kruskal’s Algorithm
All vertices have been
connected.
B 5 C The solution is
3 ED 2
4
8 6 AB 3
CD 4
8 AE 4
A F D EF 5
7
5
4 Total weight of tree: 18
2
E
Prim’s Algorithm
Select any vertex
B 5 C
A
8 AB 3
A F D
7
5
4 2
E
Prim’s Algorithm
Select the shortest
edge connected to
B 5 C
any vertex already
connected.
3 AE 4
4
8 6
8
A F D
7
5
4 2
E
Prim’s Algorithm
Select the shortest
edge connected to
B 5 C
any vertex already
connected.
3 ED 2
4
8 6
8
A F D
7
5
4 2
E
Prim’s Algorithm
Select the shortest
edge connected to
B 5 C
any vertex already
connected.
3 DC 4
4
8 6
8
A F D
7
5
4 2
E
Prim’s Algorithm
Select the shortest
edge connected to
B 5 C
any vertex already
connected.
3 EF 5
4
8 6
8
A F D
7
5
4 2
E
Prim’s Algorithm
All vertices have been
connected.
B 5 C The solution is
3 AB 3
4
8 6 AE 4
ED 2
8 DC 4
A F D EF 5
7
5
4 Total weight of tree: 18
2
E
Some points to note