SlideShare a Scribd company logo
1 of 19
Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
Binary Trees
ARUN KUMAR K A
arunkumar3040@gmail.com
www.facebook.com/arunku
mar3040
twitter.com/arunkumar304
0
in.linkedin.com/in/arunkuma
r3040
+919496349799
Tree Terminology
• A tree consists of a collection of elements or
nodes, with each node linked to its successors
• The node at the top of a tree is called its root
• The links from a node to its successors are
called branches
• The successors of a node are called its children
• The predecessor of a node is called its parent
Tree Terminology (continued)
• Each node in a tree has exactly one parent
except for the root node, which has no parent
• Nodes that have the same parent are siblings
• A node that has no children is called a leaf
node
Binary Trees
•A tree in which no node can have more than
two children.
Example: Expression Trees
• Leaves are operands (constants or variables)
• The other nodes (internal nodes) contain
operators
• Will not be a binary tree if some operators are
not binary
Example: Expression Trees
Expression tree for ( a + b * c ) + ( ( d * e + f ) * g
Binary Tree Traversal
• Traversal is the process of visiting every node
once
• 3 types of traversals
*Inorder
*Preorder
*Postorder
Preorder traversal
Expression tree for ( a + b * c ) + (( d * e + f ) * g
•root, left, right
•prefix expression
++a*bc*+*defg
Inorder traversal
Expression tree for ( a + b * c ) +( ( d * e + f ) * g
• left, root, right
•infix expression
a+b*c+d*e+f*g
Postorder traversal
Expression tree for ( a + b * c ) + (( d * e + f ) * g
• left, right, root
•postfix expression
abc*+de*f+g*+
Insert
Proceed down the tree as you would find a close match
If X is found, do nothing (or update something)
Otherwise, insert X at the last spot on the path traversed
Delete
Consider children of deleted node
Property of the search tree should be maintained.
Three cases:
(1) the node is a leaf
– Delete it immediately
(2) the node has one child
– Adjust a pointer from the parent to bypass that node
Delete
(3) the node has 2 children
– replace the key of that node with the minimum element at the
right subtree
– delete the minimum element
• Has either no child or only right child because if it has a left child, that
left child would be smaller and would have been chosen. So invoke
case 1 or 2.
Questions…..
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

More Related Content

What's hot

Ch13 Binary Search Tree
Ch13 Binary Search TreeCh13 Binary Search Tree
Ch13 Binary Search Tree
leminhvuong
 

What's hot (20)

Tree
TreeTree
Tree
 
Tree
TreeTree
Tree
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures tree
 
Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
 
Unit – vi tree
Unit – vi   treeUnit – vi   tree
Unit – vi tree
 
Mca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graphMca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graph
 
Trees
TreesTrees
Trees
 
introduction to_trees
introduction to_treesintroduction to_trees
introduction to_trees
 
Red black tree
Red black treeRed black tree
Red black tree
 
Ch13 Binary Search Tree
Ch13 Binary Search TreeCh13 Binary Search Tree
Ch13 Binary Search Tree
 
Red-black trees
Red-black treesRed-black trees
Red-black trees
 
Red black tree
Red black treeRed black tree
Red black tree
 
B-Tree
B-TreeB-Tree
B-Tree
 
Binary tree
Binary treeBinary tree
Binary tree
 
Red black trees and their properties
Red black trees and their propertiesRed black trees and their properties
Red black trees and their properties
 
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
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
 
08 B Trees
08 B Trees08 B Trees
08 B Trees
 
Binary tree
Binary treeBinary tree
Binary tree
 
B trees and_b__trees
B trees and_b__treesB trees and_b__trees
B trees and_b__trees
 

Viewers also liked (7)

Form validation in jquery
Form validation in jqueryForm validation in jquery
Form validation in jquery
 
Validation
ValidationValidation
Validation
 
Layouts in android
Layouts in androidLayouts in android
Layouts in android
 
Nexus
NexusNexus
Nexus
 
DALmodule and sp transaction
DALmodule and sp transactionDALmodule and sp transaction
DALmodule and sp transaction
 
garbage collector
garbage collectorgarbage collector
garbage collector
 
Master page in ASP . NET
Master page in ASP . NETMaster page in ASP . NET
Master page in ASP . NET
 

Similar to Binary tree

TREE DATA STRUCTURE SLIDES dsa dsa .pptx
TREE DATA STRUCTURE SLIDES dsa dsa .pptxTREE DATA STRUCTURE SLIDES dsa dsa .pptx
TREE DATA STRUCTURE SLIDES dsa dsa .pptx
asimshahzad8611
 

Similar to Binary tree (20)

Tree
TreeTree
Tree
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
BINARY SEARCH TREE
BINARY SEARCH TREEBINARY SEARCH TREE
BINARY SEARCH TREE
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
 
B+tree Data structures presentation
B+tree Data structures presentationB+tree Data structures presentation
B+tree Data structures presentation
 
Binary tree
Binary tree Binary tree
Binary tree
 
Mca admission in india
Mca admission in indiaMca admission in india
Mca admission in india
 
Tree 11.ppt
Tree 11.pptTree 11.ppt
Tree 11.ppt
 
B+ trees and height balance tree
B+ trees and height balance treeB+ trees and height balance tree
B+ trees and height balance tree
 
B+ tree.pptx
B+ tree.pptxB+ tree.pptx
B+ tree.pptx
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 
Farhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructure
 
Unit 3.ppt
Unit 3.pptUnit 3.ppt
Unit 3.ppt
 
Unit 2_1 Tree.pdf
Unit 2_1 Tree.pdfUnit 2_1 Tree.pdf
Unit 2_1 Tree.pdf
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 
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
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data Structure
 
TREE DATA STRUCTURE SLIDES dsa dsa .pptx
TREE DATA STRUCTURE SLIDES dsa dsa .pptxTREE DATA STRUCTURE SLIDES dsa dsa .pptx
TREE DATA STRUCTURE SLIDES dsa dsa .pptx
 
Bca ii dfs u-3 tree and graph
Bca  ii dfs u-3 tree and graphBca  ii dfs u-3 tree and graph
Bca ii dfs u-3 tree and graph
 

More from baabtra.com - No. 1 supplier of quality freshers

More from baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Recently uploaded (20)

Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 

Binary tree

  • 1.
  • 2. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 3. Binary Trees ARUN KUMAR K A arunkumar3040@gmail.com www.facebook.com/arunku mar3040 twitter.com/arunkumar304 0 in.linkedin.com/in/arunkuma r3040 +919496349799
  • 4. Tree Terminology • A tree consists of a collection of elements or nodes, with each node linked to its successors • The node at the top of a tree is called its root • The links from a node to its successors are called branches • The successors of a node are called its children • The predecessor of a node is called its parent
  • 5. Tree Terminology (continued) • Each node in a tree has exactly one parent except for the root node, which has no parent • Nodes that have the same parent are siblings • A node that has no children is called a leaf node
  • 6. Binary Trees •A tree in which no node can have more than two children.
  • 7. Example: Expression Trees • Leaves are operands (constants or variables) • The other nodes (internal nodes) contain operators • Will not be a binary tree if some operators are not binary
  • 8. Example: Expression Trees Expression tree for ( a + b * c ) + ( ( d * e + f ) * g
  • 9. Binary Tree Traversal • Traversal is the process of visiting every node once • 3 types of traversals *Inorder *Preorder *Postorder
  • 10. Preorder traversal Expression tree for ( a + b * c ) + (( d * e + f ) * g •root, left, right •prefix expression ++a*bc*+*defg
  • 11. Inorder traversal Expression tree for ( a + b * c ) +( ( d * e + f ) * g • left, root, right •infix expression a+b*c+d*e+f*g
  • 12. Postorder traversal Expression tree for ( a + b * c ) + (( d * e + f ) * g • left, right, root •postfix expression abc*+de*f+g*+
  • 13. Insert Proceed down the tree as you would find a close match If X is found, do nothing (or update something) Otherwise, insert X at the last spot on the path traversed
  • 14. Delete Consider children of deleted node Property of the search tree should be maintained. Three cases: (1) the node is a leaf – Delete it immediately (2) the node has one child – Adjust a pointer from the parent to bypass that node
  • 15. Delete (3) the node has 2 children – replace the key of that node with the minimum element at the right subtree – delete the minimum element • Has either no child or only right child because if it has a left child, that left child would be smaller and would have been chosen. So invoke case 1 or 2.
  • 17.
  • 18. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 19. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com