PRESENTATION
BINARY SEARCH TREE OPERATION
DEFINATION OF BINARY SEARCH TREE
Binary Search Tree is a node-based binary tree data
structure which has the following properties.
•The left subtree of a node contains only nodes with key
lesser than the node's key.
•The right subtree of a node contains only
node with keys greater than the node's key.
DIAGRAM OF TREE
BASIC OPERATION
•#1) INSERT
•#2)DELETE
•#3)SEARCH
•#4)TRAVERSAL
ADVANTAGES OF BST
•#1)Searching Is Very Efficient
We have all the nodes of BST in a specific order, hence searching for a
particular item is very efficient and faster. This is because we need not search
the entire and compare all nodes.
We just have to compare the root node to the item which we are searching and
then we decide whether we need to search in the left or right subtree.
ADVANTAGES OF BST
•#2) Efficient Working When Compared To
Array And Linked Lists
When we search an item in case of BST, we get rid of half of the left or right
subtree at every step thereby improving the performance of search operation.
This is in contrast to array or linked list in which we need to compare all the
items sequentially to search a particular.
ADVANTAGES OF BST
•#3)Insert And Delete Are Faster
Insert and delete operations also are faster when compared to other data
structures like Linked Lists and Array.
APPLICTION OF BST
• BST is used to implement multilevel indexing in database application.
• BST is also used to implement constructs like a dictionary.
• BST can be used to implement various efficient searching algorithms.
• BST is also used in applications that require a sorted list as input
like the online stories.
• BSTs are also used to evaluate expression using expression trees.
CONCLUTION
Binary search trees(BST) are a variation of the binary tree and are widely used
in the software field. They are also called ordered binary trees as each node in
BST is placed according to a specific order.
Inorder traversal of BST gives us the sorted sequence of items in ascending
order. When BSTs are used for searching, it is very efficient and is done within
no time. BSTs are also used for a variety of application like Huffman's coding,
Multilevel index in database ,etc.
OPERATIONS
SEARCH OPERATION
The Algorithm depends on the property of BST that if each left subtree has
value below root and each right subtree has value above the root.
If the value is below the root, we can say for sure that the value is not in the
right subtree; we need to only search in the left subtree and if the value above
root, we can say for sure that value is not in the left subtree; we need to only
search in the right subtree.
VISUALIZE BY DIAGRAM
VISUALIZE BY DIAGRAM
VISUALIZE BY DIAGRAM
VISUALIZE BY DIAGRAM
INSERT OPERATION
Inserting a value in the correct position is similar to searching because we try to
maintain the rule that the left subtree is lesser than root and the right subtree is
larger than root.
We keep going to either right subtree depending on the value and when we
reach a point left or right subtree is null, we put the new code there.
VISUALIZE BY DIAGRAM
VISUALIZE BY DIAGRAM
VISUALIZE BY DIAGRAM
VISUALIZE BY DIAGRAM
DELETE OPERATION
There are three cases for deleting a node from a binary
search tree.
CASE-1
In the first case, the node to be delete is the leaf node. In such a case, simply
delete the node from the tree.
CASE-2
In the second case, the node to be deleted lies has a single child node.
In such cases follow the step below
1.Replace that node with its child node.
2.Remove the child node from its original position.
CASE-3
• In the third case, the node to be deleted has two children. In such a case
follow the steps below:
1.Get the inorder successor of that.
2.Replace the node with the inorder successor.
3.Remove the inorder successor from its original position.
VISUALIZE BY DIAGRAM
VISUALIZE BY DIAGRAM
PRESENTED BY:
•Ehsan ul khaliq (F20-BsCS-5004)
•Faisal Shehzad (F20-BsCS-5030)
•Kamran Zafar (F20-BsCS-5039)

Binary search tree operations

  • 1.
  • 2.
    DEFINATION OF BINARYSEARCH TREE Binary Search Tree is a node-based binary tree data structure which has the following properties. •The left subtree of a node contains only nodes with key lesser than the node's key. •The right subtree of a node contains only node with keys greater than the node's key.
  • 3.
  • 4.
  • 5.
    ADVANTAGES OF BST •#1)SearchingIs Very Efficient We have all the nodes of BST in a specific order, hence searching for a particular item is very efficient and faster. This is because we need not search the entire and compare all nodes. We just have to compare the root node to the item which we are searching and then we decide whether we need to search in the left or right subtree.
  • 6.
    ADVANTAGES OF BST •#2)Efficient Working When Compared To Array And Linked Lists When we search an item in case of BST, we get rid of half of the left or right subtree at every step thereby improving the performance of search operation. This is in contrast to array or linked list in which we need to compare all the items sequentially to search a particular.
  • 7.
    ADVANTAGES OF BST •#3)InsertAnd Delete Are Faster Insert and delete operations also are faster when compared to other data structures like Linked Lists and Array.
  • 8.
    APPLICTION OF BST •BST is used to implement multilevel indexing in database application. • BST is also used to implement constructs like a dictionary. • BST can be used to implement various efficient searching algorithms. • BST is also used in applications that require a sorted list as input like the online stories. • BSTs are also used to evaluate expression using expression trees.
  • 9.
    CONCLUTION Binary search trees(BST)are a variation of the binary tree and are widely used in the software field. They are also called ordered binary trees as each node in BST is placed according to a specific order. Inorder traversal of BST gives us the sorted sequence of items in ascending order. When BSTs are used for searching, it is very efficient and is done within no time. BSTs are also used for a variety of application like Huffman's coding, Multilevel index in database ,etc.
  • 10.
  • 11.
    SEARCH OPERATION The Algorithmdepends on the property of BST that if each left subtree has value below root and each right subtree has value above the root. If the value is below the root, we can say for sure that the value is not in the right subtree; we need to only search in the left subtree and if the value above root, we can say for sure that value is not in the left subtree; we need to only search in the right subtree.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
    INSERT OPERATION Inserting avalue in the correct position is similar to searching because we try to maintain the rule that the left subtree is lesser than root and the right subtree is larger than root. We keep going to either right subtree depending on the value and when we reach a point left or right subtree is null, we put the new code there.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
    DELETE OPERATION There arethree cases for deleting a node from a binary search tree.
  • 22.
    CASE-1 In the firstcase, the node to be delete is the leaf node. In such a case, simply delete the node from the tree.
  • 23.
    CASE-2 In the secondcase, the node to be deleted lies has a single child node. In such cases follow the step below 1.Replace that node with its child node. 2.Remove the child node from its original position.
  • 25.
    CASE-3 • In thethird case, the node to be deleted has two children. In such a case follow the steps below: 1.Get the inorder successor of that. 2.Replace the node with the inorder successor. 3.Remove the inorder successor from its original position.
  • 26.
  • 27.
  • 28.
    PRESENTED BY: •Ehsan ulkhaliq (F20-BsCS-5004) •Faisal Shehzad (F20-BsCS-5030) •Kamran Zafar (F20-BsCS-5039)