SlideShare a Scribd company logo
1 of 16
Trees in Data Structure
Mrs.R.Sabitha M.Sc.,M.Phil.,
Assistant Professor,
Department of Computer Science
Preliminaries
 Tree is a non- linear data structure.
 A Tree is a recursive data structure containing the set
of one or more data nodes where one node is
designated as the root of the tree while the remaining
nodes are called as the children of the root.
 The nodes other than the root node are partitioned
into the non empty sets where each one of them is to
be called sub-tree.
 Nodes of a tree either maintain a parent-child
relationship between them or they are sister
nodes.
 In a general tree, A node can have any number of
children nodes but it can have only a single parent.
 The following image shows a tree, where the node
A is the root node of the tree while the other nodes
can be seen as the children of A.
Tree Structure
Basic terminology
 Root Node :- The root node is the topmost node in the tree hierarchy. In
other words, the root node is the one which doesn't have any parent.
 Sub Tree :- If the root node is not null, the tree T1, T2 and T3 is called sub-
trees of the root node.
 Leaf Node :- The node of tree, which doesn't have any child node, is called
leaf node. Leaf node is the bottom most node of the tree. There can be any
number of leaf nodes present in a general tree. Leaf nodes can also be
called external nodes.
 Path :- The sequence of consecutive edges is called path. In the tree shown
in the above image, path to the node E is A→ B → E.
Tree Example
Basic terminology
Tree Example
 Ancestor node :- An ancestor of a node is any predecessor node on a path
from root to that node. The root node doesn't have any ancestors. In the
tree shown in the above image, the node F have the ancestors, B and A.
 Degree :- Degree of a node is equal to number of children, a node have. In
the tree shown in the above image, the degree of node B is 2. Degree of a
leaf node is always 0 while in a complete binary tree, degree of each node is
equal to 2.
 Level Number :- Each node of the tree is assigned a level number in such a
way that each node is present at one level higher than its parent. Root node
of the tree is always present at level 0.
NextNext1
Structure of Tree Representation
struct node
{
int root;
struct node *parent;
struct node *lchild
struct node *rchild;
}
Types of Tree
The tree data structure can be classified
into six different categories.
1.Binary tree
2.Binary search tree
3.Expression tree
Binary Tree
Binary tree is a data structure in which each
node can have at most 2 children.
The node present at the top most level is
called the root node.
A node with the 0 children is called leaf node.
Binary Trees are used in the applications like
expression evaluation and many more.
Example of Binary Tree
Binary search tree
 Binary search tree is an ordered binary tree.
 All the elements in the left sub-tree are less than the root
while elements present in the right sub-tree are greater than
or equal to the root node element.
 Binary search trees are used in most of the applications of
computer science domain like searching, sorting, etc.
Binary search tree example
Expression tree
 Expression trees are used to evaluate the simple
arithmetic expressions.
 Expression tree is basically a binary tree where
internal nodes are represented by operators while
the leaf nodes are represented by operands.
 Expression trees are widely used to solve algebraic
expressions like (a+b)*(a-b). Consider the following
example.
Construct an expression tree by using the following
algebraic expression.
(a + b) / (a*b - c) + d
Thank You.

More Related Content

What's hot (20)

Binary tree
Binary treeBinary tree
Binary tree
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
Linked List
Linked ListLinked List
Linked List
 
Insertion in singly linked list
Insertion in singly linked listInsertion in singly linked list
Insertion in singly linked list
 
Tree-In Data Structure
Tree-In Data StructureTree-In Data Structure
Tree-In Data Structure
 
Normal forms
Normal formsNormal forms
Normal forms
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
 
Relational model
Relational modelRelational model
Relational model
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 
Tree
TreeTree
Tree
 
Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.ppt
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
 

Similar to Trees in data structures

Similar to Trees in data structures (20)

Tree
TreeTree
Tree
 
UNIT-4 TREES.ppt
UNIT-4 TREES.pptUNIT-4 TREES.ppt
UNIT-4 TREES.ppt
 
Final tree.ppt tells about tree presentation
Final tree.ppt tells about tree presentationFinal tree.ppt tells about tree presentation
Final tree.ppt tells about tree presentation
 
Trees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and AlgorithmsTrees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and Algorithms
 
tree traversals.pdf
tree traversals.pdftree traversals.pdf
tree traversals.pdf
 
NON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptxNON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptx
 
Unit 5 Tree.pptx
Unit 5 Tree.pptxUnit 5 Tree.pptx
Unit 5 Tree.pptx
 
Dsc++ unit 3 notes
Dsc++ unit 3 notesDsc++ unit 3 notes
Dsc++ unit 3 notes
 
Tree Introduction.pptx
Tree Introduction.pptxTree Introduction.pptx
Tree Introduction.pptx
 
Trees
TreesTrees
Trees
 
Data structure using c module 2
Data structure using c module 2Data structure using c module 2
Data structure using c module 2
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 
Lect 21 Zaheer Abbas
Lect 21 Zaheer AbbasLect 21 Zaheer Abbas
Lect 21 Zaheer Abbas
 
Lect 19 Zaheer Abbas
Lect 19 Zaheer AbbasLect 19 Zaheer Abbas
Lect 19 Zaheer Abbas
 
07 trees
07 trees07 trees
07 trees
 
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptx
 
Binary tree in data structures
Binary tree in  data structuresBinary tree in  data structures
Binary tree in data structures
 
Introduction to tree ds
Introduction to tree dsIntroduction to tree ds
Introduction to tree ds
 
Unit 3,4.docx
Unit 3,4.docxUnit 3,4.docx
Unit 3,4.docx
 

Recently uploaded

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 

Recently uploaded (20)

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 

Trees in data structures

  • 1. Trees in Data Structure Mrs.R.Sabitha M.Sc.,M.Phil., Assistant Professor, Department of Computer Science
  • 2. Preliminaries  Tree is a non- linear data structure.  A Tree is a recursive data structure containing the set of one or more data nodes where one node is designated as the root of the tree while the remaining nodes are called as the children of the root.  The nodes other than the root node are partitioned into the non empty sets where each one of them is to be called sub-tree.
  • 3.  Nodes of a tree either maintain a parent-child relationship between them or they are sister nodes.  In a general tree, A node can have any number of children nodes but it can have only a single parent.  The following image shows a tree, where the node A is the root node of the tree while the other nodes can be seen as the children of A.
  • 5. Basic terminology  Root Node :- The root node is the topmost node in the tree hierarchy. In other words, the root node is the one which doesn't have any parent.  Sub Tree :- If the root node is not null, the tree T1, T2 and T3 is called sub- trees of the root node.  Leaf Node :- The node of tree, which doesn't have any child node, is called leaf node. Leaf node is the bottom most node of the tree. There can be any number of leaf nodes present in a general tree. Leaf nodes can also be called external nodes.  Path :- The sequence of consecutive edges is called path. In the tree shown in the above image, path to the node E is A→ B → E. Tree Example
  • 6. Basic terminology Tree Example  Ancestor node :- An ancestor of a node is any predecessor node on a path from root to that node. The root node doesn't have any ancestors. In the tree shown in the above image, the node F have the ancestors, B and A.  Degree :- Degree of a node is equal to number of children, a node have. In the tree shown in the above image, the degree of node B is 2. Degree of a leaf node is always 0 while in a complete binary tree, degree of each node is equal to 2.  Level Number :- Each node of the tree is assigned a level number in such a way that each node is present at one level higher than its parent. Root node of the tree is always present at level 0.
  • 8. Structure of Tree Representation struct node { int root; struct node *parent; struct node *lchild struct node *rchild; }
  • 9. Types of Tree The tree data structure can be classified into six different categories. 1.Binary tree 2.Binary search tree 3.Expression tree
  • 10. Binary Tree Binary tree is a data structure in which each node can have at most 2 children. The node present at the top most level is called the root node. A node with the 0 children is called leaf node. Binary Trees are used in the applications like expression evaluation and many more.
  • 12. Binary search tree  Binary search tree is an ordered binary tree.  All the elements in the left sub-tree are less than the root while elements present in the right sub-tree are greater than or equal to the root node element.  Binary search trees are used in most of the applications of computer science domain like searching, sorting, etc.
  • 14. Expression tree  Expression trees are used to evaluate the simple arithmetic expressions.  Expression tree is basically a binary tree where internal nodes are represented by operators while the leaf nodes are represented by operands.  Expression trees are widely used to solve algebraic expressions like (a+b)*(a-b). Consider the following example.
  • 15. Construct an expression tree by using the following algebraic expression. (a + b) / (a*b - c) + d