Searching
Let us start with the find
function. The idea behind the strategy of finding an element lies in looking at a root node and then, based on the results, going to the left subtree or the right subtree. As you can see in the preceding code, we also have Boolean functions, which will help us implement the find
function based on the type of node we are dealing with. A node of a 2-3 tree can be a leaf, a 2-node, or a 3-node and as those nodes have a different number of keys, the implementations of a search function should slightly differ for each type of node.
Before the implementation of the find
function, let us first look at a simple illustrative example of looking for an element with a value of 554
in a 2-3 tree:
Figure 7.5 – A 2-3 tree example
First, we look at the root node. We see that its value is 17
and it is not equal to 554
. So, we continue looking for the number:
Figure 7.6 – First step to find...