SlideShare a Scribd company logo
Data Structure Using C
Lecture:23,Trees: Overview of Trees, Terminology, Definitions:
Binary tree, Complete tree, Full Binary tree, Strictly Binary tree
Outline
• Overview of Trees,
• Terminology,
• Definitions:
– Binary tree,
– Complete tree,
– Binary tree,
– Strictly Binary tree
Tree
• Tree is a hierarchical data structure which
stores the information naturally in the form of
hierarchy style.
• Tree is one of the most powerful and
advanced data structures.
• It is a non-linear data structure compared to
arrays, linked lists, stack and queue.
• It represents the nodes connected by edges.
Example: The node A is the root node of the tree while the other nodes can
be seen as the children of A.
Basic terminology
Example:-
Levels of a node
• Levels of a node represents the number of
connections between the node and the
root.
• It represents generation of a node.
• If the root node is at level 0, its next node
is at level 1, its grand child is at level 2
and so on.
Example: Advantages of Tree
Note:
• If node has no children, it is
called Leaves or External Nodes.
• Nodes which are not leaves, are called Internal
Nodes. Internal nodes have at least one child.
• A tree can be empty with no nodes or a tree consists of
one node called the Root.
Height of a Node
Height of a Node: Example:-
• Height of a node is a
number of edges on
the longest path
between that node and
a leaf. Each node has
height.
Note:
• Height of a node defines the longest path
from the node to a leaf.
• Path can only be downward.
Depth of a Node: Example:-
• Depth, it is located at
top which is root level
and therefore we call
it depth of a node
Note: Depth of the
root is 0.
Static representation of tree
#define MAXNODE 500
struct treenode {
int root;
int father;
int son;
int next;
}
Dynamic representation of tree
struct treenode
{
int root;
struct treenode *father;
struct treenode *son
struct treenode *next;
}
Advantages of Tree
• Tree reflects structural relationships in the
data.
• It is used to represent hierarchies.
• It provides an efficient insertion and
searching operations.
• Trees are flexible. It allows to move
subtrees around with minimum effort.
Types of Tree
• The tree data structure can be classified
into six different categories.
General Tree
• General Tree stores the elements in a
hierarchical order in which the top level
element is always present at level 0 as the
root element.
• All the nodes except the root node are present
at number of levels.
• The nodes which are present on the same
level are called siblings while the nodes
which are present on the different levels
exhibit the parent-child relationship among
them.
Forests
• Forest can be defined as the set of
disjoint trees which can be obtained
by deleting the root node and the
edges which connects root node to
the first level node.
Example:-
Example:-
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.
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.
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).
Q. Construct an expression tree by using the following algebraic expression.
(a + b) / (a*b - c) + d
Tournament Tree
• Tournament tree are used to record the winner
of the match in each round being played
between two players.
• Tournament tree can also be called as
selection tree or winner tree.
• External nodes represent the players among
which a match is being played while the
internal nodes represent the winner of the
match played.
• At the top most level, the winner of the
tournament is present as the root node of the
tree.
Example:-
Complete Tree
Example:-
• A Binary Tree is said to be
a complete binary tree if all
of the leaves are located at
the same level d. A
complete binary tree is a
binary tree that contains
exactly 2^l nodes at each
level between level 0 and d.
The total number of nodes
in a complete binary tree
with depth d is 2d+1-1 where
leaf nodes are 2d while non-
leaf nodes are 2d-1.
Full Binary tree Example:-
• A full binary tree
(sometimes proper
binary tree or 2-tree)
is a tree in which
every node other
than the leaves has
two children.
Strictly Binary tree
Example:-
• In Strictly Binary Tree,
every non-leaf node
contain non-empty left
and right sub-trees. In
other words, the degree
of every non-leaf node
will always be 2. A
strictly binary tree with
n leaves, will have (2n
- 1) nodes.

More Related Content

Similar to Tree Introduction.pptx

Unit 5 Tree.pptx
Unit 5 Tree.pptxUnit 5 Tree.pptx
Unit 5 Tree.pptx
SurajSharma266169
 
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
nakulvarshney371
 
Farhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructure
Farhana Shaikh
 
UNIT-4 TREES.ppt
UNIT-4 TREES.pptUNIT-4 TREES.ppt
UNIT-4 TREES.ppt
SIVAKUMARM603675
 
Unit 3,4.docx
Unit 3,4.docxUnit 3,4.docx
Unit 3,4.docx
Revathiparamanathan
 
Introduction to tree ds
Introduction to tree dsIntroduction to tree ds
Introduction to tree ds
Viji B
 
Tree
TreeTree
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data Structure
Om Prakash
 
Unit 3 trees
Unit 3   treesUnit 3   trees
Unit 3 trees
LavanyaJ28
 
Discrete Mathematics Tree
Discrete Mathematics  TreeDiscrete Mathematics  Tree
Discrete Mathematics Tree
Masud Parvaze
 
Data structure(Part 2)
Data structure(Part 2)Data structure(Part 2)
Data structure(Part 2)
SURBHI SAROHA
 
DSA IV Unit.pptx
DSA IV Unit.pptxDSA IV Unit.pptx
DSA IV Unit.pptx
AyeshaTakreem1
 
Unit 4.1 (tree)
Unit 4.1 (tree)Unit 4.1 (tree)
Unit 4.1 (tree)
DurgaDeviCbit
 
Tree-introduction ,Definition, Types of BT
Tree-introduction ,Definition, Types of BTTree-introduction ,Definition, Types of BT
Tree-introduction ,Definition, Types of BT
VikasNirgude2
 
NON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptxNON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptx
Rajitha Reddy Alugati
 
Binary tree
Binary treeBinary tree
Binary tree
Rajendran
 
DSA-Unit-2.pptx
DSA-Unit-2.pptxDSA-Unit-2.pptx
DSA-Unit-2.pptx
SeethaDinesh
 
Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
Dabbal Singh Mahara
 
data_structures_and_applications_-_module-4.ppt
data_structures_and_applications_-_module-4.pptdata_structures_and_applications_-_module-4.ppt
data_structures_and_applications_-_module-4.ppt
ssuser5c874e
 

Similar to Tree Introduction.pptx (20)

Unit 5 Tree.pptx
Unit 5 Tree.pptxUnit 5 Tree.pptx
Unit 5 Tree.pptx
 
Tree 11.ppt
Tree 11.pptTree 11.ppt
Tree 11.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
 
Farhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructure
 
UNIT-4 TREES.ppt
UNIT-4 TREES.pptUNIT-4 TREES.ppt
UNIT-4 TREES.ppt
 
Unit 3,4.docx
Unit 3,4.docxUnit 3,4.docx
Unit 3,4.docx
 
Introduction to tree ds
Introduction to tree dsIntroduction to tree ds
Introduction to tree ds
 
Tree
TreeTree
Tree
 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data Structure
 
Unit 3 trees
Unit 3   treesUnit 3   trees
Unit 3 trees
 
Discrete Mathematics Tree
Discrete Mathematics  TreeDiscrete Mathematics  Tree
Discrete Mathematics Tree
 
Data structure(Part 2)
Data structure(Part 2)Data structure(Part 2)
Data structure(Part 2)
 
DSA IV Unit.pptx
DSA IV Unit.pptxDSA IV Unit.pptx
DSA IV Unit.pptx
 
Unit 4.1 (tree)
Unit 4.1 (tree)Unit 4.1 (tree)
Unit 4.1 (tree)
 
Tree-introduction ,Definition, Types of BT
Tree-introduction ,Definition, Types of BTTree-introduction ,Definition, Types of BT
Tree-introduction ,Definition, Types of BT
 
NON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptxNON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptx
 
Binary tree
Binary treeBinary tree
Binary tree
 
DSA-Unit-2.pptx
DSA-Unit-2.pptxDSA-Unit-2.pptx
DSA-Unit-2.pptx
 
Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
 
data_structures_and_applications_-_module-4.ppt
data_structures_and_applications_-_module-4.pptdata_structures_and_applications_-_module-4.ppt
data_structures_and_applications_-_module-4.ppt
 

Recently uploaded

Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 

Recently uploaded (20)

Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 

Tree Introduction.pptx

  • 1. Data Structure Using C Lecture:23,Trees: Overview of Trees, Terminology, Definitions: Binary tree, Complete tree, Full Binary tree, Strictly Binary tree
  • 2. Outline • Overview of Trees, • Terminology, • Definitions: – Binary tree, – Complete tree, – Binary tree, – Strictly Binary tree
  • 3. Tree • Tree is a hierarchical data structure which stores the information naturally in the form of hierarchy style. • Tree is one of the most powerful and advanced data structures. • It is a non-linear data structure compared to arrays, linked lists, stack and queue. • It represents the nodes connected by edges.
  • 4. Example: The node A is the root node of the tree while the other nodes can be seen as the children of A.
  • 7. Levels of a node • Levels of a node represents the number of connections between the node and the root. • It represents generation of a node. • If the root node is at level 0, its next node is at level 1, its grand child is at level 2 and so on.
  • 9. Note: • If node has no children, it is called Leaves or External Nodes. • Nodes which are not leaves, are called Internal Nodes. Internal nodes have at least one child. • A tree can be empty with no nodes or a tree consists of one node called the Root.
  • 10. Height of a Node Height of a Node: Example:- • Height of a node is a number of edges on the longest path between that node and a leaf. Each node has height.
  • 11. Note: • Height of a node defines the longest path from the node to a leaf. • Path can only be downward.
  • 12. Depth of a Node: Example:- • Depth, it is located at top which is root level and therefore we call it depth of a node Note: Depth of the root is 0.
  • 13. Static representation of tree #define MAXNODE 500 struct treenode { int root; int father; int son; int next; }
  • 14. Dynamic representation of tree struct treenode { int root; struct treenode *father; struct treenode *son struct treenode *next; }
  • 15. Advantages of Tree • Tree reflects structural relationships in the data. • It is used to represent hierarchies. • It provides an efficient insertion and searching operations. • Trees are flexible. It allows to move subtrees around with minimum effort.
  • 16. Types of Tree • The tree data structure can be classified into six different categories.
  • 17.
  • 18. General Tree • General Tree stores the elements in a hierarchical order in which the top level element is always present at level 0 as the root element. • All the nodes except the root node are present at number of levels. • The nodes which are present on the same level are called siblings while the nodes which are present on the different levels exhibit the parent-child relationship among them.
  • 19. Forests • Forest can be defined as the set of disjoint trees which can be obtained by deleting the root node and the edges which connects root node to the first level node.
  • 22. 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.
  • 23. 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.
  • 24. 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).
  • 25. Q. Construct an expression tree by using the following algebraic expression. (a + b) / (a*b - c) + d
  • 26. Tournament Tree • Tournament tree are used to record the winner of the match in each round being played between two players. • Tournament tree can also be called as selection tree or winner tree. • External nodes represent the players among which a match is being played while the internal nodes represent the winner of the match played. • At the top most level, the winner of the tournament is present as the root node of the tree.
  • 28. Complete Tree Example:- • A Binary Tree is said to be a complete binary tree if all of the leaves are located at the same level d. A complete binary tree is a binary tree that contains exactly 2^l nodes at each level between level 0 and d. The total number of nodes in a complete binary tree with depth d is 2d+1-1 where leaf nodes are 2d while non- leaf nodes are 2d-1.
  • 29. Full Binary tree Example:- • A full binary tree (sometimes proper binary tree or 2-tree) is a tree in which every node other than the leaves has two children.
  • 30. Strictly Binary tree Example:- • In Strictly Binary Tree, every non-leaf node contain non-empty left and right sub-trees. In other words, the degree of every non-leaf node will always be 2. A strictly binary tree with n leaves, will have (2n - 1) nodes.