Vous êtes sur la page 1sur 2

ICS 241: Discrete Mathematics II (Spring 2015)

11.5 Minimum Spanning Trees


Minimum Spanning Tree

A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest
possible sum of weights of its edges.

Prim’s Algorithm

An algorithm for finding a minimum spanning tree.

• Begin by choosing any edge with smallest weight, putting it into the spanning tree.

• Successively add to the tree edges of minimum weight that are incident to a vertex already
in the tree, never forming a simple circuit with those edges already in the tree.

• Stop when n − 1 edges have been added.

Algorithm 3 Prim(G : weighted connected undirected graph with n vertices)


1: T = a minimum-weight edge
2: for i = 1 to n − 2 do
3: e = an edge of minimum weight incident to a vertex in T and not forming a simple circuit
in T if added to T
4: T = T with e added
5: end for
6: return T {T is a minimum spanning tree of G}

Kruskal’s Algorithm

An algorithm for finding a minimum spanning tree.

• Begin by choosing an edge in the graph with minimum weight.

• Successively add edges with minimum weight that do not form a simple circuit with those
edges already chosen.

• Stop after n − 1 edges have been selected.

Algorithm 4 Kruskal(G : weighted connected undirected graph with n vertices)


1: T = empty graph
2: for i = 1 to n − 1 do
3: e = any edge in G with smallest weight that does not form a simple circuit when added to T
4: T = T with e added
5: end for
6: return T {T is a minimum spanning tree of G}

1
ICS 241: Discrete Mathematics II (Spring 2015)

11.5 pg. 802 # 3

Use Prim’s algorithm to find a minimum spanning tree for the given weighted graph.

Choice Edge Weight


1 {e, f } 1 a b c
2 {c, f } 3
3 {e, h} 3
4 {h, i} 2
d e f
5 {b, c} 4
6 {b, d} 3
7 {a, d} 2
8 {g, h} 4 g h i
total: 22

11.5 pg. 802 # 7

Use Kruskal’s algorithm to find a minimum spanning tree for the weighted graph in Exercise 3.

Choice Edge Weight


1 {e, f } 1 a b c
2 {a, d} 2
3 {h, i} 2
4 {b, d} 3
d e f
5 {c, f } 3
6 {e, h} 3
7 {b, c} 4
8 {g, h} 4 g h i
total: 22

Vous aimerez peut-être aussi