You are on page 1of 18

Special Graph:Tree and

Forest
MSc.communication and knowledge
(Social Network Mining)
Presented by : Dikesh kumar Shrestha (402)
Trees:
• A is a root node.
• B is parent of D and E,
• A is ancestor of D and E.
• D and E are descendants of A
• C is the siblings of B.
• D and E are the children of B.
• D,E,F,G,I are leaves.
• A,B,C,H are internal nodes.
• The depth(level) of E is 2.
• The Height of tree is 3
• The degree of node B is 2
Trees:
• Tree: A Tree is a connected acyclic undirected graph.
• Properties:
• There is a unique simple path between any 2 of its
vertices
• No loops
• No multiple edges
Example 1
G1: This graph is a tree because it is a connected graph with no simple
circuit
Example 2
• G2 : is not a tree “because there is a cycle a, b, c, d, a ”
Forest
• A forest is an undirected graph such that
1. It has no simple circuit
2. It is not necessarily connected
• The connected components of a forest are trees
Labeled Trees
• Vertices are assigned unique number from 1 to n.
• The number of labeled trees of n number of vertices is n^n-2.
Unlabeled trees
• Vertices of which are not assigned any number.
• The number of vertices is (2n)!/(n+1)!n!.
Binary tree
• An ordered tree is one in which the children of
each node are ordered.
• Binary tree: ordered tree with all nodes
having at most 2 children.
• A Binary tree is either a
• Leaf or
• An internal node the root and one /two binary trees
(left subtree and / right subtree).
Binary search tree:

• Binary Search tree is a binary tree which satisfies the following property −
1. X in left sub-tree of vertex V, Value(X) ≤ Value(V)
2. .Y in right sub-tree of vertex V, Value(Y) ≥ Value(V)
Example:
Rooted (Directed)Trees:
• A rooted tree is a tree in which one node has been designated the
root and every edge is directed away from the root.
Centers and Bi-Centers of a Tree
• Center of a tree is a vertex with minimal eccentricity.
• Eccentricity of vertex X on a tree graph is the maximum
distance between the vertex X and any other vertex of the tree.
• If a tree has only one center, it is called central tree and if a tree has
only more than one centre, it is called Bi-central tree.
Note: Every tree is either central or bi-central.
Kind of confusing right?
Centers and bi-center …… umm……. But how to find out?
Algorithm to find centers and bi-center of a
tree
• Step 1: Remove all the vertices of degree 1 from the given tree and
also remove their incident edges.
• Step 2: Repeat step 1 until either a single vertex or two vertices joined
by an edge is left. If a single vertex is left then it is the center of the
tree and if two vertices joined by an edge is left then it is the bi-
center of the tree.
Continue…..
• Let’s understand with a problem 1.

• Step 1:

• Step 2:
Continue……
• Problem 2.

• Step 1:

• Step 2:
Compliete binary tree
• Level ith has 2^ith nodes
• In a tree of height h,

• Leaves are at level h


• No. of leaves is 2^h
• No. of internal nodes=1+2+2^2+….+2^h -1 = 2^h -1
• No. of internal nodes= no of leaves - 1
• Total no. of nodes is 2^h+1 -1= n
• In a tree of n nodes
• No of leaves is (n+1)/2
• Height = log2 (no of leaves)
Examples of binary Trees
• Arithmetic expressions

A+B*C
Application of graph and tree
Note: every tree can be considered as a graph, but every graph cannot
be considered as a tree.
• Graph and tree are the most popular data structures that are used to
resolve various complex problems.
• Popular in computer designing, physical structures and engineering
science.
• For example binary tree is used for storage purpose and search is as
quick as in a sorted array and insertion or deletion operation .
• Tree represents a hierarchy , for e.g. the organization structure of a
corporation or table of contents of a book.

You might also like