0% found this document useful (0 votes)
63 views15 pages

5 Tree 1

The document discusses trees as a non-linear data structure. It defines trees as a set with one root element and non-empty subsets that are subtrees of the root. It provides definitions for key tree concepts like terminal/leaf nodes, levels of nodes, ordered trees, forests, directed trees, and ways to represent trees using Venn diagrams, nesting parentheses, tables, and levels. It also defines binary trees, m-ary trees, and how any tree can be uniquely represented as a binary tree.

Uploaded by

Narendra Parmar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views15 pages

5 Tree 1

The document discusses trees as a non-linear data structure. It defines trees as a set with one root element and non-empty subsets that are subtrees of the root. It provides definitions for key tree concepts like terminal/leaf nodes, levels of nodes, ordered trees, forests, directed trees, and ways to represent trees using Venn diagrams, nesting parentheses, tables, and levels. It also defines binary trees, m-ary trees, and how any tree can be uniquely represented as a binary tree.

Uploaded by

Narendra Parmar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Data Structures (DS)

GTU # 3130702

Non-Linear Data Structure


Tree Part-1
Tree– Concepts & Definitions
 A tree is a non-empty set, one element of which is designated the root of the tree while the
remaining elements are partitioned into non-empty sets each of which is a sub-tree of the root.

Non-Linear Data Structure (Tree Part-1) 2


Tree– Concepts & Definitions

𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎 𝑽𝟎 𝑽𝟎
𝑽𝟐 𝑽𝟑 𝑽𝟒 𝑽𝟖 𝑽𝟗 𝑽𝟏 𝑽𝟕 𝑽𝟕 𝑽𝟏

𝑽𝟏 𝑽𝟕 𝑽𝟐 𝑽𝟑 𝑽𝟒 𝑽𝟖 𝑽𝟗 𝑽𝟖 𝑽𝟗 𝑽𝟐 𝑽𝟑 𝑽𝟒

𝑽𝟎 𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎 𝑽 𝟏𝟎 𝑽 𝟓 𝑽 𝟔
(a) (b) (c)

Non-Linear Data Structure (Tree Part-1) 3


Tree– Concepts & Definitions
 Terminal Node (Leaf Node)
 In a directed tree, any node which has out degree 0 is called terminal node or leaf node.

 Level of Node
 The level of any node is the length of its path from the root.

 Ordered Tree
 In a directed tree an ordering of the nodes at each level is prescribed then such a tree is called ordered tree.
 The diagrams (b) and (c) represents same directed tree but different ordered tree.

 Forest
 If we delete the root and its edges connecting the nodes at level 1, we obtain a set of disjoint tree. A set of
disjoint tree is a forest.

Non-Linear Data Structure (Tree Part-1) 4


Tree– Concepts & Definitions
 Directed Tree
 A directed tree is an acyclic digraph which has one node called its root with in degree 0, while all other nodes
have in degree 1.
 Every directed tree must have at least one node.
 An isolated node is also a directed tree.

𝑽𝟎 Root Node

𝑽𝟏 𝑽𝟕

𝑽𝟐 𝑽𝟑 𝑽𝟒 𝑽𝟖 𝑽𝟗
Terminal or
𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎 Leaf Node
Non-Linear Data Structure (Tree Part-1) 5
Representation of Directed Tree
 Other way to represent directed tree are
 Venn Diagram
𝑽𝟎
 Nesting of Parenthesis
𝑽𝟏 𝑽𝟕
 Like table content of Book
 Level Format
𝑽𝟐 𝑽𝟑 𝑽𝟒 𝑽𝟖 𝑽𝟗

𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎

Non-Linear Data Structure (Tree Part-1) 6


Venn Diagram

𝑽𝟎
V0
𝑽𝟏 𝑽𝟕 V1 V7

V2 V9
𝑽𝟐 𝑽𝟑 𝑽𝟒 𝑽𝟖 𝑽𝟗 V3
V5 V10

𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎 V6
V4

V8

Non-Linear Data Structure (Tree Part-1) 7


Nesting of Parenthesis
Like a table Content of Book
𝑽𝟎 V0
V1
𝑽𝟏 𝑽𝟕 V2
V5
V6
𝑽𝟐 𝑽𝟑 𝑽𝟒 𝑽𝟖 𝑽𝟗 V3
V4

𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎 V7
V8
V9
V10

(V0 (V1 (V2 (V5) (V6) ) (V3) (V4) ) (V7 (V8) (V9 (V10) ) ) )
Nesting of Parenthesis
Non-Linear Data Structure (Tree Part-1) 8
Level Format

𝑽𝟎 1 V0
2 V1
𝑽𝟏 𝑽𝟕 3 V2
4 V5
4 V6
𝑽𝟐 𝑽𝟑 𝑽𝟒 𝑽𝟖 𝑽𝟗 3 V3
3 V4
𝑽𝟓 𝑽𝟔 𝑽 𝟏𝟎 2 V7
3 V8
3 V9
4 V10

Non-Linear Data Structure (Tree Part-1) 9


Tree– Concepts & Definitions
 The node that is reachable from a node is called descendant of a node.
 The nodes which are reachable from a node through a single edge are called the children of
node.
 M-ary Tree
 If in a directed tree the out degree of every node is less than or equal to m then tree is called an m-ary tree.

 Full or Complete M-ary Tree


 If the out degree of each and every node is exactly equal to m or 0 and their number of nodes at level i is
m(i-1) then the tree is called a full or complete m-ary tree.
 Positional M-ary Tree
 If we consider m-ary trees in which the m children of any node are assumed to have m distinct positions, if
such positions are taken into account, then tree is called positional m-ary tree.

Non-Linear Data Structure (Tree Part-1) 10


Tree– Concepts & Definitions
 Height of the tree
 The height of a tree is the length of the path from the root to the deepest node in the tree.

 Binary Tree
 A binary tree is either empty or consists of a node called the root together with two binary trees called the left
subtree and the right subtree
 If in a directed tree the out degree of every node is less than or equal to 2 then tree is called binary tree.

 Strictly Binary Tree


 A strictly binary tree (sometimes proper binary tree or 2-tree or full binary tree) is a tree in which every node
other than the leaves has two children.
 Complete Binary Tree
 If the out degree of each and every node is exactly equal to 2 or 0 and their number of nodes at level i is 2(i-
1) then the tree is called a full or complete binary tree.
Non-Linear Data Structure (Tree Part-1) 11
Tree– Concepts & Definitions
 Sibling
 Siblings are nodes that share the same parent node

 Positional m-ary Tree


 If we consider m-ary trees in which the m children of any node are assumed to have m distinct positions, if
such positions are taken into account, then tree is called positional m-ary tree

0 1 0 1 0 1

00 01 11 00 01 11 11 00 01 10

(a) Binary tree (b) Complete binary tree (c)

Non-Linear Data Structure (Tree Part-1) 12


Convert any tree to Binary Tree
 Every Tree can be Uniquely represented by binary tree
 Let’s have an example to convert given tree into binary tree
a
a
a
b

b f b f
c f

g
d
c d g j k c d g j k
h j
e

e h i e h i i k

Non-Linear Data Structure (Tree Part-1) 13


Convert Forest to Binary Tree

a g
a

b c
h i
b g

d e f
j k l
d c h

a g
e j i

b c h i
f k l

d e f j k l

Non-Linear Data Structure (Tree Part-1) 14


Thank
You

You might also like