SlideShare a Scribd company logo
1 of 23
PRESENTED BY:
MEGHAJ KUMAR MALLICK
MCA 1ST YEAR ,2ND SEMESTER
(MCA/25017/18)
Binarytree
Binary tree
A binary tree is simply a tree in which each node can have at
most two children. It may be 0, 1 or 2.
Root node
left sub tree
Right sub tree
Binary Tree
Binary Tree
A
B
G
C
D E F
Left Child Right Child
Root
Parent
Left
subtree
CONTINUED
Left Child: The node on the left of any node is called left child.
Right child: The node on the right of any node is called right
child.
Left Sub tree: sub tree attached to left side of root node is called
left sub tree.
Right Sub tree: sub tree attached to right side of root node is
called right sub tree.
The node of a binary tree is divided into three parts :
Left childAddress Left Info Right Right child Address
Linked Representation
Ptr -> Info = Data
Ptr -> Left = Left Child
Ptr -> Right = Right Child
A
B C
11
32
D E
54
F G
76
Left Info Right
Binary tree Representation using Linked List
y
From General Tree
Binary Tree
(Linked List)
A
B
D
E F
C
I G
H
Head
Binary Tree
A
B
H
CD
E F
GI
Types of Binary Tree
Full Binary Tree Complete Binary Tree
A
B
G
C
D E F
A
B C
D E
• All nodes (except leaf)
have two children.
• Each subtree has same
length of path.
• All nodes (except leaf)
have two children.
• Each subtree can has
different length of path.
Binary search tree
A binary Search Tree is special kind if tree that
satisfied the following conditions
• If value of inserted node is bigger than parent
then it will be right subtree.
• If value of inserted node is smaller than parent
then it will be left subtree.
• This tree is known as binary search tree or
ordered binary tree.
• It used for searching
Construction of binary Search Tree (BST)
1. Construction of binary Search Tree (BST)
Step.1: Initially tree is empty ,place the first element at the root.
Step.2: Compare the next element with root
if element is grater than or equal to root then place it in
right child position.
else
place it in the left child position.
Step.3: Repeat the process (step 2) for the next element until
end of elements or nodes.
ALGORITHM FOR SEARCHING IN BST
Algorithm :
Search BST(key,targetkey)
1) START
2) If root==NULL
3) Return value not found
4) End if
5) If(target key<root)
6) Return searchBST (leftsubtree, targetkey)
7) else if(targetkey > root)
8) Return searchBST (rightsubtree, targetkey)
9) ELSE
10)FOUND target key
11)Return root
12)End if
13)End SearchBST
Example of searching in BST
5220 35
12
E.g. if we have to search 12 than go to left sub
tree
23
18 44
Binary SEARCHTREE(INSERTION)
• For insert data in
binary tree two conditions we have
to faced
1. IF tree is empty than insert to a new node make them root node.
2. If tree is not empty than all inserts take place at a leaf or at a
• leaf like node (a tree that has only one NULL subtree
Example of insertion in BST
23
4418
5220 35
12
23
4418
5220 35
12
Before insertion
19
After insertion
Binary SEARCHTREE(INSERTION)
Algorithm
1. START
2. If root==NULL
3. Root=newnode
4. If (newnode<root)
5. Return addBST(leftsubtree,newnode)
6. ELSE
7. Return addBST(rightsubtree,newnode)
8. End if
9. End addBST
 Traversal of a binary tree is to accessevery node of binary
tree at most once
• Tree traversal ways
a) Pre 0rder
b) In Order
c) Post Order
BST Traversal
1. start
2. Visit root
3. Visit left sub-tree
4. Visit right sub-tree
5. stop
5
2 1
3 8
97
5 2 1 3 7 9 8
Preorder
start
Left sub
tree
Right sub
tree
1. Visit left sub-tree
2. Visit root
3. Visit right sub-tree
5
2
2 1 3 5 7 9 8
Inorder
1
3 8
97
Right sub
tree
1. Visit left sub-tree
2. Visit right sub-tree
3. Visit root
5
2 1
3 8
97
2 1 3 7 9 8 5
Postorder
start
When we delete a node, we need to consider
how we take care of the children of thedeleted
node.
DELETE NODE
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 Cont…..
3)the node has 2 children
 replace the key of that node with the
minimum element at the right sub tree
 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 1or 2.
Binary tree Applications
 File System(storing naturally hierarchical
data)
 Organize data(searching,insertion,deletion
Binary search tree used for this purpose
 Telephone dictionary
 Arithmetic operations
 Network routing etc
Binary Tree in Data Structure

More Related Content

What's hot (20)

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 tree Binary tree
Binary tree
 
Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Linked List
Linked ListLinked List
Linked List
 
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
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Threaded Binary Tree.pptx
Threaded Binary Tree.pptxThreaded Binary Tree.pptx
Threaded Binary Tree.pptx
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
single linked list
single linked listsingle linked list
single linked list
 
Double Linked List (Algorithm)
Double Linked List (Algorithm)Double Linked List (Algorithm)
Double Linked List (Algorithm)
 
Tree
TreeTree
Tree
 
Linked list
Linked listLinked list
Linked list
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Threaded Binary Tree
Threaded Binary TreeThreaded Binary Tree
Threaded Binary Tree
 
Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.ppt
 

Similar to Binary Tree in Data Structure

Similar to Binary Tree in Data Structure (20)

Binary tree
Binary treeBinary tree
Binary tree
 
Lecture 7-BinarySearchTrees.ppt
Lecture 7-BinarySearchTrees.pptLecture 7-BinarySearchTrees.ppt
Lecture 7-BinarySearchTrees.ppt
 
Tree
TreeTree
Tree
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 
Binary Tree - Algorithms
Binary Tree - Algorithms Binary Tree - Algorithms
Binary Tree - Algorithms
 
Materi Searching
Materi Searching Materi Searching
Materi Searching
 
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
 
Unit iv data structure-converted
Unit  iv data structure-convertedUnit  iv data structure-converted
Unit iv data structure-converted
 
Binary search trees (1)
Binary search trees (1)Binary search trees (1)
Binary search trees (1)
 
VCE Unit 05.pptx
VCE Unit 05.pptxVCE Unit 05.pptx
VCE Unit 05.pptx
 
Binary tree
Binary treeBinary tree
Binary tree
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
DAA PPT.pptx
DAA PPT.pptxDAA PPT.pptx
DAA PPT.pptx
 
Biary search Tree.docx
Biary search Tree.docxBiary search Tree.docx
Biary search Tree.docx
 
Binary search tree
Binary search treeBinary search tree
Binary search tree
 
L 17 ct1120
L 17 ct1120L 17 ct1120
L 17 ct1120
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
presentation on b tress. heap trees.hashing
presentation on b tress. heap trees.hashingpresentation on b tress. heap trees.hashing
presentation on b tress. heap trees.hashing
 
Trees
TreesTrees
Trees
 
Lecture_10 - Revised.pptx
Lecture_10 - Revised.pptxLecture_10 - Revised.pptx
Lecture_10 - Revised.pptx
 

More from Meghaj Mallick

PORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSSPORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSSMeghaj Mallick
 
Introduction to Software Testing
Introduction to Software TestingIntroduction to Software Testing
Introduction to Software TestingMeghaj Mallick
 
Introduction to System Programming
Introduction to System ProgrammingIntroduction to System Programming
Introduction to System ProgrammingMeghaj Mallick
 
Icons, Image & Multimedia
Icons, Image & MultimediaIcons, Image & Multimedia
Icons, Image & MultimediaMeghaj Mallick
 
Project Tracking & SPC
Project Tracking & SPCProject Tracking & SPC
Project Tracking & SPCMeghaj Mallick
 
Architecture and security in Vanet PPT
Architecture and security in Vanet PPTArchitecture and security in Vanet PPT
Architecture and security in Vanet PPTMeghaj Mallick
 
Design Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software EngineeringDesign Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software EngineeringMeghaj Mallick
 
Text Mining of Twitter in Data Mining
Text Mining of Twitter in Data MiningText Mining of Twitter in Data Mining
Text Mining of Twitter in Data MiningMeghaj Mallick
 
DFS & BFS in Computer Algorithm
DFS & BFS in Computer AlgorithmDFS & BFS in Computer Algorithm
DFS & BFS in Computer AlgorithmMeghaj Mallick
 
Software Development Method
Software Development MethodSoftware Development Method
Software Development MethodMeghaj Mallick
 
Secant method in Numerical & Statistical Method
Secant method in Numerical & Statistical MethodSecant method in Numerical & Statistical Method
Secant method in Numerical & Statistical MethodMeghaj Mallick
 
Motivation in Organization
Motivation in OrganizationMotivation in Organization
Motivation in OrganizationMeghaj Mallick
 
Partial-Orderings in Discrete Mathematics
 Partial-Orderings in Discrete Mathematics Partial-Orderings in Discrete Mathematics
Partial-Orderings in Discrete MathematicsMeghaj Mallick
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure Meghaj Mallick
 

More from Meghaj Mallick (20)

24 partial-orderings
24 partial-orderings24 partial-orderings
24 partial-orderings
 
PORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSSPORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSS
 
Introduction to Software Testing
Introduction to Software TestingIntroduction to Software Testing
Introduction to Software Testing
 
Introduction to System Programming
Introduction to System ProgrammingIntroduction to System Programming
Introduction to System Programming
 
MACRO ASSEBLER
MACRO ASSEBLERMACRO ASSEBLER
MACRO ASSEBLER
 
Icons, Image & Multimedia
Icons, Image & MultimediaIcons, Image & Multimedia
Icons, Image & Multimedia
 
Project Tracking & SPC
Project Tracking & SPCProject Tracking & SPC
Project Tracking & SPC
 
Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
 
Routing in MANET
Routing in MANETRouting in MANET
Routing in MANET
 
Macro assembler
 Macro assembler Macro assembler
Macro assembler
 
Architecture and security in Vanet PPT
Architecture and security in Vanet PPTArchitecture and security in Vanet PPT
Architecture and security in Vanet PPT
 
Design Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software EngineeringDesign Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software Engineering
 
Text Mining of Twitter in Data Mining
Text Mining of Twitter in Data MiningText Mining of Twitter in Data Mining
Text Mining of Twitter in Data Mining
 
DFS & BFS in Computer Algorithm
DFS & BFS in Computer AlgorithmDFS & BFS in Computer Algorithm
DFS & BFS in Computer Algorithm
 
Software Development Method
Software Development MethodSoftware Development Method
Software Development Method
 
Secant method in Numerical & Statistical Method
Secant method in Numerical & Statistical MethodSecant method in Numerical & Statistical Method
Secant method in Numerical & Statistical Method
 
Motivation in Organization
Motivation in OrganizationMotivation in Organization
Motivation in Organization
 
Communication Skill
Communication SkillCommunication Skill
Communication Skill
 
Partial-Orderings in Discrete Mathematics
 Partial-Orderings in Discrete Mathematics Partial-Orderings in Discrete Mathematics
Partial-Orderings in Discrete Mathematics
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
 

Recently uploaded

Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfhenrik385807
 
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
LANDMARKS  AND MONUMENTS IN NIGERIA.pptxLANDMARKS  AND MONUMENTS IN NIGERIA.pptx
LANDMARKS AND MONUMENTS IN NIGERIA.pptxBasil Achie
 
The Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism PresentationThe Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism PresentationNathan Young
 
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...marjmae69
 
Event 4 Introduction to Open Source.pptx
Event 4 Introduction to Open Source.pptxEvent 4 Introduction to Open Source.pptx
Event 4 Introduction to Open Source.pptxaryanv1753
 
SBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSebastiano Panichella
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@vikas rana
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Pooja Nehwal
 
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxGenesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxFamilyWorshipCenterD
 
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)Basil Achie
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringSebastiano Panichella
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Salam Al-Karadaghi
 
Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸mathanramanathan2005
 
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...NETWAYS
 
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...NETWAYS
 
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Krijn Poppe
 
Philippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptPhilippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptssuser319dad
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...NETWAYS
 
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxmavinoikein
 

Recently uploaded (20)

Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
 
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
LANDMARKS  AND MONUMENTS IN NIGERIA.pptxLANDMARKS  AND MONUMENTS IN NIGERIA.pptx
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
 
The Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism PresentationThe Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism Presentation
 
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
 
Event 4 Introduction to Open Source.pptx
Event 4 Introduction to Open Source.pptxEvent 4 Introduction to Open Source.pptx
Event 4 Introduction to Open Source.pptx
 
SBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation Track
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
 
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxGenesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
 
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software Engineering
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
 
Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸
 
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
 
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
 
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
 
Philippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptPhilippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.ppt
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
 
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
 
Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptx
 

Binary Tree in Data Structure

  • 1. PRESENTED BY: MEGHAJ KUMAR MALLICK MCA 1ST YEAR ,2ND SEMESTER (MCA/25017/18) Binarytree
  • 2. Binary tree A binary tree is simply a tree in which each node can have at most two children. It may be 0, 1 or 2. Root node left sub tree Right sub tree Binary Tree
  • 3. Binary Tree A B G C D E F Left Child Right Child Root Parent Left subtree
  • 4. CONTINUED Left Child: The node on the left of any node is called left child. Right child: The node on the right of any node is called right child. Left Sub tree: sub tree attached to left side of root node is called left sub tree. Right Sub tree: sub tree attached to right side of root node is called right sub tree. The node of a binary tree is divided into three parts : Left childAddress Left Info Right Right child Address
  • 5. Linked Representation Ptr -> Info = Data Ptr -> Left = Left Child Ptr -> Right = Right Child A B C 11 32 D E 54 F G 76 Left Info Right Binary tree Representation using Linked List y
  • 6. From General Tree Binary Tree (Linked List) A B D E F C I G H Head Binary Tree A B H CD E F GI
  • 7. Types of Binary Tree Full Binary Tree Complete Binary Tree A B G C D E F A B C D E • All nodes (except leaf) have two children. • Each subtree has same length of path. • All nodes (except leaf) have two children. • Each subtree can has different length of path.
  • 8. Binary search tree A binary Search Tree is special kind if tree that satisfied the following conditions • If value of inserted node is bigger than parent then it will be right subtree. • If value of inserted node is smaller than parent then it will be left subtree. • This tree is known as binary search tree or ordered binary tree. • It used for searching
  • 9. Construction of binary Search Tree (BST) 1. Construction of binary Search Tree (BST) Step.1: Initially tree is empty ,place the first element at the root. Step.2: Compare the next element with root if element is grater than or equal to root then place it in right child position. else place it in the left child position. Step.3: Repeat the process (step 2) for the next element until end of elements or nodes.
  • 10. ALGORITHM FOR SEARCHING IN BST Algorithm : Search BST(key,targetkey) 1) START 2) If root==NULL 3) Return value not found 4) End if 5) If(target key<root) 6) Return searchBST (leftsubtree, targetkey) 7) else if(targetkey > root) 8) Return searchBST (rightsubtree, targetkey) 9) ELSE 10)FOUND target key 11)Return root 12)End if 13)End SearchBST
  • 11. Example of searching in BST 5220 35 12 E.g. if we have to search 12 than go to left sub tree 23 18 44
  • 12. Binary SEARCHTREE(INSERTION) • For insert data in binary tree two conditions we have to faced 1. IF tree is empty than insert to a new node make them root node. 2. If tree is not empty than all inserts take place at a leaf or at a • leaf like node (a tree that has only one NULL subtree
  • 13. Example of insertion in BST 23 4418 5220 35 12 23 4418 5220 35 12 Before insertion 19 After insertion
  • 14. Binary SEARCHTREE(INSERTION) Algorithm 1. START 2. If root==NULL 3. Root=newnode 4. If (newnode<root) 5. Return addBST(leftsubtree,newnode) 6. ELSE 7. Return addBST(rightsubtree,newnode) 8. End if 9. End addBST
  • 15.  Traversal of a binary tree is to accessevery node of binary tree at most once • Tree traversal ways a) Pre 0rder b) In Order c) Post Order BST Traversal
  • 16. 1. start 2. Visit root 3. Visit left sub-tree 4. Visit right sub-tree 5. stop 5 2 1 3 8 97 5 2 1 3 7 9 8 Preorder start Left sub tree Right sub tree
  • 17. 1. Visit left sub-tree 2. Visit root 3. Visit right sub-tree 5 2 2 1 3 5 7 9 8 Inorder 1 3 8 97 Right sub tree
  • 18. 1. Visit left sub-tree 2. Visit right sub-tree 3. Visit root 5 2 1 3 8 97 2 1 3 7 9 8 5 Postorder start
  • 19. When we delete a node, we need to consider how we take care of the children of thedeleted node. DELETE NODE
  • 20. 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 Cont…..
  • 21. 3)the node has 2 children  replace the key of that node with the minimum element at the right sub tree  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 1or 2.
  • 22. Binary tree Applications  File System(storing naturally hierarchical data)  Organize data(searching,insertion,deletion Binary search tree used for this purpose  Telephone dictionary  Arithmetic operations  Network routing etc