0% found this document useful (0 votes)
13 views13 pages

Binary Search Trees

Uploaded by

rinoreji07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views13 pages

Binary Search Trees

Uploaded by

rinoreji07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

BINARY SEARCH TREES

• MADE BY :
• RAYAN AGRAWAL [ 2241241 ]
• RENO REJI MATTHEW [ 2241242 ]
• ROHAN AJAY VARGHESE [ 2241243 ]
• ROHIT B [ 2241244 ]
• SARATH HARI [ 2241245 ]
BINARY SEARCH TREES

 A Binary Search Tree (BST) is a special type of binary tree in which the left child of a
node has a value less than the root’s value and the right child has a value greater than the
root’s value.
 This property is called the BST property and it makes it possible to efficiently search,
insert, and delete elements in the tree
PROPERTIES OF BINARY SEARCH TREE

• The left subtree of a node contains only nodes with keys lesser than the root’s key.
• The right subtree of a node contains only nodes with keys greater than the root’s key.
• Due to this, a binary search is very easy.
• The left and right subtree each must also be a binary search tree.
HANDLING DUPLICATE VALUES

• You can not allow the duplicated values at all.


• We must follow a consistent process throughout I,e either store the duplicate value at the
left or store the duplicate value at the right of the root but be consistent with your
approach.
• We can keep the counter with the node and if we found the duplicate value, then we
can increment the counter
HANDLING DUPLICATE VALUES
CREATION OF A BINARY SEARCH TREE

 Suppose the data elements are - 45, 15, 79, 90, 10, 55, 12, 20, 50
OPERATIONS IN BINARY SEARCH TREE

 Insertion
 Deletion
 Traversal
 Searching
INSERTION IN BINARY SEARCH TREE

IFTREE = NULL
Allocate memory for TREE
SET TREE -> DATA = ITEM
SET TREE -> LEFT = TREE ->
RIGHT = NULL
ELSE
IF ITEM < TREE -> DATA
Insert(TREE -> LEFT, ITEM)
ELSE
Insert(TREE -> RIGHT, ITEM)
[END OF IF]
[END OF IF]
•Step 2: END
DELETION IN BINARY SEARCH TREE
TRAVERSAL IN BINARY SEARCH TREE

POSTORDER
INORDER
PREORDERTRAVERSAL
TRAVERSAL
TRAVERSAL

1.Traverse the left subtree.


1.Visit the root. subtree,
2.Visit the root.
2.Traverse the right subtree
left subtree.
3.Visit the Root
3.Traverse the right subtree
SEARCHING IN BINARY SEARCH TREE
CREATION OF A BINARY SEARCH TREE

• First, we have to insert the first element into the tree as the root of the tree.
• Then, read the next element; if it is smaller than the root node, insert it as the root of the
left subtree, and move to the next element.
• Otherwise, if the element is larger than the root node, then insert it as the root of the right
subtree.
APPLICATIONS

 Online shopping: Online shopping platforms can use binary search trees to manage
product catalogs.
 Computer file systems: Binary search trees are used in computer file systems to organize
files and directories.
 Internet search engines: Internet search engines use binary search trees to store and index
web pages.

You might also like