SlideShare a Scribd company logo
1 of 12
TREES
BINARY TREES
 A binary tree is a data structure which is defined as a collection of
elements called nodes. Every node contains a "left" pointer, a "right"
pointer, and a data element. Every binary tree has a root element pointed
by a "root" pointer. The root element is the topmost node in the tree. If
root = NULL, then it means the tree is empty.
 If the root node R is not NULL, then the two trees T1 and T2 are called
the left and right subtrees of R. if T1 is non-empty, then T1 is said to be
the left successor of R. likewise, if T2 is non-empty then, it is called the
right successor of R.
8
1
32
4
5 6 7
1
2
1
0
1
1
ROOT NODE
T2T1
9
In a binary tree every node has 0, 1 or at the
most 2 successors. A node that has no
successors or 0 successors is called the leaf
node or the terminal node.
KEY TERMS
 Sibling: If N is any node in T that has left successor S1 and right successor
S2, then N is called the parent of S1 and S2. Correspondingly, S1 and S2
are called the left child and the right child of N. Also, S1 and S2 are said to
be siblings. Every node other than the root node has a parent. In other
words, all nodes that are at the same level and share the same parent are
called siblings (brothers).
Level number: Every node in the binary tree is assigned a level number.
The root node is defined to be at level 0. The left and right child of the root
node has a level number 1. Similarly, every node is at one level higher than
its parents. So all child nodes are defined to have level number as parent’s
level number + 1.
 Degree: Degree of a node is equal to the number of children that a node
has. The degree of a leaf node is zero.
In-degree of a node is the number of edges arriving at that node. The root
node is the only node that has an in-degree equal to zero. Similarly,
Out-degree of a node is the number of edges leaving that node.
Leaf node: A leaf node has no children.
KEY TERMS contd.
Similar binary trees: Given two binary trees T and T’ are said to be similar if both
of these trees have the same structure.
A
CB
D
E
F
HG
I
J
TREE T’
TREE T”
Copies of binary trees: Two binary trees T and T’ are said to be copies if they have
similar structure and same contents at the corresponding nodes.
A
CB
D E
A
CB
D
E
TREE T’
TREE T”
KEY TERMS contd.
 Directed edge: Line drawn from a node N to any of its successor is called a
directed edge. A binary tree of n nodes have exactly n – 1 edges (because, every
node except the root node is connected to its parent via an edge).
 Path: A sequence of consecutive edges is called a path.
 Depth: The depth of a node N is given as the length of the path from the root R to
the node N. The depth of the root node is zero. The height/depth of a tree is
defined as the length of the path from the root node to the deepest node in the
tree.
A tree with only a root node has a height of zero. A binary tree of height h, has at
least h nodes and at most 2h – 1
nodes. This is because every level will have at least
one node and can have at most 2 nodes. So, if every level has two nodes then a
tree with height h will have at the most 2h – 1
nodes as at level 0, there is only one
element called the root. The height of a binary tree with n nodes is at least n and
at most log2(n+1)
 Ancestor and descendant nodes: Ancestors of a node are all the nodes along the
path from the root to that node. Similarly, descendants of a node are all the nodes
along the path from that node to the leaf node.
 Binary trees are commonly used to implement binary search trees, expression
trees, tournament trees and binary heaps.
Complete Binary Trees
 A complete binary tree is a binary tree which satisfies two properties. First, in a
complete binary tree every level, except possibly the last, is completely filled.
Second, all nodes appear as far left as possible
 In a complete binary tree Tn, there are exactly n nodes and level r of T can have at
most 2r
nodes.
 The formula to find the parent, left child and right child can be given as- if K is a
parent node, then its left child can be calculated as 2 * K and its right child can be
calculated as 2 * K + 1. For example, the children of node 4 are 8 (2*4) and 9 (2* 4 +
1). Similarly, the parent of the node K can be calculated as | K/2 |. Given the node 4,
its parent can be calculated as | 4/2 | = 2. The height of a tree Tn having exactly n
nodes is given as,
 Hn = | log2 n + 1 |
 This means, if a tree T has 10,00,000 nodes then its height is 21.
1
32
4
8
5 6
7
1310 119 12
Representation of Binary Trees
in Memory
 In computer’s memory, a binary tree can be maintained either using
a linked representation (as in case of a linked list) or using
sequential representation (as in case of single arrays).
Linked Representation of Binary TreesLinked Representation of Binary Trees
 In linked representation of binary tree, every node will have three
parts, the data element, a pointer to the left node and a pointer to
the right node. So in C, the binary tree is built with a node type
given as below.
struct node {
struct node* left;
int data;
struct node* right;
};
1
2 3
4 5 6 7
X 8 X X 9 X X 10 X X 11 X X 12 X
Sequential Representation of
Binary Trees
 Sequential representation of trees is done using single or one
dimensional array. Though, it is the simplest technique for memory
representation but it is very inefficient as it requires a lot of memory
space. A sequential binary tree follows the rules given below:
 One dimensional array called TREE, will be used.
 The root of the tree will be stored in the first location. That is,
TREE[0] will store the data of the root element.
 The children of a node K, will be stored in location (2*K) and
(2*K+1).
 The maximum size of the array TREE is given as (2d+1
-1), where d is
the depth of the tree.
 An empty tree or sub-tree is specified using NULL. If TREE[0] =
NULL, then the tree is empty.
0 20
1 15
2 35
3 12
4 17
5 21
6 39
7
8
9 16
10 18
12
13
14 36
15 45
16
17
18
3515
12
17 2
1
39
45
1
6
18
3
6
20
EXPRESSION TREES
 Binary trees are widely used to store algebraic expressions. For
example, consider the algebraic expression Exp given as,
 Exp = (a – b ) + ( c * d)
 This expression can be represented using a binary tree as shown in
figure
+
*-
a b c d
TRAVERSING OF A BINARY TREE
 Traversing a binary tree is the process of visiting each node in the tree
exactly once, in a systematic way. Unlike linear data structures in which the
elements are traversed sequentially, tree is a non-linear data structure in
which the elements can be traversed in many different ways. There are
different algorithms for tree traversals. These algorithms differ in the order in
which the nodes are visited. In this section, we will read about these
algorithms.
 Pre-order algorithm
To traverse a non-empty binary tree in preorder, the following operations are
performed recursively at each node. The algorithm starts with the root node of
the tree and continues by,
 Visiting the root node.
 Traversing the left subtree.
 Traversing the right subtree.
A
CB
D E
F
IH
GA, B, D, C, E, F, G, H and I
In-order algorithm
To traverse a non-empty binary tree in in-order, the following operations
are performed recursively at each node. The algorithm starts with the
root node of the tree and continues by,
 Traversing the left subtree.
 Visiting the root node.
 Traversing the right subtree.
Post-order algorithm
To traverse a non-empty binary tree in post-order, the following operations
are performed recursively at each node. The algorithm starts with the
root node of the tree and continues by,
 Traversing the left subtree.
 Traversing the right subtree.
 Visiting the root node.
A
CB
D E
F
IH
G
B, D, A, E, H, G, I, F AND C.
D, B, H, I, G, F, E, C and A.
Thank U

More Related Content

What's hot

non linear data structure -introduction of tree
non linear data structure -introduction of treenon linear data structure -introduction of tree
non linear data structure -introduction of tree
Siddhi Viradiya
 

What's hot (20)

non linear data structure -introduction of tree
non linear data structure -introduction of treenon linear data structure -introduction of tree
non linear data structure -introduction of tree
 
Dsc++ unit 3 notes
Dsc++ unit 3 notesDsc++ unit 3 notes
Dsc++ unit 3 notes
 
Data structure tree- advance
Data structure tree- advanceData structure tree- advance
Data structure tree- advance
 
Tree
TreeTree
Tree
 
Data structure tree - intermediate
Data structure tree - intermediateData structure tree - intermediate
Data structure tree - intermediate
 
Tree data structure
Tree data structureTree data structure
Tree data structure
 
Tree
TreeTree
Tree
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures tree
 
Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++
 
Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
 
Unit – vi tree
Unit – vi   treeUnit – vi   tree
Unit – vi tree
 
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
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
Trees - Non Linear Data Structure
Trees - Non Linear Data StructureTrees - Non Linear Data Structure
Trees - Non Linear Data Structure
 
introduction to_trees
introduction to_treesintroduction to_trees
introduction to_trees
 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
 
Data structure using c module 2
Data structure using c module 2Data structure using c module 2
Data structure using c module 2
 
Tree
TreeTree
Tree
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Trees
TreesTrees
Trees
 

Similar to Lecture 5 tree.pptx

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
 
Lecture 8 data structures and algorithms
Lecture 8 data structures and algorithmsLecture 8 data structures and algorithms
Lecture 8 data structures and algorithms
Aakash deep Singhal
 

Similar to Lecture 5 tree.pptx (20)

Trees
TreesTrees
Trees
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
 
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
 
Module - 5_Trees.pdf
Module - 5_Trees.pdfModule - 5_Trees.pdf
Module - 5_Trees.pdf
 
Tree chapter
Tree chapterTree chapter
Tree chapter
 
Unit 3.ppt
Unit 3.pptUnit 3.ppt
Unit 3.ppt
 
Binary tree
Binary  treeBinary  tree
Binary tree
 
7 chapter4 trees_binary
7 chapter4 trees_binary7 chapter4 trees_binary
7 chapter4 trees_binary
 
Unit 5 Tree.pptx
Unit 5 Tree.pptxUnit 5 Tree.pptx
Unit 5 Tree.pptx
 
7.tree
7.tree7.tree
7.tree
 
Trees
TreesTrees
Trees
 
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
 
Unit 3,4.docx
Unit 3,4.docxUnit 3,4.docx
Unit 3,4.docx
 
tree.ppt
tree.ppttree.ppt
tree.ppt
 
Lecture 8 data structures and algorithms
Lecture 8 data structures and algorithmsLecture 8 data structures and algorithms
Lecture 8 data structures and algorithms
 
Trees.pptx
Trees.pptxTrees.pptx
Trees.pptx
 
UNIT-4 TREES.ppt
UNIT-4 TREES.pptUNIT-4 TREES.ppt
UNIT-4 TREES.ppt
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 
binary tree.pptx
binary tree.pptxbinary tree.pptx
binary tree.pptx
 

More from Abirami A (12)

Lecture 3 time complexity
Lecture 3 time complexityLecture 3 time complexity
Lecture 3 time complexity
 
Lecture 2 Data Structure Introduction
Lecture 2 Data Structure IntroductionLecture 2 Data Structure Introduction
Lecture 2 Data Structure Introduction
 
Lecture 1 introduction
Lecture 1 introductionLecture 1 introduction
Lecture 1 introduction
 
Lecture 14 splay tree
Lecture 14 splay treeLecture 14 splay tree
Lecture 14 splay tree
 
Lecture 16 graphs traversal
Lecture 16 graphs traversalLecture 16 graphs traversal
Lecture 16 graphs traversal
 
Lecture 16 graph introduction
Lecture 16 graph introductionLecture 16 graph introduction
Lecture 16 graph introduction
 
Lecture 6 disjoint set
Lecture 6 disjoint setLecture 6 disjoint set
Lecture 6 disjoint set
 
Lecture 8 tree traversal
Lecture 8 tree traversalLecture 8 tree traversal
Lecture 8 tree traversal
 
Lecture 9 b tree
Lecture 9 b treeLecture 9 b tree
Lecture 9 b tree
 
Lecture 7 bst
Lecture 7 bstLecture 7 bst
Lecture 7 bst
 
Lecture 6 tree traversal
Lecture 6 tree traversalLecture 6 tree traversal
Lecture 6 tree traversal
 
Lecture 1 sorting insertion & shell sort
Lecture 1 sorting insertion & shell sortLecture 1 sorting insertion & shell sort
Lecture 1 sorting insertion & shell sort
 

Recently uploaded

Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
Health
 

Recently uploaded (20)

2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 

Lecture 5 tree.pptx

  • 2. BINARY TREES  A binary tree is a data structure which is defined as a collection of elements called nodes. Every node contains a "left" pointer, a "right" pointer, and a data element. Every binary tree has a root element pointed by a "root" pointer. The root element is the topmost node in the tree. If root = NULL, then it means the tree is empty.  If the root node R is not NULL, then the two trees T1 and T2 are called the left and right subtrees of R. if T1 is non-empty, then T1 is said to be the left successor of R. likewise, if T2 is non-empty then, it is called the right successor of R. 8 1 32 4 5 6 7 1 2 1 0 1 1 ROOT NODE T2T1 9 In a binary tree every node has 0, 1 or at the most 2 successors. A node that has no successors or 0 successors is called the leaf node or the terminal node.
  • 3. KEY TERMS  Sibling: If N is any node in T that has left successor S1 and right successor S2, then N is called the parent of S1 and S2. Correspondingly, S1 and S2 are called the left child and the right child of N. Also, S1 and S2 are said to be siblings. Every node other than the root node has a parent. In other words, all nodes that are at the same level and share the same parent are called siblings (brothers). Level number: Every node in the binary tree is assigned a level number. The root node is defined to be at level 0. The left and right child of the root node has a level number 1. Similarly, every node is at one level higher than its parents. So all child nodes are defined to have level number as parent’s level number + 1.  Degree: Degree of a node is equal to the number of children that a node has. The degree of a leaf node is zero. In-degree of a node is the number of edges arriving at that node. The root node is the only node that has an in-degree equal to zero. Similarly, Out-degree of a node is the number of edges leaving that node. Leaf node: A leaf node has no children.
  • 4. KEY TERMS contd. Similar binary trees: Given two binary trees T and T’ are said to be similar if both of these trees have the same structure. A CB D E F HG I J TREE T’ TREE T” Copies of binary trees: Two binary trees T and T’ are said to be copies if they have similar structure and same contents at the corresponding nodes. A CB D E A CB D E TREE T’ TREE T”
  • 5. KEY TERMS contd.  Directed edge: Line drawn from a node N to any of its successor is called a directed edge. A binary tree of n nodes have exactly n – 1 edges (because, every node except the root node is connected to its parent via an edge).  Path: A sequence of consecutive edges is called a path.  Depth: The depth of a node N is given as the length of the path from the root R to the node N. The depth of the root node is zero. The height/depth of a tree is defined as the length of the path from the root node to the deepest node in the tree. A tree with only a root node has a height of zero. A binary tree of height h, has at least h nodes and at most 2h – 1 nodes. This is because every level will have at least one node and can have at most 2 nodes. So, if every level has two nodes then a tree with height h will have at the most 2h – 1 nodes as at level 0, there is only one element called the root. The height of a binary tree with n nodes is at least n and at most log2(n+1)  Ancestor and descendant nodes: Ancestors of a node are all the nodes along the path from the root to that node. Similarly, descendants of a node are all the nodes along the path from that node to the leaf node.  Binary trees are commonly used to implement binary search trees, expression trees, tournament trees and binary heaps.
  • 6. Complete Binary Trees  A complete binary tree is a binary tree which satisfies two properties. First, in a complete binary tree every level, except possibly the last, is completely filled. Second, all nodes appear as far left as possible  In a complete binary tree Tn, there are exactly n nodes and level r of T can have at most 2r nodes.  The formula to find the parent, left child and right child can be given as- if K is a parent node, then its left child can be calculated as 2 * K and its right child can be calculated as 2 * K + 1. For example, the children of node 4 are 8 (2*4) and 9 (2* 4 + 1). Similarly, the parent of the node K can be calculated as | K/2 |. Given the node 4, its parent can be calculated as | 4/2 | = 2. The height of a tree Tn having exactly n nodes is given as,  Hn = | log2 n + 1 |  This means, if a tree T has 10,00,000 nodes then its height is 21. 1 32 4 8 5 6 7 1310 119 12
  • 7. Representation of Binary Trees in Memory  In computer’s memory, a binary tree can be maintained either using a linked representation (as in case of a linked list) or using sequential representation (as in case of single arrays). Linked Representation of Binary TreesLinked Representation of Binary Trees  In linked representation of binary tree, every node will have three parts, the data element, a pointer to the left node and a pointer to the right node. So in C, the binary tree is built with a node type given as below. struct node { struct node* left; int data; struct node* right; }; 1 2 3 4 5 6 7 X 8 X X 9 X X 10 X X 11 X X 12 X
  • 8. Sequential Representation of Binary Trees  Sequential representation of trees is done using single or one dimensional array. Though, it is the simplest technique for memory representation but it is very inefficient as it requires a lot of memory space. A sequential binary tree follows the rules given below:  One dimensional array called TREE, will be used.  The root of the tree will be stored in the first location. That is, TREE[0] will store the data of the root element.  The children of a node K, will be stored in location (2*K) and (2*K+1).  The maximum size of the array TREE is given as (2d+1 -1), where d is the depth of the tree.  An empty tree or sub-tree is specified using NULL. If TREE[0] = NULL, then the tree is empty. 0 20 1 15 2 35 3 12 4 17 5 21 6 39 7 8 9 16 10 18 12 13 14 36 15 45 16 17 18 3515 12 17 2 1 39 45 1 6 18 3 6 20
  • 9. EXPRESSION TREES  Binary trees are widely used to store algebraic expressions. For example, consider the algebraic expression Exp given as,  Exp = (a – b ) + ( c * d)  This expression can be represented using a binary tree as shown in figure + *- a b c d
  • 10. TRAVERSING OF A BINARY TREE  Traversing a binary tree is the process of visiting each node in the tree exactly once, in a systematic way. Unlike linear data structures in which the elements are traversed sequentially, tree is a non-linear data structure in which the elements can be traversed in many different ways. There are different algorithms for tree traversals. These algorithms differ in the order in which the nodes are visited. In this section, we will read about these algorithms.  Pre-order algorithm To traverse a non-empty binary tree in preorder, the following operations are performed recursively at each node. The algorithm starts with the root node of the tree and continues by,  Visiting the root node.  Traversing the left subtree.  Traversing the right subtree. A CB D E F IH GA, B, D, C, E, F, G, H and I
  • 11. In-order algorithm To traverse a non-empty binary tree in in-order, the following operations are performed recursively at each node. The algorithm starts with the root node of the tree and continues by,  Traversing the left subtree.  Visiting the root node.  Traversing the right subtree. Post-order algorithm To traverse a non-empty binary tree in post-order, the following operations are performed recursively at each node. The algorithm starts with the root node of the tree and continues by,  Traversing the left subtree.  Traversing the right subtree.  Visiting the root node. A CB D E F IH G B, D, A, E, H, G, I, F AND C. D, B, H, I, G, F, E, C and A.