Trees (2) - s copy
Trees (2) - s copy
Discrete Structures
1
Trees
2
TREE
3
EXAMPLES OF NON TREES
4
SOME SPECIAL TREES
5
PROPERTIES OF TREES
6
Exercise
Explain why graphs with the given specification do not exist.
1. Tree, twelve vertices, fifteen edges.
2. Tree, five vertices, total degree 10.
SOLUTION:
1. Any tree with 12 vertices will have 12 - 1 = 11 edges, not 15.
2. Any tree with 5 vertices will have 5 - 1 = 4 edges.
Since, total degree of graph = 2 (No. of edges)
= 2(4) = 8
Hence, a tree with 5 vertices would have a total degree 8, not 10.
7
EXERCISE
8
EXERCISE
In part (a), tree has 2 vertices of degree ‘1’ and 3 vertices of degree ‘2’.
In part (b), 3 vertices have degree ‘1’, 1 has degree ‘2’and 1 vertex has degree
‘3’.
In part (c), possible combinations of degree are 1, 1, 1, 1, 4.
9
DEFINITION
EXAMPLE:
The terminal vertices of the tree are v1, v2, v5, v6 and v8 and
internal vertices are v3, v4, v7.
10
ROOTED TREE
A rooted tree is a tree in which one vertex is distinguished from the others and is
called the root.
The level of a vertex is the number of edges along the unique path between it and
the root.
The height of a rooted tree is the maximum level to any vertex of the tree.
The children of any internal vertex v are all those vertices that are adjacent to v
and are one level farther away from the root than v.
If w is a child of v, then v is called the parent of w.
Two vertices that are both children of the same parent are called siblings.
Given vertices v and w, if v lies on the unique path between w and the root, then
v is an ancestor of w and w is a descendant of v.
11
ROOTED TREE
12
ROOTED TREE
EXERCISE:
Consider the rooted tree shown below with root v0
a. What is the level of v8?
b. What is the level of v0?
c. What is the height of this tree?
d. What are the children of v10?
e. What are the siblings of v1?
f. What are the descendants of v12?
13
BINARY TREE
A binary tree is a rooted tree in which every internal vertex has at most two
children.
Every child in a binary tree is designated either a left child or a right child (but
not both). A full binary tree is a binary tree in which each internal vertex has
exactly two children.
EXAMPLE
14
REPRESENTATION OF ALGEBRAIC
EXPRESSIONS BY BINARY TREES
Binary trees are specially used in computer science to represent algebraic expression with
Arbitrary nesting of balanced parentheses.
The above figure represents the expression a/b. Here the operator (/) is the root and b are the
left and right children.
The second figure represents the expression a/(c+d).Here the operator (/) is the root.
Here the terminal vertices are variables (here a, c and d), and the internal vertices are
arithmetic operators (+ and /).
15
Task
16
SPANNING TREES
Introduction:
Suppose it is required to develop a system of roads between six major cities. A survey of
the area revealed that only the roads shown in the graph could be constructed.
For economic reasons, it is desired to construct the least possible number of roads to
connect the six cities.
One such set of roads is
Note that the subgraph representing these roads is a tree, it is connected &
circuit-free (six vertices and five edges)
17
SPANNING TREES
A spanning tree for a graph G is a subgraph of G that contains every vertex of G and is a
tree.
REMARK:
1. Every connected graph has a spanning tree.
2. A graph may have more than one spanning trees.
3. Any two spanning trees for a graph have the same number of edges.
4. If a graph is a tree, then its only spanning tree is itself.
EXERCISE:
Find a spanning tree for the graph below:
18
SPANNING TREES
SOLUTION:
The graph has 6 vertices (a, b, c, d, e, f) & 9 edges so we must delete 9 - 6 + 1 = 4 edges
(as we have studied in lecture 44 that a tree of vertices n has n-1 edges). We delete an
edge in each cycle.
1. Delete af 2. Delete fe
3. Delete be 4. Delete ed
Note it that we can construct road from vertex a to b, but can’t go from “a to e”, also
from “a to d” and from “a to c “, because there is no path available.
19
SPANNING TREES
EXERCISE:
Find all the spanning trees of the graph given below.
20
DEFINITION
A WEIGHTED GRAPH is a graph for which each edge has an associated real
number weight.
The sum of the weights of all the edges is the total weight of the graph.
EXAMPLE:
The figure shows a weighted graph
21
MINIMAL SPANNING TREE
A minimal spanning tree for a weighted graph is a spanning tree that has the least
possible total weight compared to all other spanning trees of the graph.
If G is a weighted graph and e is an edge of G then w(e) denotes the weight of e
and w(G) denotes the total weight of G.
EXERCISE:
Find the three spanning trees of the weighted graph below. Also indicate the
minimal spanning tree.
T 2 is the minimal spanning tree, since it has the minimum weight among the
spanning trees. 22
KRUSKAL’S ALGORITHM
23
KRUSKAL’S ALGORITHM
EXERCISE:
Use Kruskal’s algorithm to find a minimal spanning tree for the graph below.
Indicate the order in which edges are added to form the tree.
SOLUTION:
Minimal spanning tree:
24
EXERCISE
(a) When Kruskal’s algorithm is applied, edges are added in one of the following
two orders:
1. {c, d}, {c, e}, {c, b}, {d, a}
2. {c, d}, {d, e}, {c, b}, {d, a}
Thus, there are two distinct minimal spanning trees:
25
Thank You
26