SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Binary Search Tree
Aakash Montheiro - 161702
Abhishek.L.R - 161704
Deelan Jostan Monthero - 161726
I Sem - M.C.A
Aloysius Institute Of Management &
Information Technology
What is …?
• A Binary tree is a non-linear data structure which is a collection of elements
called nodes.
• A Binary Search Tree (BST) is a Binary tree in which all the nodes follow the
below-mentioned properties :
The left sub-tree of a node has a key less than or equal to its parent node's key.
The right sub-tree of a node has a key greater than to its parent node's key.
• Thus, BST divides all its sub-trees into two segments;
 Left sub-tree
 Right sub-tree
Operations Performed in a BST:
Search − Searches an element in a tree.
Insert − Inserts an element in a tree.
Traversal :
Pre-order Traversal − Traverses a tree in a pre-order manner. [Root->Left->Right]
In-order Traversal − Traverses a tree in an in-order manner. [Left->Root->Right]
Post-order Traversal − Traverses a tree in a post-order manner.[Left->Right->Root]
Example:
Given : 37 ,24 ,45 ,20 ,29 ,41,52
37
24 45
20 29 41 52
Binary Tree v/s Binary Search Tree
Given : 37 ,45 ,24 ,29 ,41 ,20 ,24 ,52
24
37
24 45
20 29 41 52
37
24 45
20 29 41 52
37
24 45
20 29 41 52
Implementation:
• Creating the Structure
typedef struct Tree{
int Data;
struct Tree *Right;
struct Tree * Left;
}TREENODE;
Data *Right*Left
Null Null
Implementation Contd..
class BSTree{
TREENODE *Root;
public:
BTree();//--Constructor
TREENODE *MakeTreeNode(int Num);
void InsertTreeNode(int Num);
void Preorder(TREENODE *Root);
void Postorder(TREENODE *Root);
void Inorder(TREENODE *Root);
TREENODE *GetRoot();
int TreeSearch(int Num);
};
Creating the Class:
Implementation Contd…
BTree::BTree()
{
Root=NULL;
}
TREENODE *BTree::MakeTreeNode(int Num)
{
TREENODE *New;
New=(TREENODE *)malloc(sizeof(TREENODE));
New->Data=Num;
New->Right=NULL;
New->Left=NULL;
return New;
}
TREENODE *BTree::GetRoot()
{
return Root;
}
Constructor
Getting the Root Node
Creating the Node
Implementation Contd…
void BTree::InsertTreeNode(int Num)
{
TREENODE *New,*Cur,*Prev;
Cur=Prev=Root;
New=MakeTreeNode(Num);
if(Root==NULL){
Root=New;
return;
}
Inserting a Element to a tree:
Implementation Contd…
Inserting a Element to a tree Contd:
while(Cur){
if(Num>Cur->Data){
Prev=Cur;
Cur=Cur->Right;
}else{
Prev=Cur;
Cur=Cur->Left;
}
}
if(Num>Prev->Data){
Prev->Right=New;
}else{
Prev->Left=New;
}
return;
}
Implementation Contd…
void BTree::Preorder(TREENODE *Root)
{
if(Root){
cout<<Root->Data<<"t""";
Preorder(Root->Left);
Preorder(Root->Right);
}
}
void BTree::Postorder(TREENODE *Root)
{
if(Root){
Postorder(Root->Left);
Postorder(Root->Right);
cout<<Root->Data<<"t";
}
}
void BTree::Inorder(TREENODE *Root)
{
if(Root){
Inorder(Root->Left);
cout<<Root->Data<<"t";
Inorder(Root->Right);
}
}
Pre-Order
In-OrderPost-Order
Traversing the Tree
int BTree::TreeSearch(int Num)
{
TREENODE *Cur;
Cur=Root;
while(Cur){
if(Num==Cur->Data){
return 1;
}else if(Num>Cur->Data){
Cur=Cur->Right;
}else{
Cur=Cur->Left;
}
}
}
Implementation Contd…
Searching the Element
Implementation Contd…
Inserting elements in Main Program cout<<"Enter the value of N : ";
cin>>N;
cout<<"Enter the elements n";
for(i=1;i<=N;i++){
cout<<"Enter the element A["<<i<<"] : ";
cin>>Num;
BT.InsertTreeNode(Num);
}
Declaration in Main Program
TREENODE *Root;
BTree BT;
Implementation Contd…
Root=BT.GetRoot();
cout<<"Pre-order traverse is : ";
BT.Preorder(Root);
cout<<"n";
break;
Traversing the TreeSearching of Elements
cout<<"Enter the Search element : ";
cin>>Search;
Res=BT.TreeSearch(Search);
if(Res==1){
cout<<"Element "<<Search<<" Found...n";
}else{
cout<<"Element "<<Search<<" Not-found....n";
}
break;
Click here to download Source Code
Thank You
For
Your
Attention !
Any Question

Weitere ähnliche Inhalte

Was ist angesagt?

Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data StructureDharita Chokshi
 
Red black tree
Red black treeRed black tree
Red black treeRajendran
 
Binary tree traversal ppt
Binary tree traversal pptBinary tree traversal ppt
Binary tree traversal pptPREEYANKAV
 
Terminology of tree
Terminology of treeTerminology of tree
Terminology of treeRacksaviR
 
Binary Search Tree and AVL
Binary Search Tree and AVLBinary Search Tree and AVL
Binary Search Tree and AVLKatang Isip
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operationsKamran Zafar
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structureAnusruti Mitra
 
trees in data structure
trees in data structure trees in data structure
trees in data structure shameen khan
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structureschauhankapil
 
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 StructureBalwant Gorad
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSGokul Hari
 
Threaded binary tree
Threaded binary treeThreaded binary tree
Threaded binary treeArunaP47
 

Was ist angesagt? (20)

Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Red black tree
Red black treeRed black tree
Red black tree
 
Binary tree traversal ppt
Binary tree traversal pptBinary tree traversal ppt
Binary tree traversal ppt
 
Terminology of tree
Terminology of treeTerminology of tree
Terminology of tree
 
Binary Search Tree and AVL
Binary Search Tree and AVLBinary Search Tree and AVL
Binary Search Tree and AVL
 
Binary search trees
Binary search treesBinary search trees
Binary search trees
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
 
Binary tree
Binary tree Binary tree
Binary tree
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
 
Stacks
StacksStacks
Stacks
 
Threaded Binary Tree.pptx
Threaded Binary Tree.pptxThreaded Binary Tree.pptx
Threaded Binary Tree.pptx
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
 
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
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Linked lists
Linked listsLinked lists
Linked lists
 
Threaded binary tree
Threaded binary treeThreaded binary tree
Threaded binary tree
 
Expression trees
Expression treesExpression trees
Expression trees
 

Andere mochten auch

Doubly linked list
Doubly linked listDoubly linked list
Doubly linked listFahd Allebdi
 
Trees data structure
Trees data structureTrees data structure
Trees data structureSumit Gupta
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1smruti sarangi
 
358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8sumitbardhan
 
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structureTushar Aneyrao
 
6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
Double linked list
Double linked listDouble linked list
Double linked listraviahuja11
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Balwant Gorad
 
Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)
Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)
Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)John C. Havens
 
Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)
Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)
Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)Lovelyn Rose
 
موقع سلايد شير
موقع سلايد شيرموقع سلايد شير
موقع سلايد شيرMohamed Elshazly
 
Open Legal Data Workshop at Stanford
Open Legal Data Workshop at StanfordOpen Legal Data Workshop at Stanford
Open Legal Data Workshop at StanfordHarry Surden
 
Harry Surden - Artificial Intelligence and Law Overview
Harry Surden - Artificial Intelligence and Law OverviewHarry Surden - Artificial Intelligence and Law Overview
Harry Surden - Artificial Intelligence and Law OverviewHarry Surden
 
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017Carol Smith
 

Andere mochten auch (20)

Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
 
Linked list
Linked listLinked list
Linked list
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
linked list
linked list linked list
linked list
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
7 Myths of AI
7 Myths of AI7 Myths of AI
7 Myths of AI
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1
 
Linked list
Linked listLinked list
Linked list
 
358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8
 
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structure
 
6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil
 
Double linked list
Double linked listDouble linked list
Double linked list
 
Cyber Crime
Cyber CrimeCyber Crime
Cyber Crime
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
 
Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)
Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)
Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)
 
Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)
Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)
Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)
 
موقع سلايد شير
موقع سلايد شيرموقع سلايد شير
موقع سلايد شير
 
Open Legal Data Workshop at Stanford
Open Legal Data Workshop at StanfordOpen Legal Data Workshop at Stanford
Open Legal Data Workshop at Stanford
 
Harry Surden - Artificial Intelligence and Law Overview
Harry Surden - Artificial Intelligence and Law OverviewHarry Surden - Artificial Intelligence and Law Overview
Harry Surden - Artificial Intelligence and Law Overview
 
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
 

Ähnlich wie Binary Search Tree

Ähnlich wie Binary Search Tree (20)

L 19 ct1120
L 19 ct1120L 19 ct1120
L 19 ct1120
 
binary search tree
binary search treebinary search tree
binary search tree
 
Binary tree
Binary treeBinary tree
Binary tree
 
Introduction to data structure by anil dutt
Introduction to data structure by anil duttIntroduction to data structure by anil dutt
Introduction to data structure by anil dutt
 
BinarySearchTrees.ppt
BinarySearchTrees.pptBinarySearchTrees.ppt
BinarySearchTrees.ppt
 
BinarySearchTrees.ppt
BinarySearchTrees.pptBinarySearchTrees.ppt
BinarySearchTrees.ppt
 
BinarySearchTrees (1).ppt
BinarySearchTrees (1).pptBinarySearchTrees (1).ppt
BinarySearchTrees (1).ppt
 
Binary searchtrees
Binary searchtreesBinary searchtrees
Binary searchtrees
 
BinarySearchTrees.ppt
BinarySearchTrees.pptBinarySearchTrees.ppt
BinarySearchTrees.ppt
 
data structure very BinarySearchTrees.ppt
data structure very BinarySearchTrees.pptdata structure very BinarySearchTrees.ppt
data structure very BinarySearchTrees.ppt
 
Binary search tree
Binary search treeBinary search tree
Binary search tree
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Unit iv data structure-converted
Unit  iv data structure-convertedUnit  iv data structure-converted
Unit iv data structure-converted
 
binarysearch-180319163432.pdf 11111111111
binarysearch-180319163432.pdf 11111111111binarysearch-180319163432.pdf 11111111111
binarysearch-180319163432.pdf 11111111111
 
Binary tree
Binary treeBinary tree
Binary tree
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Binary search tree
Binary search treeBinary search tree
Binary search tree
 
binary_trees2
binary_trees2binary_trees2
binary_trees2
 
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
 
Tree
TreeTree
Tree
 

Kürzlich hochgeladen

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 

Kürzlich hochgeladen (20)

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 

Binary Search Tree

  • 1. Binary Search Tree Aakash Montheiro - 161702 Abhishek.L.R - 161704 Deelan Jostan Monthero - 161726 I Sem - M.C.A Aloysius Institute Of Management & Information Technology
  • 2. What is …? • A Binary tree is a non-linear data structure which is a collection of elements called nodes. • A Binary Search Tree (BST) is a Binary tree in which all the nodes follow the below-mentioned properties : The left sub-tree of a node has a key less than or equal to its parent node's key. The right sub-tree of a node has a key greater than to its parent node's key. • Thus, BST divides all its sub-trees into two segments;  Left sub-tree  Right sub-tree
  • 3. Operations Performed in a BST: Search − Searches an element in a tree. Insert − Inserts an element in a tree. Traversal : Pre-order Traversal − Traverses a tree in a pre-order manner. [Root->Left->Right] In-order Traversal − Traverses a tree in an in-order manner. [Left->Root->Right] Post-order Traversal − Traverses a tree in a post-order manner.[Left->Right->Root]
  • 4. Example: Given : 37 ,24 ,45 ,20 ,29 ,41,52 37 24 45 20 29 41 52
  • 5. Binary Tree v/s Binary Search Tree Given : 37 ,45 ,24 ,29 ,41 ,20 ,24 ,52 24 37 24 45 20 29 41 52 37 24 45 20 29 41 52 37 24 45 20 29 41 52
  • 6. Implementation: • Creating the Structure typedef struct Tree{ int Data; struct Tree *Right; struct Tree * Left; }TREENODE; Data *Right*Left Null Null
  • 7. Implementation Contd.. class BSTree{ TREENODE *Root; public: BTree();//--Constructor TREENODE *MakeTreeNode(int Num); void InsertTreeNode(int Num); void Preorder(TREENODE *Root); void Postorder(TREENODE *Root); void Inorder(TREENODE *Root); TREENODE *GetRoot(); int TreeSearch(int Num); }; Creating the Class:
  • 8. Implementation Contd… BTree::BTree() { Root=NULL; } TREENODE *BTree::MakeTreeNode(int Num) { TREENODE *New; New=(TREENODE *)malloc(sizeof(TREENODE)); New->Data=Num; New->Right=NULL; New->Left=NULL; return New; } TREENODE *BTree::GetRoot() { return Root; } Constructor Getting the Root Node Creating the Node
  • 9. Implementation Contd… void BTree::InsertTreeNode(int Num) { TREENODE *New,*Cur,*Prev; Cur=Prev=Root; New=MakeTreeNode(Num); if(Root==NULL){ Root=New; return; } Inserting a Element to a tree:
  • 10. Implementation Contd… Inserting a Element to a tree Contd: while(Cur){ if(Num>Cur->Data){ Prev=Cur; Cur=Cur->Right; }else{ Prev=Cur; Cur=Cur->Left; } } if(Num>Prev->Data){ Prev->Right=New; }else{ Prev->Left=New; } return; }
  • 11. Implementation Contd… void BTree::Preorder(TREENODE *Root) { if(Root){ cout<<Root->Data<<"t"""; Preorder(Root->Left); Preorder(Root->Right); } } void BTree::Postorder(TREENODE *Root) { if(Root){ Postorder(Root->Left); Postorder(Root->Right); cout<<Root->Data<<"t"; } } void BTree::Inorder(TREENODE *Root) { if(Root){ Inorder(Root->Left); cout<<Root->Data<<"t"; Inorder(Root->Right); } } Pre-Order In-OrderPost-Order Traversing the Tree
  • 12. int BTree::TreeSearch(int Num) { TREENODE *Cur; Cur=Root; while(Cur){ if(Num==Cur->Data){ return 1; }else if(Num>Cur->Data){ Cur=Cur->Right; }else{ Cur=Cur->Left; } } } Implementation Contd… Searching the Element
  • 13. Implementation Contd… Inserting elements in Main Program cout<<"Enter the value of N : "; cin>>N; cout<<"Enter the elements n"; for(i=1;i<=N;i++){ cout<<"Enter the element A["<<i<<"] : "; cin>>Num; BT.InsertTreeNode(Num); } Declaration in Main Program TREENODE *Root; BTree BT;
  • 14. Implementation Contd… Root=BT.GetRoot(); cout<<"Pre-order traverse is : "; BT.Preorder(Root); cout<<"n"; break; Traversing the TreeSearching of Elements cout<<"Enter the Search element : "; cin>>Search; Res=BT.TreeSearch(Search); if(Res==1){ cout<<"Element "<<Search<<" Found...n"; }else{ cout<<"Element "<<Search<<" Not-found....n"; } break; Click here to download Source Code