A step-by-step illustration of Binary Search Tree (Exact Match) to help you walk through a series of operations. Illustration is accompanied by actual code with bold line indicating the current operation.
4. Find Exact Match
public Node FindExact(Node node, int target) {
if (node == null) {
return null;
}
if (node.Value == target) {
return node;
}
if (node.Value < target) {
return FindExact(node.Right, target);
}
else {
return FindExact(node.Left, target);
}
}
Base Case:
return when beyond a leaf
return a node found
Recursively search left or
right subtree