Search in Binary Search Trees (Implementation)
This lesson is about Searching in a Binary Search Tree, and how to implement searching functionality in Java.
Introduction
In this lesson, we are going to implement the Search functionality by using the BST class. The following are the steps that we perform to search for an element in BST.
- Start from Root.
- If the value is less than the current node value, then traverse the left sub-tree; if it is more, then traverse the right sub-tree.
- Keep on doing the above step until you either find a
node
with that value or reach a leafnode
—in which case the value doesn’t exist in the Binary Search Tree.
Iterative Search Implementation
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.