SlideShare a Scribd company logo
1 of 7
Download to read offline
For More Visit: Https://www.ThesisScientist.com
Unit 5
Trees
Basic Terminology about Trees
Definition of Tree: A tree is a finite set of one or more nodes such that there is a specially designated node
called the Root and remaining nodes are partitioned into n>0 disjoint sets S1....Sn where each of these sets is
a tree. S1...Sn are called the subtrees of the root. If we look at Fig 1.1 we see that the root of the tree is Alan
. Tree has three subtrees whose roots are Joe, John and Johnson.
Node: A node stands for the item of information plus the branches to other items. Consider the Tree of
Fig 1.2 it has 13 nodes.
Degree : The number of subtrees of a node is called its degree. In Fig 1.2 the degree of node 1
is 3.
Leaf or Terminal Nodes : Nodes that have degree zero is called leaf or Terminal nodes. In Fig 1.2,
6,7,9,10,11,12,13 are 'Leaf' nodes, other nodes of Tree are called 'NonLeaf' nodes.
Children : The roots of the subtrees of a node I are called the children of node I. I is the 'parent' of its
children.
AL A N
l l l
JO E
l l l
JO H N JO H N S O N
l
PET E RM A R Y C H R ISAL E C
AL A N
l l l
JO E
l l l
JO H N JO H N S O N
l
PET E RM A R Y C H R ISAL E C
For More Visit: Https://www.ThesisScientist.com
Siblings : Children of the same parent are called 'Siblings' 8,9,10, are Siblings so as 11
and12.
Level : The 'level' of a node is defined by initially letting the root be at level 1. If a node is at level l, then
its children are at level l+1.
Height or Depth : The height or depth of a Tree is defined as the maximum level of any node in the Tree.
1
3
7
2
5
11 12
6
4
10
8 9
13
LEVEL
1
2
3
4
11
33
77
22
55
1111 1212
66
44
10
88 99
1313
LEVEL
1
2
3
4
Figure 1.2: An Example Tree
Binary Trees
A Binary Tree is a finite set of elements that is either empty or is portitioned into three disjoint subsets. The
first subset contains a single element called the Root of the tree. The other two subsets are themselves
Binary Trees, called the left and right subtrees of the original tree. A left or right subtree can be empty Fig
1.3 shows a typical Binary Tree. A node of a Binary Tree can have at most two Branches.
If A is the root of a Binary Tree and B,C are the roots of its left and right subtrees respectively then A is
said to be the father of B, C and B are called Left and Right Sons respectively. If every Non Leaf node in a
Binary Tree has Non Empty Left and Right subtrees the tree is termed as Strictly Binary Tree. The Binary
Tree of Fig 1.4 is Strictly Binary Tree. A Strictly Binary Tree with n leaves always contains 2n-1 nodes.
A Complete Binary Tree is a Strictly Binary Tree of depth 'd' whose all leaves are at level d. Fig 1.5
represents complete Binary tree.
1
2
4
8
5
3
7
6
109
11
22
44
88
55
33
7
66
101099
Figure 1.3 : A Binary Tree
For More Visit: Https://www.ThesisScientist.com
1
2 3
54
6 7
11
22 33
544
66 77
Figure 1.4 : Strictly Binary Tree
1
2
4
8
5
3
76
9 10 11 12 13 14 15
11
22
44
88
55
33
766
99 10 11 12 13 14 15
Figure 1.5 : The Complete Binary Tree
Binary Tree Traversal
The traversal of a Binary Tree is to visit each node in the tree exactly once. A full traversal produces a
linear order for the information in a tree. When traversing a binary tree we want to treat each node and its
subtrees in the same fashion. If we let L,D,R stand for moving left, printing the data, and moving right
when at a node then there are six possible combinations of traversal: LDR, LRD, DLR,DRL,RDL andRDL.
If convention is adopted then we traverse left before right then only three traversals remain i.e.
LDR,LRD,DLR. To these, the names INORDER, POSTORDER and PREORDER are assigned because
there is a natural correspondence between these traversals and producing the INFIX, POSTFIX and
PREFIX forms of an expression.
Preorder
To traverse a non empty tree in preorder we perform the following three operations:
i) Visit the root
For More Visit: Https://www.ThesisScientist.com
ii) Traverse the left Subtree in Preorder
iii) Traverse the right Subtree in Preorder.
Inorder
i) Traverse the left Subtree in Inorder
ii) Visit the root
iii) Traverse the right Subtree in Inorder.
Postorder
i) Traverse the Left Subtree in Postorder.
ii) Traverse the right Subtree in Postorder.
iii) Visit the root.
Example 1
Consider the Tree of Fig 1.6.
l In Inorder Traversal the order will be
A/B**C*D+E
which is Infix form of the expression.
l In Postorder Traversal the order will be:
ABC**/D*E+
which is postfix form of the Traversal
+
E*
DI
**A
CB
+
EE*
DDI
**A
CB
Figure 1.6: Binary Tree
l In preorder Traversal the order will be :
+*/A**BCDE
For More Visit: Https://www.ThesisScientist.com
which is the prefix form of the expression.
Implementation of Binary Trees
A node (As in Fig. 1.7) of a binary tree can be represented as:
Left Data Right
;
Figure 1.7:
Deletion from a Binary Tree
One of the important operations associated with any Data Structure is deletion of the specified data item.
Assuming that we will pass the specified data item, we wish to delete from the Binary Tree to the delete
function.
There are four possible cases:
a) No node contains the specified data
b) The node containing the data has no children
c) The node c ontaining the data has exactly one child
d) The node containing the data has two children.
In case (a) we will only need to print the message that the data item is not present in the tree.
Fig 1.9 represents the case (b). We have to delete the node containing data 4. The node is leaf node and it
has no children, it can be deleted by making its parent pointing to NULL.Which of the two links(Left or
Right) of its parent node is set to NULL depends upon whether the node being deleted is a left child or a
right child of its parent.
8
96
74
a) Before Deletion
*
8
96
7
b) After Deletion
NULL
8
96
74
a) Before Deletion
*
8
96
7
b) After Deletion
NULL
For More Visit: Https://www.ThesisScientist.com
Figure 1.9
Fig 1.10 represents case (c) in which node to be deleted has one child; we have to adjust the pointer of the
parent of the node to be deleted such that after deletion it points to the child of the node being deleted. In
Fig 1.10(a) node 1 with data 1 is to be deleted. After deletion left pointers of node 6 is made to point to
child of node 1 i.e. 4 and now structure would be as shown in
Fig 1.10(b).
8
96
7
1
a) Before Deletion
*
8
96
74
b) After Deletion
4
8
96
77
1
a) Before Deletion
*
8
96
74
b) After Deletion
4
Figure 1.10
In case (d) the value is replaced by the smallest value in the right subtree or the largest key value in the left
subtree; Subsequently empty node is deleted recursively, Fig 16.11 represents this case. If the node with
data value 6 is to be deleted then first its value is replaced by smallest value in its right subtree. Adjustment
is done for the parent of this node (with smallest value) according to case (b) or (c), then the node is
deleted.
For More Visit: Https://www.ThesisScientist.com
10
126
95
4
11
7
8
(a)
10
127
95
4
11
8
(b)
10
127
95
4
11
8
(c)
10
121266
9955
44
1111
77
88
(a)
10
121277
9955
44
1111
88
(b)
10
121277
9955
44
1111
88
(c)
Fig
ure 1.11

More Related Content

What's hot

What's hot (20)

Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Search tree,Tree and binary tree and heap tree
Search tree,Tree  and binary tree and heap treeSearch tree,Tree  and binary tree and heap tree
Search tree,Tree and binary tree and heap tree
 
Tree
TreeTree
Tree
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 
Lecture7 data structure(tree)
Lecture7 data structure(tree)Lecture7 data structure(tree)
Lecture7 data structure(tree)
 
Binary tree
Binary treeBinary tree
Binary tree
 
Binary tree and Binary search tree
Binary tree and Binary search treeBinary tree and Binary search tree
Binary tree and Binary search tree
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
 
7.tree
7.tree7.tree
7.tree
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Tree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanTree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal Khan
 
Lecture 8 data structures and algorithms
Lecture 8 data structures and algorithmsLecture 8 data structures and algorithms
Lecture 8 data structures and algorithms
 
Trees
TreesTrees
Trees
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Binary tree traversal ppt
Binary tree traversal pptBinary tree traversal ppt
Binary tree traversal ppt
 
Unit iii(dsc++)
Unit iii(dsc++)Unit iii(dsc++)
Unit iii(dsc++)
 
Binary tree
Binary tree Binary tree
Binary tree
 
Binary Search Tree and AVL
Binary Search Tree and AVLBinary Search Tree and AVL
Binary Search Tree and AVL
 

Similar to Basic Tree Terminology and Binary Tree Traversal

Similar to Basic Tree Terminology and Binary Tree Traversal (20)

Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data Structure
 
Tree
TreeTree
Tree
 
Data structures
Data structuresData structures
Data structures
 
Unit 3.ppt
Unit 3.pptUnit 3.ppt
Unit 3.ppt
 
07 trees
07 trees07 trees
07 trees
 
Unit 3 Tree chapter 5
Unit 3  Tree chapter 5Unit 3  Tree chapter 5
Unit 3 Tree chapter 5
 
Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
 
TREES.pptx
TREES.pptxTREES.pptx
TREES.pptx
 
Unit – vi tree
Unit – vi   treeUnit – vi   tree
Unit – vi tree
 
Data structure using c module 2
Data structure using c module 2Data structure using c module 2
Data structure using c module 2
 
Unit 4.1 (tree)
Unit 4.1 (tree)Unit 4.1 (tree)
Unit 4.1 (tree)
 
binary tree.pptx
binary tree.pptxbinary tree.pptx
binary 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
 
VCE Unit 05.pptx
VCE Unit 05.pptxVCE Unit 05.pptx
VCE Unit 05.pptx
 
NON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptxNON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptx
 
Trees
TreesTrees
Trees
 
Trees unit 3
Trees unit 3Trees unit 3
Trees unit 3
 
Threaded Binary Tree
Threaded Binary TreeThreaded Binary Tree
Threaded Binary Tree
 
Data Structures
Data StructuresData Structures
Data Structures
 
Difference between complete,ordered,full,strict,perfect and balanced binary tree
Difference between complete,ordered,full,strict,perfect and balanced binary treeDifference between complete,ordered,full,strict,perfect and balanced binary tree
Difference between complete,ordered,full,strict,perfect and balanced binary tree
 

More from Prof Ansari

Sci Hub New Domain
Sci Hub New DomainSci Hub New Domain
Sci Hub New DomainProf Ansari
 
Sci Hub cc Not Working
Sci Hub cc Not WorkingSci Hub cc Not Working
Sci Hub cc Not WorkingProf Ansari
 
basics of computer network
basics of computer networkbasics of computer network
basics of computer networkProf Ansari
 
JAVA INTRODUCTION
JAVA INTRODUCTIONJAVA INTRODUCTION
JAVA INTRODUCTIONProf Ansari
 
Project Evaluation and Estimation in Software Development
Project Evaluation and Estimation in Software DevelopmentProject Evaluation and Estimation in Software Development
Project Evaluation and Estimation in Software DevelopmentProf Ansari
 
Stepwise Project planning in software development
Stepwise Project planning in software developmentStepwise Project planning in software development
Stepwise Project planning in software developmentProf Ansari
 
Database and Math Relations
Database and Math RelationsDatabase and Math Relations
Database and Math RelationsProf Ansari
 
Normalisation in Database management System (DBMS)
Normalisation in Database management System (DBMS)Normalisation in Database management System (DBMS)
Normalisation in Database management System (DBMS)Prof Ansari
 
Entity-Relationship Data Model in DBMS
Entity-Relationship Data Model in DBMSEntity-Relationship Data Model in DBMS
Entity-Relationship Data Model in DBMSProf Ansari
 
A Detail Database Architecture
A Detail Database ArchitectureA Detail Database Architecture
A Detail Database ArchitectureProf Ansari
 
INTRODUCTION TO Database Management System (DBMS)
INTRODUCTION TO Database Management System (DBMS)INTRODUCTION TO Database Management System (DBMS)
INTRODUCTION TO Database Management System (DBMS)Prof Ansari
 
Master thesis on Vehicular Ad hoc Networks (VANET)
Master thesis on Vehicular Ad hoc Networks (VANET)Master thesis on Vehicular Ad hoc Networks (VANET)
Master thesis on Vehicular Ad hoc Networks (VANET)Prof Ansari
 
Master Thesis on Vehicular Ad-hoc Network (VANET)
Master Thesis on Vehicular Ad-hoc Network (VANET)Master Thesis on Vehicular Ad-hoc Network (VANET)
Master Thesis on Vehicular Ad-hoc Network (VANET)Prof Ansari
 
INTERFACING WITH INTEL 8251A (USART)
INTERFACING WITH INTEL 8251A (USART)INTERFACING WITH INTEL 8251A (USART)
INTERFACING WITH INTEL 8251A (USART)Prof Ansari
 
HOST AND NETWORK SECURITY by ThesisScientist.com
HOST AND NETWORK SECURITY by ThesisScientist.comHOST AND NETWORK SECURITY by ThesisScientist.com
HOST AND NETWORK SECURITY by ThesisScientist.comProf Ansari
 
SYSTEM NETWORK ADMINISTRATIONS GOALS and TIPS
SYSTEM NETWORK ADMINISTRATIONS GOALS and TIPSSYSTEM NETWORK ADMINISTRATIONS GOALS and TIPS
SYSTEM NETWORK ADMINISTRATIONS GOALS and TIPSProf Ansari
 
INTRODUCTION TO VISUAL BASICS
INTRODUCTION TO VISUAL BASICS INTRODUCTION TO VISUAL BASICS
INTRODUCTION TO VISUAL BASICS Prof Ansari
 
introduction to Blogging ppt
introduction to Blogging pptintroduction to Blogging ppt
introduction to Blogging pptProf Ansari
 
INTRODUCTION TO SOFTWARE ENGINEERING
INTRODUCTION TO SOFTWARE ENGINEERINGINTRODUCTION TO SOFTWARE ENGINEERING
INTRODUCTION TO SOFTWARE ENGINEERINGProf Ansari
 
Introduction to E-commerce
Introduction to E-commerceIntroduction to E-commerce
Introduction to E-commerceProf Ansari
 

More from Prof Ansari (20)

Sci Hub New Domain
Sci Hub New DomainSci Hub New Domain
Sci Hub New Domain
 
Sci Hub cc Not Working
Sci Hub cc Not WorkingSci Hub cc Not Working
Sci Hub cc Not Working
 
basics of computer network
basics of computer networkbasics of computer network
basics of computer network
 
JAVA INTRODUCTION
JAVA INTRODUCTIONJAVA INTRODUCTION
JAVA INTRODUCTION
 
Project Evaluation and Estimation in Software Development
Project Evaluation and Estimation in Software DevelopmentProject Evaluation and Estimation in Software Development
Project Evaluation and Estimation in Software Development
 
Stepwise Project planning in software development
Stepwise Project planning in software developmentStepwise Project planning in software development
Stepwise Project planning in software development
 
Database and Math Relations
Database and Math RelationsDatabase and Math Relations
Database and Math Relations
 
Normalisation in Database management System (DBMS)
Normalisation in Database management System (DBMS)Normalisation in Database management System (DBMS)
Normalisation in Database management System (DBMS)
 
Entity-Relationship Data Model in DBMS
Entity-Relationship Data Model in DBMSEntity-Relationship Data Model in DBMS
Entity-Relationship Data Model in DBMS
 
A Detail Database Architecture
A Detail Database ArchitectureA Detail Database Architecture
A Detail Database Architecture
 
INTRODUCTION TO Database Management System (DBMS)
INTRODUCTION TO Database Management System (DBMS)INTRODUCTION TO Database Management System (DBMS)
INTRODUCTION TO Database Management System (DBMS)
 
Master thesis on Vehicular Ad hoc Networks (VANET)
Master thesis on Vehicular Ad hoc Networks (VANET)Master thesis on Vehicular Ad hoc Networks (VANET)
Master thesis on Vehicular Ad hoc Networks (VANET)
 
Master Thesis on Vehicular Ad-hoc Network (VANET)
Master Thesis on Vehicular Ad-hoc Network (VANET)Master Thesis on Vehicular Ad-hoc Network (VANET)
Master Thesis on Vehicular Ad-hoc Network (VANET)
 
INTERFACING WITH INTEL 8251A (USART)
INTERFACING WITH INTEL 8251A (USART)INTERFACING WITH INTEL 8251A (USART)
INTERFACING WITH INTEL 8251A (USART)
 
HOST AND NETWORK SECURITY by ThesisScientist.com
HOST AND NETWORK SECURITY by ThesisScientist.comHOST AND NETWORK SECURITY by ThesisScientist.com
HOST AND NETWORK SECURITY by ThesisScientist.com
 
SYSTEM NETWORK ADMINISTRATIONS GOALS and TIPS
SYSTEM NETWORK ADMINISTRATIONS GOALS and TIPSSYSTEM NETWORK ADMINISTRATIONS GOALS and TIPS
SYSTEM NETWORK ADMINISTRATIONS GOALS and TIPS
 
INTRODUCTION TO VISUAL BASICS
INTRODUCTION TO VISUAL BASICS INTRODUCTION TO VISUAL BASICS
INTRODUCTION TO VISUAL BASICS
 
introduction to Blogging ppt
introduction to Blogging pptintroduction to Blogging ppt
introduction to Blogging ppt
 
INTRODUCTION TO SOFTWARE ENGINEERING
INTRODUCTION TO SOFTWARE ENGINEERINGINTRODUCTION TO SOFTWARE ENGINEERING
INTRODUCTION TO SOFTWARE ENGINEERING
 
Introduction to E-commerce
Introduction to E-commerceIntroduction to E-commerce
Introduction to E-commerce
 

Recently uploaded

UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 

Recently uploaded (20)

UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 

Basic Tree Terminology and Binary Tree Traversal

  • 1. For More Visit: Https://www.ThesisScientist.com Unit 5 Trees Basic Terminology about Trees Definition of Tree: A tree is a finite set of one or more nodes such that there is a specially designated node called the Root and remaining nodes are partitioned into n>0 disjoint sets S1....Sn where each of these sets is a tree. S1...Sn are called the subtrees of the root. If we look at Fig 1.1 we see that the root of the tree is Alan . Tree has three subtrees whose roots are Joe, John and Johnson. Node: A node stands for the item of information plus the branches to other items. Consider the Tree of Fig 1.2 it has 13 nodes. Degree : The number of subtrees of a node is called its degree. In Fig 1.2 the degree of node 1 is 3. Leaf or Terminal Nodes : Nodes that have degree zero is called leaf or Terminal nodes. In Fig 1.2, 6,7,9,10,11,12,13 are 'Leaf' nodes, other nodes of Tree are called 'NonLeaf' nodes. Children : The roots of the subtrees of a node I are called the children of node I. I is the 'parent' of its children. AL A N l l l JO E l l l JO H N JO H N S O N l PET E RM A R Y C H R ISAL E C AL A N l l l JO E l l l JO H N JO H N S O N l PET E RM A R Y C H R ISAL E C
  • 2. For More Visit: Https://www.ThesisScientist.com Siblings : Children of the same parent are called 'Siblings' 8,9,10, are Siblings so as 11 and12. Level : The 'level' of a node is defined by initially letting the root be at level 1. If a node is at level l, then its children are at level l+1. Height or Depth : The height or depth of a Tree is defined as the maximum level of any node in the Tree. 1 3 7 2 5 11 12 6 4 10 8 9 13 LEVEL 1 2 3 4 11 33 77 22 55 1111 1212 66 44 10 88 99 1313 LEVEL 1 2 3 4 Figure 1.2: An Example Tree Binary Trees A Binary Tree is a finite set of elements that is either empty or is portitioned into three disjoint subsets. The first subset contains a single element called the Root of the tree. The other two subsets are themselves Binary Trees, called the left and right subtrees of the original tree. A left or right subtree can be empty Fig 1.3 shows a typical Binary Tree. A node of a Binary Tree can have at most two Branches. If A is the root of a Binary Tree and B,C are the roots of its left and right subtrees respectively then A is said to be the father of B, C and B are called Left and Right Sons respectively. If every Non Leaf node in a Binary Tree has Non Empty Left and Right subtrees the tree is termed as Strictly Binary Tree. The Binary Tree of Fig 1.4 is Strictly Binary Tree. A Strictly Binary Tree with n leaves always contains 2n-1 nodes. A Complete Binary Tree is a Strictly Binary Tree of depth 'd' whose all leaves are at level d. Fig 1.5 represents complete Binary tree. 1 2 4 8 5 3 7 6 109 11 22 44 88 55 33 7 66 101099 Figure 1.3 : A Binary Tree
  • 3. For More Visit: Https://www.ThesisScientist.com 1 2 3 54 6 7 11 22 33 544 66 77 Figure 1.4 : Strictly Binary Tree 1 2 4 8 5 3 76 9 10 11 12 13 14 15 11 22 44 88 55 33 766 99 10 11 12 13 14 15 Figure 1.5 : The Complete Binary Tree Binary Tree Traversal The traversal of a Binary Tree is to visit each node in the tree exactly once. A full traversal produces a linear order for the information in a tree. When traversing a binary tree we want to treat each node and its subtrees in the same fashion. If we let L,D,R stand for moving left, printing the data, and moving right when at a node then there are six possible combinations of traversal: LDR, LRD, DLR,DRL,RDL andRDL. If convention is adopted then we traverse left before right then only three traversals remain i.e. LDR,LRD,DLR. To these, the names INORDER, POSTORDER and PREORDER are assigned because there is a natural correspondence between these traversals and producing the INFIX, POSTFIX and PREFIX forms of an expression. Preorder To traverse a non empty tree in preorder we perform the following three operations: i) Visit the root
  • 4. For More Visit: Https://www.ThesisScientist.com ii) Traverse the left Subtree in Preorder iii) Traverse the right Subtree in Preorder. Inorder i) Traverse the left Subtree in Inorder ii) Visit the root iii) Traverse the right Subtree in Inorder. Postorder i) Traverse the Left Subtree in Postorder. ii) Traverse the right Subtree in Postorder. iii) Visit the root. Example 1 Consider the Tree of Fig 1.6. l In Inorder Traversal the order will be A/B**C*D+E which is Infix form of the expression. l In Postorder Traversal the order will be: ABC**/D*E+ which is postfix form of the Traversal + E* DI **A CB + EE* DDI **A CB Figure 1.6: Binary Tree l In preorder Traversal the order will be : +*/A**BCDE
  • 5. For More Visit: Https://www.ThesisScientist.com which is the prefix form of the expression. Implementation of Binary Trees A node (As in Fig. 1.7) of a binary tree can be represented as: Left Data Right ; Figure 1.7: Deletion from a Binary Tree One of the important operations associated with any Data Structure is deletion of the specified data item. Assuming that we will pass the specified data item, we wish to delete from the Binary Tree to the delete function. There are four possible cases: a) No node contains the specified data b) The node containing the data has no children c) The node c ontaining the data has exactly one child d) The node containing the data has two children. In case (a) we will only need to print the message that the data item is not present in the tree. Fig 1.9 represents the case (b). We have to delete the node containing data 4. The node is leaf node and it has no children, it can be deleted by making its parent pointing to NULL.Which of the two links(Left or Right) of its parent node is set to NULL depends upon whether the node being deleted is a left child or a right child of its parent. 8 96 74 a) Before Deletion * 8 96 7 b) After Deletion NULL 8 96 74 a) Before Deletion * 8 96 7 b) After Deletion NULL
  • 6. For More Visit: Https://www.ThesisScientist.com Figure 1.9 Fig 1.10 represents case (c) in which node to be deleted has one child; we have to adjust the pointer of the parent of the node to be deleted such that after deletion it points to the child of the node being deleted. In Fig 1.10(a) node 1 with data 1 is to be deleted. After deletion left pointers of node 6 is made to point to child of node 1 i.e. 4 and now structure would be as shown in Fig 1.10(b). 8 96 7 1 a) Before Deletion * 8 96 74 b) After Deletion 4 8 96 77 1 a) Before Deletion * 8 96 74 b) After Deletion 4 Figure 1.10 In case (d) the value is replaced by the smallest value in the right subtree or the largest key value in the left subtree; Subsequently empty node is deleted recursively, Fig 16.11 represents this case. If the node with data value 6 is to be deleted then first its value is replaced by smallest value in its right subtree. Adjustment is done for the parent of this node (with smallest value) according to case (b) or (c), then the node is deleted.
  • 7. For More Visit: Https://www.ThesisScientist.com 10 126 95 4 11 7 8 (a) 10 127 95 4 11 8 (b) 10 127 95 4 11 8 (c) 10 121266 9955 44 1111 77 88 (a) 10 121277 9955 44 1111 88 (b) 10 121277 9955 44 1111 88 (c) Fig ure 1.11