SlideShare a Scribd company logo
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

Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
Äshïsh Jäïn
 
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
zia eagle
 
Tree
TreeTree
Tree
bhumish
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
Shivam Singh
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
Anusruti Mitra
 
Lecture7 data structure(tree)
Lecture7 data structure(tree)Lecture7 data structure(tree)
Binary tree and Binary search tree
Binary tree and Binary search treeBinary tree and Binary search tree
Binary tree and Binary search tree
Mayeesha Samiha
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
Meghaj Mallick
 
7.tree
7.tree7.tree
trees in data structure
trees in data structure trees in data structure
trees in data structure
shameen khan
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
Mahmoud Alfarra
 
Tree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanTree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal Khan
Daniyal Khan
 
Lecture 8 data structures and algorithms
Lecture 8 data structures and algorithmsLecture 8 data structures and algorithms
Lecture 8 data structures and algorithmsAakash deep Singhal
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
Dhrumil Panchal
 
Binary tree traversal ppt
Binary tree traversal pptBinary tree traversal ppt
Binary tree traversal ppt
PREEYANKAV
 
Unit iii(dsc++)
Unit iii(dsc++)Unit iii(dsc++)
Unit iii(dsc++)
Durga Devi
 
Binary tree
Binary tree Binary tree
Binary tree
Rajendran
 
Binary Search Tree and AVL
Binary Search Tree and AVLBinary Search Tree and AVL
Binary Search Tree and AVL
Katang Isip
 

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 Trees in Data Structure

Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data Structure
Om Prakash
 
Data structures
Data structuresData structures
Data structures
IIUI
 
07 trees
07 trees07 trees
07 trees
Rajan Gautam
 
Unit 3 Tree chapter 5
Unit 3  Tree chapter 5Unit 3  Tree chapter 5
Unit 3 Tree chapter 5
DrkhanchanaR
 
Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
Dabbal Singh Mahara
 
TREES.pptx
TREES.pptxTREES.pptx
Unit – vi tree
Unit – vi   treeUnit – vi   tree
Unit – vi tree
Tribhuvan University
 
Data structure using c module 2
Data structure using c module 2Data structure using c module 2
Data structure using c module 2
smruti sarangi
 
Unit 4.1 (tree)
Unit 4.1 (tree)Unit 4.1 (tree)
Unit 4.1 (tree)
DurgaDeviCbit
 
binary tree.pptx
binary tree.pptxbinary tree.pptx
binary tree.pptx
DhanushSrinivasulu
 
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
 
VCE Unit 05.pptx
VCE Unit 05.pptxVCE Unit 05.pptx
VCE Unit 05.pptx
skilljiolms
 
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
 
Trees
TreesTrees
Trees unit 3
Trees unit 3Trees unit 3
Trees unit 3
praveena p
 
Threaded Binary Tree
Threaded Binary TreeThreaded Binary Tree
Threaded Binary Tree
khabbab_h
 
Data Structures
Data StructuresData Structures
Data Structures
Nitesh Bichwani
 
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
Ajay Chimmani
 

Similar to Trees in Data Structure (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 Domain
Prof Ansari
 
Sci Hub cc Not Working
Sci Hub cc Not WorkingSci Hub cc Not Working
Sci Hub cc Not Working
Prof Ansari
 
basics of computer network
basics of computer networkbasics of computer network
basics of computer network
Prof Ansari
 
JAVA INTRODUCTION
JAVA INTRODUCTIONJAVA INTRODUCTION
JAVA INTRODUCTION
Prof 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 Development
Prof Ansari
 
Stepwise Project planning in software development
Stepwise Project planning in software developmentStepwise Project planning in software development
Stepwise Project planning in software development
Prof Ansari
 
Database and Math Relations
Database and Math RelationsDatabase and Math Relations
Database and Math Relations
Prof 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 DBMS
Prof Ansari
 
A Detail Database Architecture
A Detail Database ArchitectureA Detail Database Architecture
A Detail Database Architecture
Prof 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.com
Prof Ansari
 
SYSTEM NETWORK ADMINISTRATIONS GOALS and TIPS
SYSTEM NETWORK ADMINISTRATIONS GOALS and TIPSSYSTEM NETWORK ADMINISTRATIONS GOALS and TIPS
SYSTEM NETWORK ADMINISTRATIONS GOALS and TIPS
Prof 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 ppt
Prof Ansari
 
INTRODUCTION TO SOFTWARE ENGINEERING
INTRODUCTION TO SOFTWARE ENGINEERINGINTRODUCTION TO SOFTWARE ENGINEERING
INTRODUCTION TO SOFTWARE ENGINEERING
Prof Ansari
 
Introduction to E-commerce
Introduction to E-commerceIntroduction to E-commerce
Introduction to E-commerce
Prof 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

一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
ssuser7dcef0
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 

Recently uploaded (20)

一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 

Trees in Data Structure

  • 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