SlideShare a Scribd company logo
1 of 30
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 Data Structures Tree Overview Terminology Definitions

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 presentationnakulvarshney371
 
Farhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana Shaikh
 
Introduction to tree ds
Introduction to tree dsIntroduction to tree ds
Introduction to tree dsViji B
 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data StructureOm Prakash
 
Discrete Mathematics Tree
Discrete Mathematics  TreeDiscrete Mathematics  Tree
Discrete Mathematics TreeMasud Parvaze
 
Data structure(Part 2)
Data structure(Part 2)Data structure(Part 2)
Data structure(Part 2)SURBHI SAROHA
 
NON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptxNON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptxRajitha Reddy Alugati
 
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.pptssuser5c874e
 
Mca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graphMca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graphRai University
 

Similar to Data Structures Tree Overview Terminology Definitions (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)
 
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
 
Mca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graphMca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graph
 

Recently uploaded

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
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
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
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
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
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
 
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
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
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
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 

Recently uploaded (20)

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
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
 
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🔝
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
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
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
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
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.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
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 

Data Structures Tree Overview Terminology Definitions

  • 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.