SlideShare a Scribd company logo
1 of 23
BINARY TREE
BINARY TREE 
• A binary tree is a special form of tree in which a 
node can have atmost two children 
• A node in a binary tree may not necessarily have 
the maximum of two children i.e either 1,2 or 0 
child. 
• A tree which does not contain any node is called 
empty binary node.
Binary Tree 
Full binary tree Complete binary tree
Full Binary Tree 
A binary tree is said to be full binary tree 
if each node has exactly zero or two 
children. 
Also known as proper binary tree
Complete Binary Tree 
A complete binary tree is either a full 
binary tree or one in which every level is 
fully occupied except possibly for the 
bottomost level where all the nodes 
must be as far left as possible.
PROPERTIES OF BINARY TREE 
• 1.The maximum number of nodes in a binary tree 
on a given level (say L) is 2L a,where L>=0 . 
• 2.The maximum number of nodes in an binary tree 
with height h is 2h+1-1 
• 3.the minimum number of nodes possible in a 
binary tree of height h is h+1
• 4.if n is the number of nodes and e is the number of 
edges in an non-empty binary tree then n=e+1. 
• 5.if n0 is the number of leaf nodes (no child) and n2 is 
the number of nodes with two children in a non-empty 
binary tree then n0= n2+1 
• 6.for a complete binary tree T with n nodes ,the 
height is floor[log2(n+1) -1]
Binary Tree Traversal Techniques 
• Three recursive techniques for binary tree 
traversal 
• In each technique, the left subtree is traversed 
recursively, the right subtree is traversed 
recursively, and the root is visited 
• What distinguishes the techniques from one 
another is the order of those 3 tasks 
8
Preoder, Inorder, Postorder 
• In Preorder, the root 
is visited before (pre) 
the subtrees traversals 
• In Inorder, the root is 
visited in-between left 
and right subtree traversal 
• In Preorder, the root 
is visited after (pre) 
the subtrees traversals 
9 
Preorder Traversal: 
1. Visit the root 
2. Traverse left subtree 
3. Traverse right subtree 
Inorder Traversal: 
1. Traverse left subtree 
2. Visit the root 
3. Traverse right subtree 
Postorder Traversal: 
1. Traverse left subtree 
2. Traverse right subtree 
3. Visit the root
Illustrations for Traversals 
1 
• Assume: visiting a node 
is printing its label 
3 
7 
• Preorder: 
5 
8 9 
1 3 5 4 6 7 8 9 10 11 12 
10 
4 6 
• Inorder: 
11 
12 
4 5 6 3 1 8 7 9 11 10 12 
• Postorder: 
4 6 5 3 8 11 12 10 8 9 7 1 10
Illustrations for Traversals (Contd.) 
• Assume: visiting a node 
15 
8 
20 
is printing its data 
• Preorder: 15 8 2 6 3 7 
2 
11 
27 
11 10 12 14 20 27 22 30 
6 
10 
12 
22 30 
• Inorder: 3 6 7 2 8 10 11 
3 7 
14 
12 14 15 20 22 27 30 
• Postorder: 3 7 6 2 10 14 
12 11 8 22 30 27 20 15 11
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
PRE-ORDER USING STACK 
• PREORD(INFO,LEFT,RIGHT,ROOT): A binary tree 
T is in memory .The algorithm does a 
preorder traversal of T, applying an 
operation PROCESS to each of its node. An 
array STACK is used to temporarily hold the 
addresses of nodes.
• 1.[Initiaaly push NULL onto STACK and initialize 
PTR] 
Set TOP1.STACK[1]NULL and PTRROOT 
2.Repeat steps 3 to 5 while PTR!=NULL 
3.Apply PROCESS to INFO[PTR] 
4.[Right Child?] 
If RIGHT[PTR]!=NULL [Push on STACK] 
TOPTOP+1 
STACK[TOP]RIGHT[PTR] 
[End of if structure]
• 5.[Left Child ?] 
If LEFT[PTR]!=NULL, 
Set PTRLEFT[PTR] 
Else [pop from stack] 
PTRSTACK[TOP] 
TOPTOP-1 
[End of if strucutre] 
[End of step 2 loop] 
6.Exit
IN-ORDER 
• INORDER(INFO,LEFT,RIGHT,ROOT):A binary tree is 
in memory. This algorithm does an inorder traversal 
.applying PROCESS to each of its node.An array 
STACK is used to temporarily hold the addresses of 
node.
1.[Push NULL onto STACK and initialize PTR] 
TOP1,STACK[1]NULL and PTRROOT 
2.Repeat while PTR!=NULL [Push left most path onto 
stack] 
a)TOPTOP+1 and STACK[TOP]PTR [Saves 
nodes] 
b)PTRLEFT[PTR] [updates PTR] 
[End of loop] 
3.PTRSTACK[TOP] 
TOPTOP-1 [pops node from STACK]
4.Repeat steps 5 to 7 while PTR!=NULL [Backtracking] 
5.Apply PROCESS to INFO[PTR] 
6.[Right child?] 
If RIGHT[PTR]!=NULL 
a)PTRRIGHT[PTR] 
b)GOTO step 2 
7.PTRSTACK[TOP] 
TOP=TOP-1 [Pops node] 
[end of step 4 loop] 
8.Exit
POSTORDER 
• POSTORD(INFO,LEFT,RIGHT,ROOT):A binary 
tree T is in memory.This algorithm does a 
postorder traversal of T,applying an 
operation PROCESS to each of its node.An 
array STACK is used to temporarily hold the 
address of nodes
1.[push NULL onto STACK and initialize PTR] 
Set TOP1,STACK[1]NULL,PTRROOT 
2.[Push left-most path onto STACK] 
Repeat steps 3 to 5 while(PTR!=NULL) 
3.TOPTOP+1 
STACK[TOP]PTR [ Pushes PTR on STACK] 
4.if RIGHT[PTR]!=NULL, then [Push on STACK] 
TOPTOP+1 and STACK[TOP]=-RIGHT[PTR]. 
[end of If strucutre]
Set PTRLEFT[PTR] [Updates pointer PTR] 
[End of Step 2 loop] 
6.Set PTRSTACK[TOP] and TOPTOP-1 [Pops node from STACK] 
7.Repeat while PTR>0. 
A)Apply PROCESS to INFO[PTR] 
B)Set PTRSTACK[TOP] and TOPTOP-1 [pops node from 
STACK] 
8.If PTR<0 ,then: 
a)PTR-PTR 
b)Goto step 2. 
[End of If structure] 
9.EXIT

More Related Content

What's hot

Bubble Sort Algorithm Presentation
Bubble Sort Algorithm Presentation Bubble Sort Algorithm Presentation
Bubble Sort Algorithm Presentation AhmedAlbutty
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search treeKrish_ver2
 
Bubble sort | Data structure |
Bubble sort | Data structure |Bubble sort | Data structure |
Bubble sort | Data structure |MdSaiful14
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structureMAHALAKSHMI P
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search TreeAbhishek L.R
 
Trees data structure
Trees data structureTrees data structure
Trees data structureSumit Gupta
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data StructuresSHAKOOR AB
 
3.6 radix sort
3.6 radix sort3.6 radix sort
3.6 radix sortKrish_ver2
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structureschauhankapil
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)Trupti Agrawal
 
Red black tree in data structure
Red black tree in data structureRed black tree in data structure
Red black tree in data structureVrushali Dhanokar
 
Tree_Definition.pptx
Tree_Definition.pptxTree_Definition.pptx
Tree_Definition.pptxsandeep54552
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structureVardhil Patel
 
Double Linked List (Algorithm)
Double Linked List (Algorithm)Double Linked List (Algorithm)
Double Linked List (Algorithm)Huba Akhtar
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSGokul Hari
 

What's hot (20)

Bubble Sort Algorithm Presentation
Bubble Sort Algorithm Presentation Bubble Sort Algorithm Presentation
Bubble Sort Algorithm Presentation
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Bubble sort | Data structure |
Bubble sort | Data structure |Bubble sort | Data structure |
Bubble sort | Data structure |
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
 
3.6 radix sort
3.6 radix sort3.6 radix sort
3.6 radix sort
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
Binary tree
Binary  treeBinary  tree
Binary tree
 
Red black tree in data structure
Red black tree in data structureRed black tree in data structure
Red black tree in data structure
 
Tree_Definition.pptx
Tree_Definition.pptxTree_Definition.pptx
Tree_Definition.pptx
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structure
 
Leftist heap
Leftist heapLeftist heap
Leftist heap
 
Double Linked List (Algorithm)
Double Linked List (Algorithm)Double Linked List (Algorithm)
Double Linked List (Algorithm)
 
Linked list
Linked listLinked list
Linked list
 
Heap sort
Heap sortHeap sort
Heap sort
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 

Viewers also liked

Viewers also liked (18)

Tree and binary tree
Tree and binary treeTree and binary tree
Tree and binary tree
 
computer notes - Traversal of a binary tree
computer notes - Traversal of a binary treecomputer notes - Traversal of a binary tree
computer notes - Traversal of a binary tree
 
Binary tree
Binary tree Binary tree
Binary tree
 
Binary trees
Binary treesBinary trees
Binary trees
 
Altar de Muertos
Altar de Muertos Altar de Muertos
Altar de Muertos
 
Cse Binary tree presentation
Cse Binary tree presentationCse Binary tree presentation
Cse Binary tree presentation
 
Binary tree and Binary search tree
Binary tree and Binary search treeBinary tree and Binary search tree
Binary tree and Binary search tree
 
6. binary tree
6. binary tree6. binary tree
6. binary tree
 
Graph representation
Graph representationGraph representation
Graph representation
 
Traversals | Data Structures
Traversals | Data StructuresTraversals | Data Structures
Traversals | Data Structures
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 
Ch13 Binary Search Tree
Ch13 Binary Search TreeCh13 Binary Search Tree
Ch13 Binary Search Tree
 
Binomial heap presentation
Binomial heap presentationBinomial heap presentation
Binomial heap presentation
 
(Binary tree)
(Binary tree)(Binary tree)
(Binary tree)
 
Trees - Data structures in C/Java
Trees - Data structures in C/JavaTrees - Data structures in C/Java
Trees - Data structures in C/Java
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Binary tree
Binary treeBinary tree
Binary tree
 

Similar to binary tree

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 terminologyKamranAli649587
 
Data structures and Algorithm analysis_Lecture4.pptx
Data structures and Algorithm analysis_Lecture4.pptxData structures and Algorithm analysis_Lecture4.pptx
Data structures and Algorithm analysis_Lecture4.pptxAhmedEldesoky24
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search TreeAdityaK92
 
tree-160731205832.pptx
tree-160731205832.pptxtree-160731205832.pptx
tree-160731205832.pptxMouDhara1
 
tutorial-tree (3).ppt
tutorial-tree (3).ppttutorial-tree (3).ppt
tutorial-tree (3).pptSrinivasanCSE
 
PVEB Tree.pptx
PVEB Tree.pptxPVEB Tree.pptx
PVEB Tree.pptxSanthosh A
 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeManishPrajapati78
 
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10sumitbardhan
 
4a searching-more
4a searching-more4a searching-more
4a searching-moreShahzad Ali
 
data_structures_and_applications_-_module-4.ppt
data_structures_and_applications_-_module-4.pptdata_structures_and_applications_-_module-4.ppt
data_structures_and_applications_-_module-4.pptssuser5c874e
 
ds 10-Binary Tree.ppt
ds 10-Binary Tree.pptds 10-Binary Tree.ppt
ds 10-Binary Tree.pptkhitishlpu
 
part4-trees.ppt
part4-trees.pptpart4-trees.ppt
part4-trees.pptSuneel61
 

Similar to binary tree (20)

Trees
TreesTrees
Trees
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
 
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
 
Data structures and Algorithm analysis_Lecture4.pptx
Data structures and Algorithm analysis_Lecture4.pptxData structures and Algorithm analysis_Lecture4.pptx
Data structures and Algorithm analysis_Lecture4.pptx
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
tree-160731205832.pptx
tree-160731205832.pptxtree-160731205832.pptx
tree-160731205832.pptx
 
tree.ppt
tree.ppttree.ppt
tree.ppt
 
BINARY SEARCH TREE
BINARY SEARCH TREEBINARY SEARCH TREE
BINARY SEARCH TREE
 
tutorial-tree (3).ppt
tutorial-tree (3).ppttutorial-tree (3).ppt
tutorial-tree (3).ppt
 
Binary tree
Binary treeBinary tree
Binary tree
 
PVEB Tree.pptx
PVEB Tree.pptxPVEB Tree.pptx
PVEB Tree.pptx
 
7.tree
7.tree7.tree
7.tree
 
Unit 4 tree
Unit 4   treeUnit 4   tree
Unit 4 tree
 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary Tree
 
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10
 
4a searching-more
4a searching-more4a searching-more
4a searching-more
 
data_structures_and_applications_-_module-4.ppt
data_structures_and_applications_-_module-4.pptdata_structures_and_applications_-_module-4.ppt
data_structures_and_applications_-_module-4.ppt
 
ds 10-Binary Tree.ppt
ds 10-Binary Tree.pptds 10-Binary Tree.ppt
ds 10-Binary Tree.ppt
 
part4-trees.ppt
part4-trees.pptpart4-trees.ppt
part4-trees.ppt
 
Module - 5_Trees.pdf
Module - 5_Trees.pdfModule - 5_Trees.pdf
Module - 5_Trees.pdf
 

Recently uploaded

Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Piping Basic stress analysis by engineering
Piping Basic stress analysis by engineeringPiping Basic stress analysis by engineering
Piping Basic stress analysis by engineeringJuanCarlosMorales19600
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction managementMariconPadriquez1
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 

Recently uploaded (20)

Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Piping Basic stress analysis by engineering
Piping Basic stress analysis by engineeringPiping Basic stress analysis by engineering
Piping Basic stress analysis by engineering
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction management
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 

binary tree

  • 2. BINARY TREE • A binary tree is a special form of tree in which a node can have atmost two children • A node in a binary tree may not necessarily have the maximum of two children i.e either 1,2 or 0 child. • A tree which does not contain any node is called empty binary node.
  • 3. Binary Tree Full binary tree Complete binary tree
  • 4. Full Binary Tree A binary tree is said to be full binary tree if each node has exactly zero or two children. Also known as proper binary tree
  • 5. Complete Binary Tree A complete binary tree is either a full binary tree or one in which every level is fully occupied except possibly for the bottomost level where all the nodes must be as far left as possible.
  • 6. PROPERTIES OF BINARY TREE • 1.The maximum number of nodes in a binary tree on a given level (say L) is 2L a,where L>=0 . • 2.The maximum number of nodes in an binary tree with height h is 2h+1-1 • 3.the minimum number of nodes possible in a binary tree of height h is h+1
  • 7. • 4.if n is the number of nodes and e is the number of edges in an non-empty binary tree then n=e+1. • 5.if n0 is the number of leaf nodes (no child) and n2 is the number of nodes with two children in a non-empty binary tree then n0= n2+1 • 6.for a complete binary tree T with n nodes ,the height is floor[log2(n+1) -1]
  • 8. Binary Tree Traversal Techniques • Three recursive techniques for binary tree traversal • In each technique, the left subtree is traversed recursively, the right subtree is traversed recursively, and the root is visited • What distinguishes the techniques from one another is the order of those 3 tasks 8
  • 9. Preoder, Inorder, Postorder • In Preorder, the root is visited before (pre) the subtrees traversals • In Inorder, the root is visited in-between left and right subtree traversal • In Preorder, the root is visited after (pre) the subtrees traversals 9 Preorder Traversal: 1. Visit the root 2. Traverse left subtree 3. Traverse right subtree Inorder Traversal: 1. Traverse left subtree 2. Visit the root 3. Traverse right subtree Postorder Traversal: 1. Traverse left subtree 2. Traverse right subtree 3. Visit the root
  • 10. Illustrations for Traversals 1 • Assume: visiting a node is printing its label 3 7 • Preorder: 5 8 9 1 3 5 4 6 7 8 9 10 11 12 10 4 6 • Inorder: 11 12 4 5 6 3 1 8 7 9 11 10 12 • Postorder: 4 6 5 3 8 11 12 10 8 9 7 1 10
  • 11. Illustrations for Traversals (Contd.) • Assume: visiting a node 15 8 20 is printing its data • Preorder: 15 8 2 6 3 7 2 11 27 11 10 12 14 20 27 22 30 6 10 12 22 30 • Inorder: 3 6 7 2 8 10 11 3 7 14 12 14 15 20 22 27 30 • Postorder: 3 7 6 2 10 14 12 11 8 22 30 27 20 15 11
  • 12. Tree Traversals Pre-Order(NLR) 1, 3, 5, 9, 6, 8
  • 13. Tree Traversals In-Order(LNR) 5, 3, 9, 1, 8, 6
  • 15. PRE-ORDER USING STACK • PREORD(INFO,LEFT,RIGHT,ROOT): A binary tree T is in memory .The algorithm does a preorder traversal of T, applying an operation PROCESS to each of its node. An array STACK is used to temporarily hold the addresses of nodes.
  • 16. • 1.[Initiaaly push NULL onto STACK and initialize PTR] Set TOP1.STACK[1]NULL and PTRROOT 2.Repeat steps 3 to 5 while PTR!=NULL 3.Apply PROCESS to INFO[PTR] 4.[Right Child?] If RIGHT[PTR]!=NULL [Push on STACK] TOPTOP+1 STACK[TOP]RIGHT[PTR] [End of if structure]
  • 17. • 5.[Left Child ?] If LEFT[PTR]!=NULL, Set PTRLEFT[PTR] Else [pop from stack] PTRSTACK[TOP] TOPTOP-1 [End of if strucutre] [End of step 2 loop] 6.Exit
  • 18. IN-ORDER • INORDER(INFO,LEFT,RIGHT,ROOT):A binary tree is in memory. This algorithm does an inorder traversal .applying PROCESS to each of its node.An array STACK is used to temporarily hold the addresses of node.
  • 19. 1.[Push NULL onto STACK and initialize PTR] TOP1,STACK[1]NULL and PTRROOT 2.Repeat while PTR!=NULL [Push left most path onto stack] a)TOPTOP+1 and STACK[TOP]PTR [Saves nodes] b)PTRLEFT[PTR] [updates PTR] [End of loop] 3.PTRSTACK[TOP] TOPTOP-1 [pops node from STACK]
  • 20. 4.Repeat steps 5 to 7 while PTR!=NULL [Backtracking] 5.Apply PROCESS to INFO[PTR] 6.[Right child?] If RIGHT[PTR]!=NULL a)PTRRIGHT[PTR] b)GOTO step 2 7.PTRSTACK[TOP] TOP=TOP-1 [Pops node] [end of step 4 loop] 8.Exit
  • 21. POSTORDER • POSTORD(INFO,LEFT,RIGHT,ROOT):A binary tree T is in memory.This algorithm does a postorder traversal of T,applying an operation PROCESS to each of its node.An array STACK is used to temporarily hold the address of nodes
  • 22. 1.[push NULL onto STACK and initialize PTR] Set TOP1,STACK[1]NULL,PTRROOT 2.[Push left-most path onto STACK] Repeat steps 3 to 5 while(PTR!=NULL) 3.TOPTOP+1 STACK[TOP]PTR [ Pushes PTR on STACK] 4.if RIGHT[PTR]!=NULL, then [Push on STACK] TOPTOP+1 and STACK[TOP]=-RIGHT[PTR]. [end of If strucutre]
  • 23. Set PTRLEFT[PTR] [Updates pointer PTR] [End of Step 2 loop] 6.Set PTRSTACK[TOP] and TOPTOP-1 [Pops node from STACK] 7.Repeat while PTR>0. A)Apply PROCESS to INFO[PTR] B)Set PTRSTACK[TOP] and TOPTOP-1 [pops node from STACK] 8.If PTR<0 ,then: a)PTR-PTR b)Goto step 2. [End of If structure] 9.EXIT