Searching in a Binary Search Tree (Implementation)
This lesson is about Searching in Binary Search Tree and how to implement searching functionality in C++.
We'll cover the following...
We'll cover the following...
Introduction #
In this lesson, we’ll implement a search function for binary search trees, which will return a node from the tree if the value to be searched matches it. We’ll again implement both an iterative and a recursive solution.
Here is a high-level description of the algorithm:
-
Set the
current nodeequal to root. -
If the value is less than the
current node's value, then move on to the left subtree, otherwise move on to the right sub-tree -
Repeat until the value at the
current nodeis equal to the value searched, or it becomesNULL. -
Return the current node ...