Suppose we want to look for an element x that may be in a dictionary represented by a binary search tree T. We can express the lookup operation by the following recursive algorithm.
Basis: If the tree is empty, then x is not present. If the tree is not empty and x appears at the root, then x is present.
Induction: If x is not empty and x appears not at the root, let y be the element at the root of T. If x < y, look in the left subtree of the root. If x > y, look in the right subtree of the root.
In the example x > y means ape > animal The algorithm as a Nassi Shneidermann diagram:
Procedure Look_up(node n_r, label x):
Last modified: 27/July/98 (12:14)