You are on page 1of 11

Government Engineering College, Modasa.

Department of Sciences and Humanities


4th Semester B.E. Programme (IT)
Discrete Mathematics - (3140708)
ACADEMIC YEAR 2021-2022
UNIT-5 TREE
Introduction to Trees
Definition: A tree is a connected undirected graph with no simple circuits.
• A tree is a connected undirected graph with
– No simple circuits
– No multiple edges
– No loops
 An undirected graph is a tree if and only if there is a unique simple path between any two of its
vertices
Q. Which graphs are trees?

Answer: G1, G2
Forest:
• What if there are no simple circuits but the graph is not connected?
• Each of the connected components is a tree
The collection is called a forest
Root Tree:
A rooted tree is a tree in which one vertex has been designed as the root and every edge is directed away
from the root.

What if a different root is chosen?

Consider
• If v is a vertex of tree T other than the root, the parent of v is the unique vertex u such that there is a
directed edge from u to v.
• When u is the parent of v, v is called the child of u.
• If two vertices share the same parent, then they are called siblings.
• The ancestors of a vertex other than the root are the vertices in the path from the root to this vertex,
excluding the vertex itself and including the root.
• The descendants of a vertex v are those
vertices that have v as an ancestor
• A vertex with no children is called a leaf.
• Vertices with children are called internal vertices.

• If a is a vertex in a tree, the subtree with a as its root is:


• the subgraph of the tree consisting of a and its descendants, and all edges incident to these
descendants

• A rooted tree is called an m-ary tree if every internal vertex has no more than m children.
• A tree is called a full m-ary tree if every internal vertex has exactly m children.
• An m-ary tree with m  2 is called a binary tree.
Q. What is the arity of this tree?
• Is this a full m-ary tree?
-------------------
• This is a 2-ary, or binary, tree.
• Yes, this is a full binary tree, since every internal vertex has exactly 2 children.

• Q. Is this a full m-ary tree?


This is a full 3-ary tree, since every internal vertex has exactly 3 children

• This is a full 5-ary tree

• Is following a full m-ary tree?


Some internal nodes have 2 children, but some have 3, so this is a 3-ary
tree.

It is not a full-3-ary tree, since one internal node has only 2 children.

• An ordered rooted tree is one where the children of each internal vertex are ordered.
• In an ordered binary tree, if an internal vertex has two children, then they are called left child and
right child.
• The subtree rooted at the left child of a vertex is called the left subtree and subtree rooted at the right
child of a vertex is called the right subtree.

• The level of a vertex v in a rooted tree is the length of the unique path from the root to this vertex.
• What is the level of the root? 0
The height of a rooted tree is the maximum of the levels of the vertices

Properties of Trees:
• A tree with n vertices has n1 edges.
• An full m-ary tree with i internal vertices contains n = mi + 1 vertices.
• A rooted m-ary tree of height h is called balanced if all leaves are at levels h or h–1
Q. Is this tree balanced?
Distance in Graph:
In a connected graph G, The distance 𝑑(𝑣𝑖 , 𝑣𝑗 ) between two vertices 𝑣𝑖 and 𝑣𝑗 is the length of the shortest
path between them.
d(a, c) = d(c, a)
d(a, b) = d(b, a)
d(a, d) = d(d, a)

Eccentricity:
The eccentricity of a vertex 𝑣 (𝐸(𝑣)) in a graph G is the distance from vertex 𝑣 to the vertex farthest from 𝑣
in graph G.
𝐸(𝑣) = max 𝑑(𝑣, 𝑣𝑖 )

For vertex a,
d (a, b) = 1
d (a, c) = 2 = d (a, f)
d (a, d) = 3 = d (a, e)
E(a) = max {1, 2, 3, 3, 2}
=3

Centre of a Graph:
A vertex with minimum eccentricity in graph G is called a center of G.

Here, E(a) = 3 = E(d) = E(e) = E(f)


E(b) = 2 = E(c)
Minimum E = 2 = E(b) and E(c)
Vertices b and c are center of graph.

Spanning Trees:
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
Example 1 Find a spanning tree of G

Solution: Remove an edge from any circuit.


(Repeat until no circuit exists)

Four spanning trees of G:


Note: A simple graph is connected if and only if it has a spanning tree
Minimum Spanning Trees
G: connected weighted graph (each edge has an weight  0)
Definition minimum spanning tree of G: a spanning tree of G with smallest sum of weights of its edges.

Example: Use Prim’s algorithm to find a minimum spanning tree of G.

Solution:
Example: Use Kruskal algorithm to find a minimum spanning tree of G

Solution:

Example: Find the spanning tree for the following Graphs

Example: Use Prim’s and Kruskal’s algorithm for finding the minimum spanning tree from the
following weighted graphs

You might also like