SlideShare une entreprise Scribd logo
We’ll discuss the following Content today:
Binary Search Tree
Definition
Properties of Binary Tree
How to search a binary search tree?
• Pseudo code
• Complexities
• Examples
• Resources
Binary Search Tree
Definition
• The Binary Tree is a Tree. In which every parent
node have maximum two child nodes.
• A Binary Search Tree is a variation of Binary
Search Tree. The values in the Binary Search tree
can be stored in the specific sequence.
• It is called a search tree because it can be used to
search for the presence of a number in O(Log(n)
times.
• A Binary Search Tree is an ordered tree.
• There is no permission for duplicate nodes.
Properties of Binary
Search Tree
The properties that separate a binary search tree
from a regular binary tree is:
• All nodes of left sub tree are less than the root
node.
• All nodes of right sub tree are more than the
root node.
• Both sub trees of each node are also BSTs
i.e. they have the above two properties.
8
6
5
9
10
7
Root
Properties of Binary
Search Tree
8
3
1 6
4
8
3
1 6
2
The binary tree on the right side isn't a binary search tree
because the right subtree of the node "3" contains a value
How to search a binary
search tree?
17
15
18
6
3 7
13
13
4
9
20
Root
(1) Start at the root
(2) Compare the value of the item
you are searching for with the
value stored at the root
(3) If the values are equal, then item
found; otherwise, if it is a leaf
node, then not found.
(4) If it is less than the value stored
at the root, then search the left
sub tree.
(5) If it is greater than the value
stored at the root, then search
the right sub tree.
(6) Repeat steps 2-6 for the root of
the sub tree chosen in the
previous step 4 or 5.
Compare
9 with 15
Compare 9
with 6
Compare 9
with 7
Compare
9 with 13
Compare 9
with 9
Is this better than searching
a linked list? Yes !! ---> O(logN)
Time Complexities
Operation
Best Case
Complexity
Average Case
Complexity
Worst Case
Complexity
Search O(log n) O(log n) O(n)
Insertion O(log n) O(log n) O(n)
Deletion O(log n) O(log n) O(n)
Space Complexity
The space complexity for all the operations is O(n).
Note: Here, n is the number of nodes in the tree.
Applications
• In multilevel indexing in the database
• For dynamic sorting
• For managing virtual memory areas in Unix
kernel
• https://www.programiz.com/dsa/binary-search-tree
• https://en.wikipedia.org/wiki/Binary_search_tree
• https://www.upgrad.com/blog/difference-between-
binary-tree-and-binary-search-tree/
Resources
Thanks

Contenu connexe

Similaire à Binary Search Tree

Binary Trees.ppt
Binary Trees.pptBinary Trees.ppt
Binary Trees.ppt
Riannel Tecson
 
4a searching-more
4a searching-more4a searching-more
4a searching-more
Shahzad Ali
 
Binary Search Tree In Python.pptx
Binary Search Tree In Python.pptxBinary Search Tree In Python.pptx
Binary Search Tree In Python.pptx
RohanThota3
 
Trees second part in data structures with examples
Trees second part in data structures with examplesTrees second part in data structures with examples
Trees second part in data structures with examples
rupanaveen24
 
Binary Search Tree.pptx
Binary Search Tree.pptxBinary Search Tree.pptx
Binary Search Tree.pptx
RaaviKapoor
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
Anusruti Mitra
 
Unit 3 trees
Unit 3   treesUnit 3   trees
Unit 3 trees
LavanyaJ28
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
Krish_ver2
 
Binary tree
Binary treeBinary tree
Binary tree
MKalpanaDevi
 
Database Engine
Database EngineDatabase Engine
Database Engine
prashanthbabu07
 
Tree
TreeTree
Tree
sbkbca
 
Binary tree
Binary treeBinary tree
Binary tree
Afaq Mansoor Khan
 
Tree 11.ppt
Tree 11.pptTree 11.ppt
Tree 11.ppt
DEEPAK948083
 
Rahat & juhith
Rahat & juhithRahat & juhith
Rahat & juhith
Rj Juhith
 
B Tree, Introduction ,example,Splay tree
B Tree, Introduction ,example,Splay treeB Tree, Introduction ,example,Splay tree
B Tree, Introduction ,example,Splay tree
VikasNirgude2
 
Search tree,Tree and binary tree and heap tree
Search tree,Tree  and binary tree and heap treeSearch tree,Tree  and binary tree and heap tree
Search tree,Tree and binary tree and heap tree
zia eagle
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
Kamran Zafar
 
Data structure(Part 2)
Data structure(Part 2)Data structure(Part 2)
Data structure(Part 2)
SURBHI SAROHA
 
Data Structures 8
Data Structures 8Data Structures 8
Data Structures 8
Dr.Umadevi V
 
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNNsplaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
ratnapatil14
 

Similaire à Binary Search Tree (20)

Binary Trees.ppt
Binary Trees.pptBinary Trees.ppt
Binary Trees.ppt
 
4a searching-more
4a searching-more4a searching-more
4a searching-more
 
Binary Search Tree In Python.pptx
Binary Search Tree In Python.pptxBinary Search Tree In Python.pptx
Binary Search Tree In Python.pptx
 
Trees second part in data structures with examples
Trees second part in data structures with examplesTrees second part in data structures with examples
Trees second part in data structures with examples
 
Binary Search Tree.pptx
Binary Search Tree.pptxBinary Search Tree.pptx
Binary Search Tree.pptx
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 
Unit 3 trees
Unit 3   treesUnit 3   trees
Unit 3 trees
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Binary tree
Binary treeBinary tree
Binary tree
 
Database Engine
Database EngineDatabase Engine
Database Engine
 
Tree
TreeTree
Tree
 
Binary tree
Binary treeBinary tree
Binary tree
 
Tree 11.ppt
Tree 11.pptTree 11.ppt
Tree 11.ppt
 
Rahat & juhith
Rahat & juhithRahat & juhith
Rahat & juhith
 
B Tree, Introduction ,example,Splay tree
B Tree, Introduction ,example,Splay treeB Tree, Introduction ,example,Splay tree
B Tree, Introduction ,example,Splay tree
 
Search tree,Tree and binary tree and heap tree
Search tree,Tree  and binary tree and heap treeSearch tree,Tree  and binary tree and heap tree
Search tree,Tree and binary tree and heap tree
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
 
Data structure(Part 2)
Data structure(Part 2)Data structure(Part 2)
Data structure(Part 2)
 
Data Structures 8
Data Structures 8Data Structures 8
Data Structures 8
 
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNNsplaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
 

Dernier

HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
David Brossard
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 

Dernier (20)

HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 

Binary Search Tree

  • 1.
  • 2. We’ll discuss the following Content today: Binary Search Tree Definition Properties of Binary Tree How to search a binary search tree? • Pseudo code • Complexities • Examples • Resources
  • 3. Binary Search Tree Definition • The Binary Tree is a Tree. In which every parent node have maximum two child nodes. • A Binary Search Tree is a variation of Binary Search Tree. The values in the Binary Search tree can be stored in the specific sequence. • It is called a search tree because it can be used to search for the presence of a number in O(Log(n) times. • A Binary Search Tree is an ordered tree. • There is no permission for duplicate nodes.
  • 4. Properties of Binary Search Tree The properties that separate a binary search tree from a regular binary tree is: • All nodes of left sub tree are less than the root node. • All nodes of right sub tree are more than the root node. • Both sub trees of each node are also BSTs i.e. they have the above two properties. 8 6 5 9 10 7 Root
  • 5. Properties of Binary Search Tree 8 3 1 6 4 8 3 1 6 2 The binary tree on the right side isn't a binary search tree because the right subtree of the node "3" contains a value
  • 6. How to search a binary search tree? 17 15 18 6 3 7 13 13 4 9 20 Root (1) Start at the root (2) Compare the value of the item you are searching for with the value stored at the root (3) If the values are equal, then item found; otherwise, if it is a leaf node, then not found. (4) If it is less than the value stored at the root, then search the left sub tree. (5) If it is greater than the value stored at the root, then search the right sub tree. (6) Repeat steps 2-6 for the root of the sub tree chosen in the previous step 4 or 5. Compare 9 with 15 Compare 9 with 6 Compare 9 with 7 Compare 9 with 13 Compare 9 with 9 Is this better than searching a linked list? Yes !! ---> O(logN)
  • 7. Time Complexities Operation Best Case Complexity Average Case Complexity Worst Case Complexity Search O(log n) O(log n) O(n) Insertion O(log n) O(log n) O(n) Deletion O(log n) O(log n) O(n) Space Complexity The space complexity for all the operations is O(n). Note: Here, n is the number of nodes in the tree.
  • 8. Applications • In multilevel indexing in the database • For dynamic sorting • For managing virtual memory areas in Unix kernel
  • 9. • https://www.programiz.com/dsa/binary-search-tree • https://en.wikipedia.org/wiki/Binary_search_tree • https://www.upgrad.com/blog/difference-between- binary-tree-and-binary-search-tree/ Resources