0% found this document useful (0 votes)
3 views

Trees (2) - s copy

The document provides an overview of trees in graph theory, defining a tree as a connected, circuit-free graph and detailing various types of trees, including trivial and binary trees. It discusses properties of trees, exercises related to tree structures, and introduces concepts such as spanning trees and minimal spanning trees, along with Kruskal's algorithm for finding them. Additionally, it includes examples and exercises to reinforce understanding of these concepts.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Trees (2) - s copy

The document provides an overview of trees in graph theory, defining a tree as a connected, circuit-free graph and detailing various types of trees, including trivial and binary trees. It discusses properties of trees, exercises related to tree structures, and introduces concepts such as spanning trees and minimal spanning trees, along with Kruskal's algorithm for finding them. Additionally, it includes examples and exercises to reinforce understanding of these concepts.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 26

Welcome to !

Discrete Structures

1
Trees

2
TREE

A tree is a connected graph that does not contain any non-trivial


circuit. (i.e. it is circuitfree).
A trivial circuit is one that consists of a single vertex.
Examples of tree are

3
EXAMPLES OF NON TREES

In graph (a), there exists circuit, so not a tree.


In graph (b), there exists no connectedness, so not a tree.
In graph (c), there exists a circuit (also due to loop), so not a tree
(because trees have to be a circuit free).

4
SOME SPECIAL TREES

1. TRIVIAL TREE: A graph that consists of a single vertex is


called a trivial tree or degenerate tree.
2. EMPTY TREE: A tree that does not have any vertices or
edges is called an empty tree.
3. FOREST: A graph is called a forest if, and only if, it is
circuit-free. OR “Any non-connected graph that contains no
circuit is called a forest.”
Hence, it clears that the connected components of a forest are
trees.

5
PROPERTIES OF TREES

1. A tree with n vertices has n - 1 edges (where n ≥0).


2. Any connected graph with n vertices and n - 1 edges is a tree.
3. A tree has no non-trivial circuit; but if one new edge (but no
new vertex) is added to it, then the resulting graph has exactly
one non-trivial circuit.
4. A tree is connected, but if any edge is deleted from it, then the
resulting graph is not connected.
5. Any tree that has more than one vertex has at least two vertices
of degree 1.
6. A graph is a tree iff there is a unique path between any two of
its vertices.

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

Find all non-isomorphic trees with four vertices.


SOLUTION:
Any tree with four vertices has (4-1=3) three edges. Thus, the total degree
of a tree with 4 vertices must be 6 [by using total degree=2(total number
of edges)]. Also, every tree with more than one vertex has at least two
vertices of degree 1, so the only possible combinations of degrees for the
vertices of the trees are 1, 1, 1, 3 and 1, 1, 2, 2.
The corresponding trees (clearly non-isomorphic, by definition) are

8
EXERCISE

Find all non-isomorphic trees with five vertices.


SOLUTION:
There are three non-isomorphic trees with five vertices as shown
(where every tree with five vertices has 5-1=4 edges).

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

A vertex of degree 1 in a tree is called a terminal vertex or a leaf


and a vertex of degree greater than 1 in a tree is called an
internal vertex or a branch vertex.

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

We redraw the tree as and see what the relations are

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

• Draw a binary tree with height 3 and having seven terminal


vertices.

•Draw a binary tree to represent the following expression a/(b-c.d)

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

with total weight is 2 + 6 + 3 + 2 + 3 + 1 = 17

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

Input: G [a weighted graph with n vertices]


Algorithm:
1. Initialize T(the minimal spanning tree of G) to have all the vertices of G and no
edges.
2. Let E be the set of all edges of G and let m: = 0.
3. While (m < n - 1)
3a. Find an edge e in E of least weight.
3b. Delete e from E.
3c. If addition of e to the edge set of T does not produce a circuit then add e to the
edge set of T and set m: = m + 1
end while
Output T
end 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

Find all minimal spanning trees that can be obtained using


(a) Kruskal’s algorithm

(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

You might also like