SlideShare a Scribd company logo
PRESENTED BY:
TABISH HAMID
PRIYANKA MEHTA
CONTACT NO: 08376023134
Submitted to:
MISS. RAJ BALA SIMON
TREES
SESSION OUTLINE:
• TREE
• BINARY TREE
• TREES TRAVERSAL
• BINARY SEARCH TREE
• INSERTION AND DELETION IN BINARY SEARCH TREE
• AVL TREE
TREES
• TREE DATA STRUCTURE IS MAINLY USED
TO REPRESENT DATA CONTAINING A
HIERARCHICAL RELATIONSHIP BETWEEN
ELEMENTS .
TREES
• COLLECTION OF NODESOR
FINITE SET OF NODES
• THIS COLLECTION CAN BE EMPTY.
• DEGREE OF A NODE IS NUMBER OF NODES
CONNECTED TO A PARTICULAR NODE.
TREES LEVELS
• A PATH FROM NODE N1 TO NK IS
DEFINED AS A SEQUENCE OF
NODES N1, N2, …….., NK.
• THE LENGTH OF THIS PATH IS THE
NUMBER OF EDGES ON THE PATH.
• THERE IS A PATH OF LENGTH ZERO
FROM EVERY NODE TO ITSELF.
• THERE IS EXACTLY ONE PATH
FROM THE ROOT TO EACH NODE IN
A TREE.
TREES
• HEIGHTOF A NODE IS THE LENGTH OF A
LONGEST PATH FROM THIS NODE TO A LEAF
• ALL LEAVES ARE AT HEIGHT ZERO
• HEIGHT OF A TREE IS THE HEIGHT OF ITS ROOT
(MAXIMUM LEVEL)
TREES
• DEPTHOF A NODE IS THE LENGTH OF PATH
FROM ROOT TO THIS NODE
• ROOT IS AT DEPTH ZERO
• DEPTH OF A TREE IS THE DEPTH OF ITS
DEEPEST LEAF THAT IS EQUAL TO THE
HEIGHT OF THIS TREE
TREES
BINARY TREE
Complete binary treeFull binary tree
FULL BINARY TREE
A binary tree is said to
be full if all its leaves
are at the same level
and every internal node
has two
children.
The full binary tree of
height h has
l = 2h
leaves
and
m = 2h
– 1 internal
nodes.
COMPLETE BINARY TREE
A complete binary tree is
either a full binary tree or one
that is full except for a
segment of missing leaves
on the right side of the
bottom level.
PICTURE OF A BINARY TREE
a
b c
d e
g h i
l
f
j k
TREE TRAVERSALS
• PRE-ORDER
• N L R
• IN-ORDER
• L N R
• POST-ORDER
• L R N
TREE TRAVERSALS
PRE-ORDER(NLR)
1, 3, 5, 9, 6, 8
TREE TRAVERSALS
IN-ORDER(LNR)
5, 3, 9, 1, 8, 6
TREE TRAVERSALS
POST-ORDER(LRN)
5, 9, 3, 8, 6, 1
TREE TRAVERSALS
IN-ORDER TRAVERSAL : 1,2,3,4,5,6,7,8,9
PREORDER TRAVERSAL:1,2,4,7,5,8,3,6,9
ARE GIVEN.
DRAW BINARY TREE FROM THESE TWO
TRAVERSALS?
In:4,7,2,8,5
Pre:2,4,7,5,8
In:6,9,3
Pre:3,6,9
1
7
6
1
2
5
4
8
3
9
REPRESENTATION OF BINARY TREE
i)SEQUENTIAL REPRESENTATION (ARRAYS)
ii)LINKED LIST REPRESENTATION
I) SEQUENTIAL REPRESENTATION
(ARRAYS)
REQUIRED THREE DIFFERENT ARRAYS
1.ARR (CONTAIN ITEMS OF TREE)
2.LC (REPRESENT LEFT CHILD)
3.RC (REPRESENT RIGHT CHILD)
SEQUENTIAL REPRESENTATION
(ARRAYS)
A B C D E ‘0’ F
1 3 -1 -1 -1 -1 -1
2 4 6 -1 -1 -1 -1
arr
lc
rc
LINKED LIST REPRESENTATION
IN LINKED LIST REPRESENTATION
EACH NODE HAS THREE FIELDS:-
DATA PART
ADDRESS OF THE LEFT SUBTREE.
ADDRESS OF THE RIGHT SUBTREE
EXTENDED BINARY TREE
A BINARY TREE CAN BE CONVERTED TO AN EXTENDED BINARY
TREE BY ADDING NEW NODES TO ITS LEAF NODES AND TO
THE NODES THAT HAVE ONLY ONE CHILD. THESE NEW NODES
ARE ADDED IN SUCH A WAY THAT ALL THE NODES IN
RESULTANT TREE HAVE ZERO OR TWO CHILDREN.
IT IS ALSO KNOWN AS 2-TREE.THE NODES OF THE ORIGINAL
TREE ARE CALLED INTERNAL NODES.
NEW NODES THAT ARE ADDED TO BINARY TREE ,TO MAKE IT
AN EXTENDED BINARY TREE ARE CALLED EXTERNAL NODES.
25
.
Binary Tree Extended Binary Tree
Binary Search tree
It is a tree that may be empty.
and non-empty binary Search tree satisfies the
following properties :-
(1)Every element has a key or value and no two
elements have the same key that is all keys are
unique.
(2) The keys if any in the left sub tree of the root
are smaller than the key in the node.
(3) The keys if any in the right sub tree of the root
are larger than the key in the node.
(4) Left and Right sub trees of the root are also
binary search tree.
Example of the Binary Search Tree :-
The input list is
20 17 6 8 10 7 18 13 12 5
20
17
6 18
5
8
7 10
13
12
Insertion in Binary Search Tree
Insert 53 in this binary search tree
Representation of Binary Search Tree :-
struct btreenode
{
struct btreenode *left;
int data;
struct btreenode *right;
};
Function code of Inorder :-
void inorder(struct btreenode *sr)
{
if(sr!=NULL)
{
inorder(sr->left);
printf(“%d”,sr->data);
inorder(sr->right);
}
}
Function code of Preorder :-
void preorder(struct btreenode *sr)
{
if(sr!=NULL)
{
printf(“%d”,sr->data);
preorder(sr->left);
preorder(sr->right);
}
}
Function code of Postorder :-
void postorder(struct btreenode *sr)
{
if(sr!=NULL)
{
postorder(sr->left);
postorder(sr->right);
printf(“%d”,sr->data);
}
}
Function code for Insertion of a node in
binary search tree-
void insert(struct btreenode **sr,int num)
{
if(*sr==NULL)
{
*sr=malloc (sizeof(struct btreenode))
(*sr)->left=NULL;
(*sr)->data=num;
(*sr)->right=NULL;
}
else
{
if(num<(sr)->data)
insert(&((*sr)->left),num);
else
insert(&((*sr)->right),num);
}
}
CASES FOR DELETION
• IF NODE HAS NO SPECIFIC DATA OR NO CHILD
• IF NODE HAS ONLY LEFT CHILD.
• IF NODE HAS ONLY RIGHT CHILD
• IF NODE HAS TWO CHILDREN
CASE 1
• IF NODE TO BE DELETED HAS NO CHILD
IF (( X->LEFT == NULL) && (X->RIGHT == NULL))
{
• IF ( PARENT ->RIGHT == X)
• PARENT -> RIGHT = NULL;
• ELSE
• PARENT -> LEFT = NULL;
• FREE (X);
}
X 14 200 X 15 X
X 18 X
parent
CASE 2
IF NODE TO BE DELETED HAS ONLY RIGHT CHILD
IF (( X-> LEFT==NULL) && (X-> RIGHT !=NULL))
{
• IF (PARENT -> LEFT == X)
• PARENT ->LEFT = X-> RIGHT;
• ELSE
• PARENT ->RIGHT = X-> RIGHT;
• FREE (X);
}
180 14 200 X 15 X
X 16 220 X 18 X
X 17 X
parent
X
220 14 200 X 15 X
X 18 XX 17 X
parent
CASE 3
IF NODE HAS ONLY LEFT CHILD
IF((X->LEFT!=NULL)&&(X->RIGHT==NULL))
{
IF (PARENT->LEFT==X)
PARENT->LEFT=X->LEFT;
ELSE
PARENT->RIGHT->X->LEFT;
FREE(X);
}
180 14 200 X 15 X
X 16 X
220 18 X
X 17 X
parent
X
180 14 220 X 15 X
X 16 220
X 17 X
parent
CASE 4
IF NODE TO BE DELETED HAS TWO CHILDREN
IF((X-> LEFT !=NULL) && (X-> RIGHT!=NULL))
{ PARENT = X;
XSUCC= X->RIGHT;
WHILE (XSUCC->LEFT!=NULL)
{
PARENT = XSUCC;
XSUCC =XSUCC-> LEFT;
}
X->DATA = XSUCC->DATA;
X=XSUCC }
X 15 X 180 14 200
X 16 X
240 18 220
X 17 X X 19 X
parent
X
XSUCC
X 15 X 180 17 200
X 16 X
X 18 220
X 19 X
Data Structure: TREES

More Related Content

What's hot

1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
Krish_ver2
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
Gurukul Kangri Vishwavidyalaya - Faculty of Engineering and Technology
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
Muhazzab Chouhadry
 
Trees
TreesTrees
Trees
Trees Trees
Trees
Gaditek
 
Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
Md. Israil Fakir
 
Red black tree
Red black treeRed black tree
Red black tree
Dr Sandeep Kumar Poonia
 
Binary tree traversal ppt - 02.03.2020
Binary tree traversal   ppt - 02.03.2020Binary tree traversal   ppt - 02.03.2020
Binary tree traversal ppt - 02.03.2020
V.V.Vanniapermal College for Women
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
ghhgj jhgh
 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
Adam Mukharil Bachtiar
 
Chapter 8 ds
Chapter 8 dsChapter 8 ds
Chapter 8 ds
Hanif Durad
 
Tree-In Data Structure
Tree-In Data StructureTree-In Data Structure
Tree-In Data Structure
United International University
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures tree
maamir farooq
 
Expression trees
Expression treesExpression trees
Expression trees
Salman Vadsarya
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
shameen khan
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
ManishPrajapati78
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
Zafar Ayub
 
Terminology of tree
Terminology of treeTerminology of tree
Terminology of tree
RacksaviR
 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
Then Murugeshwari
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
Anandhasilambarasan D
 

What's hot (20)

1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 
Trees
TreesTrees
Trees
 
Trees
Trees Trees
Trees
 
Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
 
Red black tree
Red black treeRed black tree
Red black tree
 
Binary tree traversal ppt - 02.03.2020
Binary tree traversal   ppt - 02.03.2020Binary tree traversal   ppt - 02.03.2020
Binary tree traversal ppt - 02.03.2020
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
 
Chapter 8 ds
Chapter 8 dsChapter 8 ds
Chapter 8 ds
 
Tree-In Data Structure
Tree-In Data StructureTree-In Data Structure
Tree-In Data Structure
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures tree
 
Expression trees
Expression treesExpression trees
Expression trees
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Terminology of tree
Terminology of treeTerminology of tree
Terminology of tree
 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 

Viewers also liked

Data structure unitfirst part1
Data structure unitfirst part1Data structure unitfirst part1
Data structure unitfirst part1
Amar Rawat
 
Entity relationship modeling
Entity relationship modelingEntity relationship modeling
Entity relationship modeling
Neelesh Shukla
 
Data mining 1
Data mining 1Data mining 1
Data mining 1
Krunal Doshi
 
datamodel_vector
datamodel_vectordatamodel_vector
datamodel_vector
Riya Gupta
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
Mahmoud Alfarra
 
Graphs data Structure
Graphs data StructureGraphs data Structure
Graphs data Structure
Mahmoud Alfarra
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
Ashim Lamichhane
 
Radix sort presentation
Radix sort presentationRadix sort presentation
Radix sort presentation
Ratul Hasan
 
Knowledgebase vs Database
Knowledgebase vs DatabaseKnowledgebase vs Database
Knowledgebase vs Database
CJ Jenkins
 
Problem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - GraphsProblem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - Graphs
Yi-Lung Tsai
 
B Trees
B TreesB Trees
Graph data structure
Graph data structureGraph data structure
Graph data structure
Tech_MX
 
Data structures
Data structuresData structures
Data structures
Manaswi Sharma
 
Dbms mca-section a
Dbms mca-section aDbms mca-section a
Dbms mca-section a
Vaibhav Kathuria
 
B tree
B treeB tree
B tree
Tech_MX
 
Radix sorting
Radix sortingRadix sorting
Radix sorting
Madhawa Gunasekara
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
Anuj Modi
 
Geometric modeling111431635 geometric-modeling-glad (1)
Geometric modeling111431635 geometric-modeling-glad (1)Geometric modeling111431635 geometric-modeling-glad (1)
Geometric modeling111431635 geometric-modeling-glad (1)
manojg1990
 
Files Vs DataBase
Files Vs DataBaseFiles Vs DataBase
Files Vs DataBase
Dr. C.V. Suresh Babu
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
Abrish06
 

Viewers also liked (20)

Data structure unitfirst part1
Data structure unitfirst part1Data structure unitfirst part1
Data structure unitfirst part1
 
Entity relationship modeling
Entity relationship modelingEntity relationship modeling
Entity relationship modeling
 
Data mining 1
Data mining 1Data mining 1
Data mining 1
 
datamodel_vector
datamodel_vectordatamodel_vector
datamodel_vector
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Graphs data Structure
Graphs data StructureGraphs data Structure
Graphs data Structure
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
Radix sort presentation
Radix sort presentationRadix sort presentation
Radix sort presentation
 
Knowledgebase vs Database
Knowledgebase vs DatabaseKnowledgebase vs Database
Knowledgebase vs Database
 
Problem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - GraphsProblem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - Graphs
 
B Trees
B TreesB Trees
B Trees
 
Graph data structure
Graph data structureGraph data structure
Graph data structure
 
Data structures
Data structuresData structures
Data structures
 
Dbms mca-section a
Dbms mca-section aDbms mca-section a
Dbms mca-section a
 
B tree
B treeB tree
B tree
 
Radix sorting
Radix sortingRadix sorting
Radix sorting
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
 
Geometric modeling111431635 geometric-modeling-glad (1)
Geometric modeling111431635 geometric-modeling-glad (1)Geometric modeling111431635 geometric-modeling-glad (1)
Geometric modeling111431635 geometric-modeling-glad (1)
 
Files Vs DataBase
Files Vs DataBaseFiles Vs DataBase
Files Vs DataBase
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 

Similar to Data Structure: TREES

BINARY SEARCH TREE
BINARY SEARCH TREEBINARY SEARCH TREE
BINARY SEARCH TREE
ER Punit Jain
 
Unit 3 dsuc
Unit 3 dsucUnit 3 dsuc
Unit 3 dsuc
Sweta Singh
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
SeethaDinesh
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
AdityaK92
 
LEC 5-DS ALGO(updated).pdf
LEC 5-DS  ALGO(updated).pdfLEC 5-DS  ALGO(updated).pdf
LEC 5-DS ALGO(updated).pdf
MuhammadUmerIhtisham
 
lecture10 date structure types of graph and terminology
lecture10 date structure types of graph and terminologylecture10 date structure types of graph and terminology
lecture10 date structure types of graph and terminology
KamranAli649587
 
tree-160731205832.pptx
tree-160731205832.pptxtree-160731205832.pptx
tree-160731205832.pptx
MouDhara1
 
Binary tree
Binary treeBinary tree
Binary tree
MKalpanaDevi
 
Algorithms summary (English version)
Algorithms summary (English version)Algorithms summary (English version)
Algorithms summary (English version)
Young-Min kang
 
DSA-Unit-2.pptx
DSA-Unit-2.pptxDSA-Unit-2.pptx
DSA-Unit-2.pptx
SeethaDinesh
 
Trees
TreesTrees
Red black trees
Red black treesRed black trees
Red black trees
TCHAYE Jude
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
Meghaj Mallick
 
Tree
TreeTree
6_1 (1).ppt
6_1 (1).ppt6_1 (1).ppt
6_1 (1).ppt
ayeshamangrio3
 
Unit 3 trees
Unit 3   treesUnit 3   trees
Unit 3 trees
LavanyaJ28
 
Tree chapter
Tree chapterTree chapter
Tree chapter
LJ Projects
 
tutorial-tree (3).ppt
tutorial-tree (3).ppttutorial-tree (3).ppt
tutorial-tree (3).ppt
SrinivasanCSE
 
Tree
TreeTree
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
Anusruti Mitra
 

Similar to Data Structure: TREES (20)

BINARY SEARCH TREE
BINARY SEARCH TREEBINARY SEARCH TREE
BINARY SEARCH TREE
 
Unit 3 dsuc
Unit 3 dsucUnit 3 dsuc
Unit 3 dsuc
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
LEC 5-DS ALGO(updated).pdf
LEC 5-DS  ALGO(updated).pdfLEC 5-DS  ALGO(updated).pdf
LEC 5-DS ALGO(updated).pdf
 
lecture10 date structure types of graph and terminology
lecture10 date structure types of graph and terminologylecture10 date structure types of graph and terminology
lecture10 date structure types of graph and terminology
 
tree-160731205832.pptx
tree-160731205832.pptxtree-160731205832.pptx
tree-160731205832.pptx
 
Binary tree
Binary treeBinary tree
Binary tree
 
Algorithms summary (English version)
Algorithms summary (English version)Algorithms summary (English version)
Algorithms summary (English version)
 
DSA-Unit-2.pptx
DSA-Unit-2.pptxDSA-Unit-2.pptx
DSA-Unit-2.pptx
 
Trees
TreesTrees
Trees
 
Red black trees
Red black treesRed black trees
Red black trees
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Tree
TreeTree
Tree
 
6_1 (1).ppt
6_1 (1).ppt6_1 (1).ppt
6_1 (1).ppt
 
Unit 3 trees
Unit 3   treesUnit 3   trees
Unit 3 trees
 
Tree chapter
Tree chapterTree chapter
Tree chapter
 
tutorial-tree (3).ppt
tutorial-tree (3).ppttutorial-tree (3).ppt
tutorial-tree (3).ppt
 
Tree
TreeTree
Tree
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 

Recently uploaded

ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
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
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
HODECEDSIET
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
mamamaam477
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball playEric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
enizeyimana36
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
rpskprasana
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 

Recently uploaded (20)

ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
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
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball playEric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 

Data Structure: TREES

  • 1. PRESENTED BY: TABISH HAMID PRIYANKA MEHTA CONTACT NO: 08376023134 Submitted to: MISS. RAJ BALA SIMON
  • 2. TREES SESSION OUTLINE: • TREE • BINARY TREE • TREES TRAVERSAL • BINARY SEARCH TREE • INSERTION AND DELETION IN BINARY SEARCH TREE • AVL TREE
  • 3. TREES • TREE DATA STRUCTURE IS MAINLY USED TO REPRESENT DATA CONTAINING A HIERARCHICAL RELATIONSHIP BETWEEN ELEMENTS .
  • 4. TREES • COLLECTION OF NODESOR FINITE SET OF NODES • THIS COLLECTION CAN BE EMPTY. • DEGREE OF A NODE IS NUMBER OF NODES CONNECTED TO A PARTICULAR NODE.
  • 6. • A PATH FROM NODE N1 TO NK IS DEFINED AS A SEQUENCE OF NODES N1, N2, …….., NK. • THE LENGTH OF THIS PATH IS THE NUMBER OF EDGES ON THE PATH. • THERE IS A PATH OF LENGTH ZERO FROM EVERY NODE TO ITSELF. • THERE IS EXACTLY ONE PATH FROM THE ROOT TO EACH NODE IN A TREE. TREES
  • 7. • HEIGHTOF A NODE IS THE LENGTH OF A LONGEST PATH FROM THIS NODE TO A LEAF • ALL LEAVES ARE AT HEIGHT ZERO • HEIGHT OF A TREE IS THE HEIGHT OF ITS ROOT (MAXIMUM LEVEL) TREES
  • 8. • DEPTHOF A NODE IS THE LENGTH OF PATH FROM ROOT TO THIS NODE • ROOT IS AT DEPTH ZERO • DEPTH OF A TREE IS THE DEPTH OF ITS DEEPEST LEAF THAT IS EQUAL TO THE HEIGHT OF THIS TREE TREES
  • 9. BINARY TREE Complete binary treeFull binary tree
  • 10. FULL BINARY TREE A binary tree is said to be full if all its leaves are at the same level and every internal node has two children. The full binary tree of height h has l = 2h leaves and m = 2h – 1 internal nodes.
  • 11. COMPLETE BINARY TREE A complete binary tree is either a full binary tree or one that is full except for a segment of missing leaves on the right side of the bottom level.
  • 12. PICTURE OF A BINARY TREE a b c d e g h i l f j k
  • 13. TREE TRAVERSALS • PRE-ORDER • N L R • IN-ORDER • L N R • POST-ORDER • L R N
  • 17. TREE TRAVERSALS IN-ORDER TRAVERSAL : 1,2,3,4,5,6,7,8,9 PREORDER TRAVERSAL:1,2,4,7,5,8,3,6,9 ARE GIVEN. DRAW BINARY TREE FROM THESE TWO TRAVERSALS?
  • 20. REPRESENTATION OF BINARY TREE i)SEQUENTIAL REPRESENTATION (ARRAYS) ii)LINKED LIST REPRESENTATION
  • 21. I) SEQUENTIAL REPRESENTATION (ARRAYS) REQUIRED THREE DIFFERENT ARRAYS 1.ARR (CONTAIN ITEMS OF TREE) 2.LC (REPRESENT LEFT CHILD) 3.RC (REPRESENT RIGHT CHILD)
  • 22. SEQUENTIAL REPRESENTATION (ARRAYS) A B C D E ‘0’ F 1 3 -1 -1 -1 -1 -1 2 4 6 -1 -1 -1 -1 arr lc rc
  • 24. IN LINKED LIST REPRESENTATION EACH NODE HAS THREE FIELDS:- DATA PART ADDRESS OF THE LEFT SUBTREE. ADDRESS OF THE RIGHT SUBTREE
  • 25. EXTENDED BINARY TREE A BINARY TREE CAN BE CONVERTED TO AN EXTENDED BINARY TREE BY ADDING NEW NODES TO ITS LEAF NODES AND TO THE NODES THAT HAVE ONLY ONE CHILD. THESE NEW NODES ARE ADDED IN SUCH A WAY THAT ALL THE NODES IN RESULTANT TREE HAVE ZERO OR TWO CHILDREN. IT IS ALSO KNOWN AS 2-TREE.THE NODES OF THE ORIGINAL TREE ARE CALLED INTERNAL NODES. NEW NODES THAT ARE ADDED TO BINARY TREE ,TO MAKE IT AN EXTENDED BINARY TREE ARE CALLED EXTERNAL NODES. 25
  • 26. . Binary Tree Extended Binary Tree
  • 27. Binary Search tree It is a tree that may be empty. and non-empty binary Search tree satisfies the following properties :- (1)Every element has a key or value and no two elements have the same key that is all keys are unique. (2) The keys if any in the left sub tree of the root are smaller than the key in the node. (3) The keys if any in the right sub tree of the root are larger than the key in the node. (4) Left and Right sub trees of the root are also binary search tree.
  • 28. Example of the Binary Search Tree :- The input list is 20 17 6 8 10 7 18 13 12 5 20 17 6 18 5 8 7 10 13 12
  • 29. Insertion in Binary Search Tree Insert 53 in this binary search tree
  • 30. Representation of Binary Search Tree :- struct btreenode { struct btreenode *left; int data; struct btreenode *right; };
  • 31. Function code of Inorder :- void inorder(struct btreenode *sr) { if(sr!=NULL) { inorder(sr->left); printf(“%d”,sr->data); inorder(sr->right); } }
  • 32. Function code of Preorder :- void preorder(struct btreenode *sr) { if(sr!=NULL) { printf(“%d”,sr->data); preorder(sr->left); preorder(sr->right); } }
  • 33. Function code of Postorder :- void postorder(struct btreenode *sr) { if(sr!=NULL) { postorder(sr->left); postorder(sr->right); printf(“%d”,sr->data); } }
  • 34. Function code for Insertion of a node in binary search tree- void insert(struct btreenode **sr,int num) { if(*sr==NULL) { *sr=malloc (sizeof(struct btreenode)) (*sr)->left=NULL; (*sr)->data=num; (*sr)->right=NULL; }
  • 36. CASES FOR DELETION • IF NODE HAS NO SPECIFIC DATA OR NO CHILD • IF NODE HAS ONLY LEFT CHILD. • IF NODE HAS ONLY RIGHT CHILD • IF NODE HAS TWO CHILDREN
  • 37. CASE 1 • IF NODE TO BE DELETED HAS NO CHILD IF (( X->LEFT == NULL) && (X->RIGHT == NULL)) { • IF ( PARENT ->RIGHT == X) • PARENT -> RIGHT = NULL; • ELSE • PARENT -> LEFT = NULL; • FREE (X); }
  • 38.
  • 39. X 14 200 X 15 X X 18 X parent
  • 40. CASE 2 IF NODE TO BE DELETED HAS ONLY RIGHT CHILD IF (( X-> LEFT==NULL) && (X-> RIGHT !=NULL)) { • IF (PARENT -> LEFT == X) • PARENT ->LEFT = X-> RIGHT; • ELSE • PARENT ->RIGHT = X-> RIGHT; • FREE (X); }
  • 41. 180 14 200 X 15 X X 16 220 X 18 X X 17 X parent X
  • 42. 220 14 200 X 15 X X 18 XX 17 X parent
  • 43. CASE 3 IF NODE HAS ONLY LEFT CHILD IF((X->LEFT!=NULL)&&(X->RIGHT==NULL)) { IF (PARENT->LEFT==X) PARENT->LEFT=X->LEFT; ELSE PARENT->RIGHT->X->LEFT; FREE(X); }
  • 44. 180 14 200 X 15 X X 16 X 220 18 X X 17 X parent X
  • 45. 180 14 220 X 15 X X 16 220 X 17 X parent
  • 46. CASE 4 IF NODE TO BE DELETED HAS TWO CHILDREN IF((X-> LEFT !=NULL) && (X-> RIGHT!=NULL)) { PARENT = X; XSUCC= X->RIGHT; WHILE (XSUCC->LEFT!=NULL) { PARENT = XSUCC; XSUCC =XSUCC-> LEFT; } X->DATA = XSUCC->DATA; X=XSUCC }
  • 47. X 15 X 180 14 200 X 16 X 240 18 220 X 17 X X 19 X parent X XSUCC
  • 48. X 15 X 180 17 200 X 16 X X 18 220 X 19 X