Introduction to the Binary Search Tree Searching Algorithm

A Binary search tree searching algorithm searches by comparing the value of the node that is being searched with the root node and if the value is greater it goes to the right subtree and if it is less then it goes to the left subtree and it keeps going until it either finds the value or doesnt find it and return null

Algorithm steps

  • Compare the element with the root of the tree
  • If the item is matched then return the location of the node
  • Otherwise check if item is less than the element present on root, if so then move to the left sub-tree
  • If not, then move to the right sub-tree
  • Repeat this procedure recursively until match found
  • If element is not found then return NULL
  • Binary Search tree

    Example: Let us say we are searching for the number 4 in this Binary Search Tree, we would first compare 4 with 8 and 4 is less than eight so we would go to the left subtree and compare 4 with 3, and 4 is greater than 3 so we would go to the right subtree and compare 4 with 6, and 4 is less than 6 so we would go to the left subtree and compare 4 with 4 ,where 4 is equal to 4 so we would return that node

    Link to a site that will help you learn more about Binary Search Tree Searching Algorithm