...

/

Searching in a Binary Search Tree (Implementation)

Searching in a Binary Search Tree (Implementation)

Learn about searching in the binary search tree and how to implement searching functionality in C#.

Introduction

In this lesson, you will implement a search function for binary search trees, which will return a node from the tree if the value to be searched matches it. And again, you will implement both an iterative and a recursive solution.

Here is a high-level description of the algorithm:

  1. Set the currentNode equal to root.

  2. If the value is less than the currentNode's value, then move on to the left-subtree. Otherwise, move on to the right-subtree.

  3. Repeat until the value at the currentNode is equal to the value searched, or it becomes NULL.

  4. Return the currentNode. ... ...