SlideShare a Scribd company logo
TREE
leaves
branches
root
roo
t
nodes
leav
es
branch
es
 Connected graph.Connected graph.
 Acyclic graph.
 A finite non-empty set of elements.
 CConsisting of nodes with a parent-child
relation.
Introduction of a Tree
B C
FD E G
A
Family Structures of a Tree
 Root-node without parent (A)
 Siblings-nodes share the same parent.
Internal node-node with at least one child (A, B, C, E)
External node (leaf): node without children (D,F,G, H, I)
Ancestors of a node: parent, grandparent, grand-grandparent,
etc.
Descendant of a node: child, grandchild, grand-grandchild, etc.
Depth of a node: number of ancestors
Height of a tree: maximum depth of any node (3)
Degree of a node: the number of its children
Degree of a tree: the maximum number of its node.
 Subtree: tree consisting of a node and its descendants
Left Child Right Sibling
Representation
Data
Left Child Right
Sibling
A
B C D
IHGFE
J K L
 Preorder Sequence.
 Inorder Sequence.
 Postorder Sequence.
 Level order Sequence
Tree Traversal Technique
Tree Traversal Technique
Preorder Inorder Postorder Level order
Tree Traversal Technique
(CONT.)
Preorder Sequence:
 Visits the nodes of a tree in a systematic manner
 A node is visited before its descendants
 Application: print a structured document
Algorithm:
void preorder(node *root){
if(root!=NULL){
printf(“%c”,root->data);
if(root->left!=NULL)
preorder(root->left);
if(root->right!=NULL)
preorder(root->right);
}
}
Inorder Sequence:
 A node is visited after its left subtree and before its right sub
tree
Algorithm :
void inorder(node *root){
if(root!=NULL){
if(root->left!=NULL)
inorder(root->left);
printf(“%c”,root->data);
if(root->right!=NULL)
inorder(root->right);
}
}
Postorder Sequence:
 A node is visited after its descendants
 Application: compute space used by files in a directory
and its subdirectories
Algorithm :
void postorder(node *root){
if(root!=NULL){
if(root->left!=NULL)
postorder(root->left);
if(root->right!=NULL)
postorder(root->right);
printf(“%c”,root->data);
}
}
Level order Sequence:
 A node is traversed in a level by level
order.
Algorithm :
Queue<-root
while Queue !=Empty
v<-Queue
visit v
Visited Sequence<-v
if left(v) !=NULL then
Queue<-left(v)
if right(v) !=NULL then
Queue<-right(v)
endwhile
return Visited Sequence
 Each internal node has at most two children
(degree of two)
 The children of a node are an ordered pair
Alternative Recursive Defintion:
 A tree consisting of a single node, or
 A tree whose root has an ordered pair of children.
Applications:
 Arithmetic expressions.
 Decisions process searching.
 Searching.
A
B C
F GD E
H I
Strict Binary Tree:
 Each node exactly having two or zero child.
Full Binary Tree:
 Each node exactly having two node or zero child
and leaf node at the same level.
Complete Binary Tree:
 All leaf node is at the same height.
 No missing node in the sequence.
Strict Binary Tree
Full Binary Tree
A
B C
GE
I
D
H
F
Complete Binary Tree
A
B C
GF
Basic Operations:
 Inserting an element into tree.
 Deleting an element from tree.
 Searching for an element.
 Traversing the tree.
Auxiliary Operations:
 Finding size of tree.
 Calculating height of tree.
 Expressions trees are used in compiler.
 Huffman coding trees which are used in data compression
technique.
 Binary Search Tree (BST) supports insertion & deletion of node
with o(log n)
 Priority queue supports search and deletion of min or max on a
collection of items in a logarithmic times.
Method 1:
 height=max(level(i))
Method 2:
 height= log2(n)
Method 3:
 height(T)=max(height(Tl),height(Tr))+1
Algorithm :
int height(node *root){
if(root==NULL)
return -1;
else if(root->left==NULL && root->right==NULL)
return 0;
else
return max(height(root->left),height(root->right))+1;
}
Int max(int x,int y){
if(x>y)
return x;
else
return y;
}
https://en.wikipedia.org/wiki/Tree_%28data_stru cture%29
 http://www.slideshare.net/samsumitgupta/trees-data-structure
 http://www.i-programmer.info/babbages-bag/477-trees.html
 https://www.cse.iitb.ac.in/~cs101/pdfs/Trees.ppt
Tree of Data Structure
Tree of Data Structure
Tree of Data Structure

More Related Content

What's hot

Data structure tree- advance
Data structure tree- advanceData structure tree- advance
Data structure tree- advance
MD. MARUFUZZAMAN .
 
Tree(Data Structure)
Tree(Data Structure)Tree(Data Structure)
Tree(Data Structure)
FariaFerdowsy
 
Data structure tree - beginner
Data structure tree - beginnerData structure tree - beginner
Data structure tree - beginner
MD. MARUFUZZAMAN .
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
Dhrumil Panchal
 
Chapter 8 ds
Chapter 8 dsChapter 8 ds
Chapter 8 ds
Hanif Durad
 
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
 
Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
Dabbal Singh Mahara
 
Trees in data structures
Trees in data structuresTrees in data structures
Trees in data structures
ASairamSairam1
 
Trees - Data structures in C/Java
Trees - Data structures in C/JavaTrees - Data structures in C/Java
Trees - Data structures in C/Javageeksrik
 
Trees
TreesTrees
Unit – vi tree
Unit – vi   treeUnit – vi   tree
Unit – vi tree
Tribhuvan University
 
Threaded binarytree&heapsort
Threaded binarytree&heapsortThreaded binarytree&heapsort
Threaded binarytree&heapsortSsankett Negi
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures tree
maamir farooq
 
Trees
TreesTrees
introduction to_trees
introduction to_treesintroduction to_trees
introduction to_trees
Danish Aakash
 
Threaded Binary Tree
Threaded Binary TreeThreaded Binary Tree
Threaded Binary Tree
khabbab_h
 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary Tree
ManishPrajapati78
 
Dsc++ unit 3 notes
Dsc++ unit 3 notesDsc++ unit 3 notes
Dsc++ unit 3 notes
Guru Nanak Institute Of Tech
 
Full threded binary tree
Full threded binary treeFull threded binary tree
Full threded binary tree
Soham Kansodaria
 

What's hot (20)

Data structure tree- advance
Data structure tree- advanceData structure tree- advance
Data structure tree- advance
 
Tree(Data Structure)
Tree(Data Structure)Tree(Data Structure)
Tree(Data Structure)
 
Data structure tree - beginner
Data structure tree - beginnerData structure tree - beginner
Data structure tree - beginner
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Chapter 8 ds
Chapter 8 dsChapter 8 ds
Chapter 8 ds
 
Lecture 8 data structures and algorithms
Lecture 8 data structures and algorithmsLecture 8 data structures and algorithms
Lecture 8 data structures and algorithms
 
Binary tree
Binary treeBinary tree
Binary tree
 
Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
 
Trees in data structures
Trees in data structuresTrees in data structures
Trees in data structures
 
Trees - Data structures in C/Java
Trees - Data structures in C/JavaTrees - Data structures in C/Java
Trees - Data structures in C/Java
 
Trees
TreesTrees
Trees
 
Unit – vi tree
Unit – vi   treeUnit – vi   tree
Unit – vi tree
 
Threaded binarytree&heapsort
Threaded binarytree&heapsortThreaded binarytree&heapsort
Threaded binarytree&heapsort
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures tree
 
Trees
TreesTrees
Trees
 
introduction to_trees
introduction to_treesintroduction to_trees
introduction to_trees
 
Threaded Binary Tree
Threaded Binary TreeThreaded Binary Tree
Threaded Binary Tree
 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary Tree
 
Dsc++ unit 3 notes
Dsc++ unit 3 notesDsc++ unit 3 notes
Dsc++ unit 3 notes
 
Full threded binary tree
Full threded binary treeFull threded binary tree
Full threded binary tree
 

Similar to Tree of Data Structure

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
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
shameen khan
 
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
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
 
07 trees
07 trees07 trees
07 trees
Rajan Gautam
 
VCE Unit 05.pptx
VCE Unit 05.pptxVCE Unit 05.pptx
VCE Unit 05.pptx
skilljiolms
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
worldchannel
 
tree traversals.pdf
tree traversals.pdftree traversals.pdf
tree traversals.pdf
MaryJacob24
 
binary tree.pptx
binary tree.pptxbinary tree.pptx
binary tree.pptx
DhanushSrinivasulu
 
Lecture 21_Trees - I.pptx
Lecture 21_Trees - I.pptxLecture 21_Trees - I.pptx
Lecture 21_Trees - I.pptx
fizzaahmed9
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
Muhazzab Chouhadry
 
heap sort
 heap sort heap sort
heap sort
Anaya Zafar
 
unit 4 for trees data structure notes it is
unit 4 for trees data structure notes it isunit 4 for trees data structure notes it is
unit 4 for trees data structure notes it is
logesswarisrinivasan
 
TREE in Data Structures
TREE in Data StructuresTREE in Data Structures
TREE in Data Structures
NARESH GUMMAGUTTA
 
Graph and tree
Graph and treeGraph and tree
Graph and tree
Inamul Hossain Imran
 
Trees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and AlgorithmsTrees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and Algorithms
BHARATH KUMAR
 
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptx
Abirami A
 
discrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptxdiscrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptx
ansariparveen06
 

Similar to Tree of Data Structure (20)

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
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
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
 
Data structure using c module 2
Data structure using c module 2Data structure using c module 2
Data structure using c module 2
 
07 trees
07 trees07 trees
07 trees
 
VCE Unit 05.pptx
VCE Unit 05.pptxVCE Unit 05.pptx
VCE Unit 05.pptx
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
 
tree traversals.pdf
tree traversals.pdftree traversals.pdf
tree traversals.pdf
 
binary tree.pptx
binary tree.pptxbinary tree.pptx
binary tree.pptx
 
Unit 3.ppt
Unit 3.pptUnit 3.ppt
Unit 3.ppt
 
Lecture 21_Trees - I.pptx
Lecture 21_Trees - I.pptxLecture 21_Trees - I.pptx
Lecture 21_Trees - I.pptx
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 
heap sort
 heap sort heap sort
heap sort
 
unit 4 for trees data structure notes it is
unit 4 for trees data structure notes it isunit 4 for trees data structure notes it is
unit 4 for trees data structure notes it is
 
TREE in Data Structures
TREE in Data StructuresTREE in Data Structures
TREE in Data Structures
 
Graph and tree
Graph and treeGraph and tree
Graph and tree
 
Trees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and AlgorithmsTrees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and Algorithms
 
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptx
 
discrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptxdiscrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptx
 

More from B.Sc in CSE, United International University - UIU, Dhaka

Electronics project
Electronics projectElectronics project
Leisure Life E-Commerce Bookstore
Leisure Life E-Commerce BookstoreLeisure Life E-Commerce Bookstore
Project Management Tool & Technique of Online Bookstore
Project Management Tool & Technique of Online BookstoreProject Management Tool & Technique of Online Bookstore
Project Management Tool & Technique of Online Bookstore
B.Sc in CSE, United International University - UIU, Dhaka
 
Balanced Tree(AVL Tree,Red Black Tree)
Balanced Tree(AVL Tree,Red Black Tree)Balanced Tree(AVL Tree,Red Black Tree)
Balanced Tree(AVL Tree,Red Black Tree)
B.Sc in CSE, United International University - UIU, Dhaka
 
Red Black Tree
Red Black TreeRed Black Tree
Karnaugh Graph or K-Map
Karnaugh Graph or K-MapKarnaugh Graph or K-Map

More from B.Sc in CSE, United International University - UIU, Dhaka (8)

Electronics project
Electronics projectElectronics project
Electronics project
 
Leisure Life E-Commerce Bookstore
Leisure Life E-Commerce BookstoreLeisure Life E-Commerce Bookstore
Leisure Life E-Commerce Bookstore
 
Project Management Tool & Technique of Online Bookstore
Project Management Tool & Technique of Online BookstoreProject Management Tool & Technique of Online Bookstore
Project Management Tool & Technique of Online Bookstore
 
Balanced Tree(AVL Tree,Red Black Tree)
Balanced Tree(AVL Tree,Red Black Tree)Balanced Tree(AVL Tree,Red Black Tree)
Balanced Tree(AVL Tree,Red Black Tree)
 
Red Black Tree
Red Black TreeRed Black Tree
Red Black Tree
 
Sudoku
SudokuSudoku
Sudoku
 
Karnaugh Graph or K-Map
Karnaugh Graph or K-MapKarnaugh Graph or K-Map
Karnaugh Graph or K-Map
 
Bermuda Triangle
Bermuda TriangleBermuda Triangle
Bermuda Triangle
 

Recently uploaded

A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 

Recently uploaded (20)

A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 

Tree of Data Structure

  • 1.
  • 5.  Connected graph.Connected graph.  Acyclic graph.  A finite non-empty set of elements.  CConsisting of nodes with a parent-child relation. Introduction of a Tree B C FD E G A
  • 6. Family Structures of a Tree  Root-node without parent (A)  Siblings-nodes share the same parent. Internal node-node with at least one child (A, B, C, E) External node (leaf): node without children (D,F,G, H, I) Ancestors of a node: parent, grandparent, grand-grandparent, etc. Descendant of a node: child, grandchild, grand-grandchild, etc. Depth of a node: number of ancestors Height of a tree: maximum depth of any node (3) Degree of a node: the number of its children Degree of a tree: the maximum number of its node.  Subtree: tree consisting of a node and its descendants
  • 7.
  • 8. Left Child Right Sibling Representation Data Left Child Right Sibling A B C D IHGFE J K L
  • 9.  Preorder Sequence.  Inorder Sequence.  Postorder Sequence.  Level order Sequence Tree Traversal Technique Tree Traversal Technique Preorder Inorder Postorder Level order
  • 10. Tree Traversal Technique (CONT.) Preorder Sequence:  Visits the nodes of a tree in a systematic manner  A node is visited before its descendants  Application: print a structured document Algorithm: void preorder(node *root){ if(root!=NULL){ printf(“%c”,root->data); if(root->left!=NULL) preorder(root->left); if(root->right!=NULL) preorder(root->right); } }
  • 11.
  • 12. Inorder Sequence:  A node is visited after its left subtree and before its right sub tree Algorithm : void inorder(node *root){ if(root!=NULL){ if(root->left!=NULL) inorder(root->left); printf(“%c”,root->data); if(root->right!=NULL) inorder(root->right); } }
  • 13.
  • 14. Postorder Sequence:  A node is visited after its descendants  Application: compute space used by files in a directory and its subdirectories Algorithm : void postorder(node *root){ if(root!=NULL){ if(root->left!=NULL) postorder(root->left); if(root->right!=NULL) postorder(root->right); printf(“%c”,root->data); } }
  • 15.
  • 16. Level order Sequence:  A node is traversed in a level by level order. Algorithm : Queue<-root while Queue !=Empty v<-Queue visit v Visited Sequence<-v if left(v) !=NULL then Queue<-left(v) if right(v) !=NULL then Queue<-right(v) endwhile return Visited Sequence
  • 17.
  • 18.  Each internal node has at most two children (degree of two)  The children of a node are an ordered pair Alternative Recursive Defintion:  A tree consisting of a single node, or  A tree whose root has an ordered pair of children. Applications:  Arithmetic expressions.  Decisions process searching.  Searching. A B C F GD E H I
  • 19. Strict Binary Tree:  Each node exactly having two or zero child. Full Binary Tree:  Each node exactly having two node or zero child and leaf node at the same level. Complete Binary Tree:  All leaf node is at the same height.  No missing node in the sequence.
  • 20. Strict Binary Tree Full Binary Tree A B C GE I D H F Complete Binary Tree A B C GF
  • 21. Basic Operations:  Inserting an element into tree.  Deleting an element from tree.  Searching for an element.  Traversing the tree. Auxiliary Operations:  Finding size of tree.  Calculating height of tree.
  • 22.  Expressions trees are used in compiler.  Huffman coding trees which are used in data compression technique.  Binary Search Tree (BST) supports insertion & deletion of node with o(log n)  Priority queue supports search and deletion of min or max on a collection of items in a logarithmic times.
  • 23. Method 1:  height=max(level(i)) Method 2:  height= log2(n) Method 3:  height(T)=max(height(Tl),height(Tr))+1
  • 24. Algorithm : int height(node *root){ if(root==NULL) return -1; else if(root->left==NULL && root->right==NULL) return 0; else return max(height(root->left),height(root->right))+1; } Int max(int x,int y){ if(x>y) return x; else return y; }
  • 25. https://en.wikipedia.org/wiki/Tree_%28data_stru cture%29  http://www.slideshare.net/samsumitgupta/trees-data-structure  http://www.i-programmer.info/babbages-bag/477-trees.html  https://www.cse.iitb.ac.in/~cs101/pdfs/Trees.ppt