Professional Documents
Culture Documents
MAT214ALecture4 19
MAT214ALecture4 19
MAT214ALecture4 19
Friday 4/19
Spring 2019 10:50am - 12:05pm
Recall:
Section 9-3 Spanning Trees
Sometimes, you are given graph, but only need one way to connect nodes. Think of communication networks,
transportation networks, electrical grids, etc.
A spanning tree T of a graph G is a subgraph of G that connects all the vertices of G.
A spanning tree is not unique unless the graph is a tree graph
The breadth first search tree is a shortest path tree starting from its root. *BFS tree is short and “branchy”
The idea of this algorithm is to make a path as long as possible, and then go back (backtrack) to add branches
also as long as possible. *The DFS tree is typically "long and stringy"
Section 9-4 Minimal Spanning Trees
Given a weighted graph, find a minimum weight subgraph that contains all vertices.
Must be a spanning tree – must contain all vertices
Must be connected – so every vertex can be reached from every other
Must have one simple path between each pair of vertices – multiple paths would not produce a minimum
weight.
Step 1:
Assume start is vertex 1
Edge Weight
(1,5) 3
(1,3) 2 select
(1,2) 4
Step 2:
V = {1, 3}, E = {(1,3)}
Edge Weight
(1,5) 3
(1,2) 4
(3,4) 1 select
(3,6) 3
(3,5) 6
Step 3:
V = {1, 3, 4}, E = {(1,3), (3,4)}
Edge Weight
(1,5) 3 select
(1,2) 4
(3,6) 3
(3,5) 6
(4,6) 3
(4,2) 5
**I could select either e(1,5) or e(4,6). We will choose e(1,5)
Step 4:
V = {1, 3, 4, 5}, E = {(1,3), (3,4) (1,5)}
Edge Weight
(1,2) 4
(3,6) 3
(3,5) 6
(4,6) 3
(4,2) 5
(5,6) 2 select
Step 5:
V = {1, 3, 4, 5, 6}, E = { (1,3), (3,4), (1,5), (5,6)}
Edge Weight
(1,2) 4 select
(3,6) 3
(4,6) 3
(4,2) 5
1 2
3 4
5 6
Note that this is not the same as the “nearest neighbor” approximation approach to the Traveling
Salesman Problem. The “nearest neighbor” selects nearest unvisited vertex incident to most recently
added vertex. This does not always give the minimum weight tree.
Homework #1
Def: A binary tree is a rooted tree in which each vertex has at most 2 children.
If a vertex has 2 children, we label right or left. If a vertex has only one child, we name as either right or left.
Binary tree:
Def: A full binary tree is a binary tree where each vertex has 0 or 2 children.
Full binary tree:
Theorem: If T is a full binary tree with I internal vertices, then T has i + 1 terminating vertices and 2i + 1 total
vertices.
Proof: Each internal vertex has 2 children = 2i
Root is a “nonchild” =1
Total vertices =2i + 1
Example: Show that if n teams play in a single elimination tournament, n-1 matches are played.
This is a full binary tree where each node has 0 or 2 children.
Teams are the terminal vertices. There are n teams so n terminating vertices
We know from theorem that there are i + 1 terminating vertices, where i = # of internal vertices
So, n = i+ 1
We know that the matches are the internal vertices – there are two teams playing, winner is vertex. The
number of matches = i
Substituting: n = #matches + 1, rearranging #matches = n – 1
Done
Example: Once the teams are assigned, how many ways can the tournament be played?
There are n – 1matches, each match has two possible outcomes.
There are 2n-1 possible ways the tournament can be played
Height = 4 levels There are t ≤ 24 terminal vertices Height = 3 levels There are t ≤ 23 terminal vertices
t ≤16 terminal vertices t ≤ 8 terminal vertices
5 ≤ 16 5≤8