Binary Search Trees
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
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
• 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.