Searching in a Binary Search Tree (Implementation)
Explore how to implement and understand both iterative and recursive search functions in binary search trees using Python. This lesson helps you grasp the traversal logic and algorithmic approach to efficiently find values within a BST, enhancing your coding skills for technical interviews.
We'll cover the following...
We'll cover the following...
Introduction
We are going to 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 node’ equal 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 ...