Professional Documents
Culture Documents
Nothing Special 3
Nothing Special 3
Discrete Mathematics
Spanning Trees 1
Example: Road System
Farnham Trois-Rivières
Sherbrooke
Bedford
Cowansville
Granby
Spanning Trees 2
Spanning Tree
Farnham Trois-Rivières
Sherbrooke
Bedford
Cowansville
Granby
Farnham Trois-Rivières
Sherbrooke
Bedford
Cowansville
Granby
Spanning Trees 3
Spanning Tree
Definition
Let G be a simple graph. A spanning tree of G is a subgraph of
G that is a tree containing every vertex of G .
Theorem
A simple graph is connected if and only if it has a spanning tree.
Spanning Trees 4
How to Build a Spanning Tree of a Graph
Sherbrooke
Bedford
Cowansville
Granby
Farnham Trois-Rivières
Sherbrooke
Bedford
Cowansville
Granby
This algorithm is inefficient because it requires that simple circuits
be identified.
Spanning Trees 5
Depth-First Search
Spanning Trees 6
Example of Depth-First Search
a d i j f
h e
c f
e h k k c
i g d
b g j b a
Grapg G Spanning tree of G
Spanning Trees 7
Algorithm of Depth-First Search
Spanning Trees 8
Algorithm of Depth-First Search (cont.)
Spanning Trees 9
Breadth-First Search
Spanning Trees 10
Example of Breadth-First Search
a b c l e
d e f g b d f i
h i
k
j a c h g j
m k l m
Simple graph G Spanning tree
Spanning Trees 11
Breadth-First Search Iterative Algorithm
Spanning Trees 12
Breadth-First Search Iterative Algorithm (cont.)
Spanning Trees 13
Backtracking Applications
Spanning Trees 14
Example of Backtracking
Problem: Find a subset of the set {11, 7, 5, 9} such that the sum
of the elements of the subset is 14. Here is the exhaustive list, as a
decision tree, of all possible subsets (and solutions).
11 7 5 9
7 5 9 11 5 9 11 7 9 11 7 5
5 9 7 9 7 5 5 9 11 9 11 5 7 9 11 9 11 7 7 5 11 5 11 7
Spanning Trees 15
Example of Backtracking
11 7 5
7 5 9 11 5 9 11 7 9
11 9 11 9
This subtree, of the decision tree with all possible solutions,
represent the depth-first search done until the first solution {5, 9}
were found.
Spanning Trees 16