SlideShare ist ein Scribd-Unternehmen logo
1 von 82
Downloaden Sie, um offline zu lesen
Minimum Spanning Tree – Prim’s
and Kruskal’s algorithms
Dr. Maamoun Ahmed
A spanning tree of a graph is just a subgraph that
contains all the vertices and is a tree.
A graph may have many spanning trees.
or or or
Some Spanning Trees from Graph AGraph A
Spanning Trees
All 16 of its Spanning TreesComplete Graph
Minimum Spanning Trees
The Minimum Spanning Tree for a given graph is the Spanning Tree of
minimum cost for that graph.
5
7
2
1
3
4
2
1
3
Complete Graph Minimum Spanning Tree
Algorithms for Obtaining the Minimum Spanning Tree
• Kruskal's Algorithm
• Prim's Algorithm
• Boruvka's Algorithm
Kruskal's Algorithm
This algorithm creates a forest of trees. Initially the forest consists of n
single node trees (and no edges). At each step, we add one edge (the
cheapest one) so that it joins two trees together. If it were to form a cycle,
it would simply link two nodes that were already part of a single
connected tree, so that this edge would not be needed.
The steps are:
1. The forest is constructed - with each node in a separate tree.
2. The edges are placed in a priority queue.
3. Until we've added n-1 edges,
1. Extract the cheapest edge from the queue,
2. If it forms a cycle, reject it,
3. Else add it to the forest. Adding it to the forest will join two
trees together.
Every step will have joined two trees in the forest together, so that at
the end, there will only be one tree in T.
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Complete Graph
1
4
2
5
2
5
4
3
4
4
4
10
1
6
3
3
2
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A AB D
B B
B
C D
J C
C
E
F
D
D H
J E G
F FG I
G GI J
H J JI
2
5
2
5
4
3
4
4
10
1
6
3
3
2
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
B
B
D
J
C
C
E
F
D
D H
J
E G
F
F
G
I
G
G
I
J
H J
JI
1A D
4B C
4A B
Sort Edges
(in reality they are placed in a priority
queue - not sorted - but sorting them
makes the algorithm easier to visualize)
2
5
2
5
4
3
4
4
10
1
6
3
3
2
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
B
B
D
J
C
C
E
F
D
D H
J
E G
F
F
G
I
G
G
I
J
H J
JI
1A D
4B C
4A B
Add Edge
2
5
2
5
4
3
4
4
10
1
6
3
3
2
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
B
B
D
J
C
C
E
F
D
D H
J
E G
F
F
G
I
G
G
I
J
H J
JI
1A D
4B C
4A B
Add Edge
2
5
2
5
4
3
4
4
10
1
6
3
3
2
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
B
B
D
J
C
C
E
F
D
D H
J
E G
F
F
G
I
G
G
I
J
H J
JI
1A D
4B C
4A B
Add Edge
2
5
2
5
4
3
4
4
10
1
6
3
3
2
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
B
B
D
J
C
C
E
F
D
D H
J
E G
F
F
G
I
G
G
I
J
H J
JI
1A D
4B C
4A B
Add Edge
2
5
2
5
4
3
4
4
10
1
6
3
3
2
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
B
B
D
J
C
C
E
F
D
D H
J
E G
F
F
G
I
G
G
I
J
H J
JI
1A D
4B C
4A B
Add Edge
2
5
2
5
4
3
4
4
10
1
6
3
3
2
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
B
B
D
J
C
C
E
F
D
D H
J
E G
F
F
G
I
G
G
I
J
H J
JI
1A D
4B C
4A B
Cycle
Don’t Add Edge
2
5
2
5
4
3
4
4
10
1
6
3
3
2
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
B
B
D
J
C
C
E
F
D
D H
J
E G
F
F
G
I
G
G
I
J
H J
JI
1A D
4B C
4A B
Add Edge
2
5
2
5
4
3
4
4
10
1
6
3
3
2
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
B
B
D
J
C
C
E
F
D
D H
J
E G
F
F
G
I
G
G
I
J
H J
JI
1A D
4B C
4A B
Add Edge
2
5
2
5
4
3
4
4
10
1
6
3
3
2
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
B
B
D
J
C
C
E
F
D
D H
J
E G
F
F
G
I
G
G
I
J
H J
JI
1A D
4B C
4A B
Add Edge
2
5
2
5
4
3
4
4
10
1
6
3
3
2
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
B
B
D
J
C
C
E
F
D
D H
J
E G
F
F
G
I
G
G
I
J
H J
JI
1A D
4B C
4A B
Cycle
Don’t Add Edge
2
5
2
5
4
3
4
4
10
1
6
3
3
2
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
B
B
D
J
C
C
E
F
D
D H
J
E G
F
F
G
I
G
G
I
J
H J
JI
1A D
4B C
4A B
Add Edge
4
1
2
2 1
3
32
4
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Minimum Spanning Tree Complete Graph
Analysis of Kruskal's Algorithm
Running Time = O(m log n) (m = edges, n = nodes)
Testing if an edge creates a cycle can be slow unless a complicated data
structure called a “union-find” structure is used.
It usually only has to check a small fraction of the edges, but in some
cases (like if there was a vertex connected to the graph by only one edge
and it was the longest edge) it would have to check all the edges.
This algorithm works best, of course, if the number of edges is kept to a
minimum.
Prim's Algorithm
This algorithm starts with one node. It then, one by one, adds a node that
is unconnected to the new graph to the new graph, each time selecting
the node whose connecting edge has the smallest weight out of the
available nodes’ connecting edges.
The steps are:
1. The new graph is constructed - with one node from the old graph.
2. While new graph has fewer than n nodes,
1. Find the node from the old graph with the smallest connecting
edge to the new graph,
2. Add it to the new graph
Every step will have joined one node, so that at the end we will have
one graph with all the nodes and it will be a minimum spanning tree of
the original graph.
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Complete Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2
2 1
3
32
4
A
B C
D
E F
G
H
I
J
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Complete Graph Minimum Spanning Tree
– Matrix Form
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Prim’s Algorithm: Find the Minimum
Spanning Tree T:
Step 1: Select any node to be the first of T
Step 2: Circle the new node of T in the top
row and cross out the row corresponding
to this new node.
Step 3: Find the smallest weight left in the
columns of the nodes of T. Circle the weight.
Then choose the node whose weight is the
minimum to join T. (if several, choose any)
Step 4: Repeat steps 2 and 3 until T contains
every node.
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Two minimum edges, choose one!
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Two minimum edges, choose one!
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A B C D E F G H I J
A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞
B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10
C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞
D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6
E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞
F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞
G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4
H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2
I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3
J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
Analysis of Prim's Algorithm
Running Time = O(m + n log n) (m = edges, n = nodes)
If a heap is not used, the run time will be O(n^2) instead of
O(m + n log n). However, using a heap complicates the code since
you’re complicating the data structure. A Fibonacci heap is the best kind
of heap to use, but again, it complicates the code.
Unlike Kruskal’s, it doesn’t need to see all of the graph at once. It can
deal with it one piece at a time. It also doesn’t need to worry if adding
an edge will create a cycle since this algorithm deals primarily with the
nodes, and not the edges.
For this algorithm the number of nodes needs to be kept to a minimum
in addition to the number of edges. For small graphs, the edges matter
more, while for large graphs the number of nodes matters more.

Weitere ähnliche Inhalte

Mehr von Dr. Maamoun Ahmed

Solving linear homogeneous recurrence relations
Solving linear homogeneous recurrence relationsSolving linear homogeneous recurrence relations
Solving linear homogeneous recurrence relationsDr. Maamoun Ahmed
 
Theory of Computation - Lectures 6 & 7
Theory of Computation - Lectures 6 & 7Theory of Computation - Lectures 6 & 7
Theory of Computation - Lectures 6 & 7Dr. Maamoun Ahmed
 
Theory of Computation - Lectures 4 and 5
Theory of Computation - Lectures 4 and 5Theory of Computation - Lectures 4 and 5
Theory of Computation - Lectures 4 and 5Dr. Maamoun Ahmed
 
Theory of Computation - Lecture 3
Theory of Computation - Lecture 3Theory of Computation - Lecture 3
Theory of Computation - Lecture 3Dr. Maamoun Ahmed
 
Theory of Computation - Strings and Languages and Proofs (Lecture 2)
Theory of Computation  - Strings and Languages and Proofs (Lecture 2)Theory of Computation  - Strings and Languages and Proofs (Lecture 2)
Theory of Computation - Strings and Languages and Proofs (Lecture 2)Dr. Maamoun Ahmed
 

Mehr von Dr. Maamoun Ahmed (6)

A* - Astar - A-Star
A* - Astar - A-StarA* - Astar - A-Star
A* - Astar - A-Star
 
Solving linear homogeneous recurrence relations
Solving linear homogeneous recurrence relationsSolving linear homogeneous recurrence relations
Solving linear homogeneous recurrence relations
 
Theory of Computation - Lectures 6 & 7
Theory of Computation - Lectures 6 & 7Theory of Computation - Lectures 6 & 7
Theory of Computation - Lectures 6 & 7
 
Theory of Computation - Lectures 4 and 5
Theory of Computation - Lectures 4 and 5Theory of Computation - Lectures 4 and 5
Theory of Computation - Lectures 4 and 5
 
Theory of Computation - Lecture 3
Theory of Computation - Lecture 3Theory of Computation - Lecture 3
Theory of Computation - Lecture 3
 
Theory of Computation - Strings and Languages and Proofs (Lecture 2)
Theory of Computation  - Strings and Languages and Proofs (Lecture 2)Theory of Computation  - Strings and Languages and Proofs (Lecture 2)
Theory of Computation - Strings and Languages and Proofs (Lecture 2)
 

Kürzlich hochgeladen

Kürzlich hochgeladen (7)

Angewandte Kognitions- und Medienwissenschaft an der Universität Duisburg_Essen
Angewandte Kognitions- und Medienwissenschaft an der Universität Duisburg_EssenAngewandte Kognitions- und Medienwissenschaft an der Universität Duisburg_Essen
Angewandte Kognitions- und Medienwissenschaft an der Universität Duisburg_Essen
 
Wirtschaftsingenieurwesen an der Universität Duisburg-Essen
Wirtschaftsingenieurwesen an der Universität Duisburg-EssenWirtschaftsingenieurwesen an der Universität Duisburg-Essen
Wirtschaftsingenieurwesen an der Universität Duisburg-Essen
 
LAKO Kreativpreis_2024_Startnummer_02_(LFS_LA).pdf
LAKO Kreativpreis_2024_Startnummer_02_(LFS_LA).pdfLAKO Kreativpreis_2024_Startnummer_02_(LFS_LA).pdf
LAKO Kreativpreis_2024_Startnummer_02_(LFS_LA).pdf
 
Angewandte Philosophie an der Universität Duisburg-Essen.
Angewandte Philosophie an der Universität Duisburg-Essen.Angewandte Philosophie an der Universität Duisburg-Essen.
Angewandte Philosophie an der Universität Duisburg-Essen.
 
Welche KI-Kompetenzen brauchen Lehrpersonen?!
Welche KI-Kompetenzen brauchen Lehrpersonen?!Welche KI-Kompetenzen brauchen Lehrpersonen?!
Welche KI-Kompetenzen brauchen Lehrpersonen?!
 
1029-Danh muc Sach Giao Khoa khoi 12.pdf
1029-Danh muc Sach Giao Khoa khoi 12.pdf1029-Danh muc Sach Giao Khoa khoi 12.pdf
1029-Danh muc Sach Giao Khoa khoi 12.pdf
 
1029-Danh muc Sach Giao Khoa khoi 11.pdf
1029-Danh muc Sach Giao Khoa khoi 11.pdf1029-Danh muc Sach Giao Khoa khoi 11.pdf
1029-Danh muc Sach Giao Khoa khoi 11.pdf
 

Minimum spanning trees – prim's and kruskal's algorithms

  • 1. Minimum Spanning Tree – Prim’s and Kruskal’s algorithms Dr. Maamoun Ahmed
  • 2. A spanning tree of a graph is just a subgraph that contains all the vertices and is a tree. A graph may have many spanning trees. or or or Some Spanning Trees from Graph AGraph A Spanning Trees
  • 3. All 16 of its Spanning TreesComplete Graph
  • 4. Minimum Spanning Trees The Minimum Spanning Tree for a given graph is the Spanning Tree of minimum cost for that graph. 5 7 2 1 3 4 2 1 3 Complete Graph Minimum Spanning Tree
  • 5. Algorithms for Obtaining the Minimum Spanning Tree • Kruskal's Algorithm • Prim's Algorithm • Boruvka's Algorithm
  • 6. Kruskal's Algorithm This algorithm creates a forest of trees. Initially the forest consists of n single node trees (and no edges). At each step, we add one edge (the cheapest one) so that it joins two trees together. If it were to form a cycle, it would simply link two nodes that were already part of a single connected tree, so that this edge would not be needed.
  • 7. The steps are: 1. The forest is constructed - with each node in a separate tree. 2. The edges are placed in a priority queue. 3. Until we've added n-1 edges, 1. Extract the cheapest edge from the queue, 2. If it forms a cycle, reject it, 3. Else add it to the forest. Adding it to the forest will join two trees together. Every step will have joined two trees in the forest together, so that at the end, there will only be one tree in T.
  • 8. 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J Complete Graph
  • 9. 1 4 2 5 2 5 4 3 4 4 4 10 1 6 3 3 2 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A AB D B B B C D J C C E F D D H J E G F FG I G GI J H J JI
  • 10. 2 5 2 5 4 3 4 4 10 1 6 3 3 2 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J B B D J C C E F D D H J E G F F G I G G I J H J JI 1A D 4B C 4A B Sort Edges (in reality they are placed in a priority queue - not sorted - but sorting them makes the algorithm easier to visualize)
  • 11. 2 5 2 5 4 3 4 4 10 1 6 3 3 2 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J B B D J C C E F D D H J E G F F G I G G I J H J JI 1A D 4B C 4A B Add Edge
  • 12. 2 5 2 5 4 3 4 4 10 1 6 3 3 2 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J B B D J C C E F D D H J E G F F G I G G I J H J JI 1A D 4B C 4A B Add Edge
  • 13. 2 5 2 5 4 3 4 4 10 1 6 3 3 2 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J B B D J C C E F D D H J E G F F G I G G I J H J JI 1A D 4B C 4A B Add Edge
  • 14. 2 5 2 5 4 3 4 4 10 1 6 3 3 2 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J B B D J C C E F D D H J E G F F G I G G I J H J JI 1A D 4B C 4A B Add Edge
  • 15. 2 5 2 5 4 3 4 4 10 1 6 3 3 2 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J B B D J C C E F D D H J E G F F G I G G I J H J JI 1A D 4B C 4A B Add Edge
  • 16. 2 5 2 5 4 3 4 4 10 1 6 3 3 2 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J B B D J C C E F D D H J E G F F G I G G I J H J JI 1A D 4B C 4A B Cycle Don’t Add Edge
  • 17. 2 5 2 5 4 3 4 4 10 1 6 3 3 2 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J B B D J C C E F D D H J E G F F G I G G I J H J JI 1A D 4B C 4A B Add Edge
  • 18. 2 5 2 5 4 3 4 4 10 1 6 3 3 2 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J B B D J C C E F D D H J E G F F G I G G I J H J JI 1A D 4B C 4A B Add Edge
  • 19. 2 5 2 5 4 3 4 4 10 1 6 3 3 2 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J B B D J C C E F D D H J E G F F G I G G I J H J JI 1A D 4B C 4A B Add Edge
  • 20. 2 5 2 5 4 3 4 4 10 1 6 3 3 2 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J B B D J C C E F D D H J E G F F G I G G I J H J JI 1A D 4B C 4A B Cycle Don’t Add Edge
  • 21. 2 5 2 5 4 3 4 4 10 1 6 3 3 2 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J B B D J C C E F D D H J E G F F G I G G I J H J JI 1A D 4B C 4A B Add Edge
  • 22. 4 1 2 2 1 3 32 4 A B C D E F G H I J 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J Minimum Spanning Tree Complete Graph
  • 23. Analysis of Kruskal's Algorithm Running Time = O(m log n) (m = edges, n = nodes) Testing if an edge creates a cycle can be slow unless a complicated data structure called a “union-find” structure is used. It usually only has to check a small fraction of the edges, but in some cases (like if there was a vertex connected to the graph by only one edge and it was the longest edge) it would have to check all the edges. This algorithm works best, of course, if the number of edges is kept to a minimum.
  • 24. Prim's Algorithm This algorithm starts with one node. It then, one by one, adds a node that is unconnected to the new graph to the new graph, each time selecting the node whose connecting edge has the smallest weight out of the available nodes’ connecting edges.
  • 25. The steps are: 1. The new graph is constructed - with one node from the old graph. 2. While new graph has fewer than n nodes, 1. Find the node from the old graph with the smallest connecting edge to the new graph, 2. Add it to the new graph Every step will have joined one node, so that at the end we will have one graph with all the nodes and it will be a minimum spanning tree of the original graph.
  • 26. 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J Complete Graph
  • 27. 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J Old Graph New Graph 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J
  • 28. 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J Old Graph New Graph 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J
  • 29. 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J Old Graph New Graph 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J
  • 30. 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J Old Graph New Graph 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J
  • 31. 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J Old Graph New Graph 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J
  • 32. 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J Old Graph New Graph 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J
  • 33. 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J Old Graph New Graph 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J
  • 34. 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J Old Graph New Graph 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J
  • 35. 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J Old Graph New Graph 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J
  • 36. 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J Old Graph New Graph 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J
  • 37. 4 1 2 2 1 3 32 4 A B C D E F G H I J Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J
  • 38. Complete Graph Minimum Spanning Tree – Matrix Form 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J Prim’s Algorithm: Find the Minimum Spanning Tree T: Step 1: Select any node to be the first of T Step 2: Circle the new node of T in the top row and cross out the row corresponding to this new node. Step 3: Find the smallest weight left in the columns of the nodes of T. Circle the weight. Then choose the node whose weight is the minimum to join T. (if several, choose any) Step 4: Repeat steps 2 and 3 until T contains every node.
  • 39. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 40. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 41. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 42. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 43. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 44. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 45. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 46. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 47. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0 Two minimum edges, choose one!
  • 48. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0 Two minimum edges, choose one!
  • 49. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 50. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 51. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 52. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 53. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 54. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 55. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 56. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 57. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 58. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 59. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 60. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 61. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 62. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 63. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 64. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 65. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 66. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 67. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 68. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 69. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 70. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 71. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 72. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 73. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 74. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 75. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 76. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 77. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 78. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 79. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 80. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 81. Complete Graph Minimum Spanning Tree 4 1 2 3 2 1 3 5 3 4 2 5 6 4 4 10 A B C D E F G H I J A B C D E F G H I J A 0 4 ∞ 1 ∞ ∞ ∞ ∞ ∞ ∞ B 4 0 4 4 ∞ ∞ ∞ ∞ ∞ 10 C ∞ 4 0 ∞ 2 1 ∞ ∞ ∞ ∞ D 1 4 ∞ 0 ∞ ∞ ∞ 5 ∞ 6 E ∞ ∞ 2 ∞ 0 ∞ 2 ∞ ∞ ∞ F ∞ ∞ 1 ∞ ∞ 0 3 ∞ 5 ∞ G ∞ ∞ ∞ ∞ 2 3 0 ∞ 3 4 H ∞ ∞ ∞ 5 ∞ ∞ ∞ 0 ∞ 2 I ∞ ∞ ∞ ∞ ∞ 5 3 ∞ 0 3 J ∞ 10 ∞ 6 ∞ ∞ 4 2 3 0
  • 82. Analysis of Prim's Algorithm Running Time = O(m + n log n) (m = edges, n = nodes) If a heap is not used, the run time will be O(n^2) instead of O(m + n log n). However, using a heap complicates the code since you’re complicating the data structure. A Fibonacci heap is the best kind of heap to use, but again, it complicates the code. Unlike Kruskal’s, it doesn’t need to see all of the graph at once. It can deal with it one piece at a time. It also doesn’t need to worry if adding an edge will create a cycle since this algorithm deals primarily with the nodes, and not the edges. For this algorithm the number of nodes needs to be kept to a minimum in addition to the number of edges. For small graphs, the edges matter more, while for large graphs the number of nodes matters more.