When building a binary search tree it is easier to start with the root and then insert new nodes as needed. The following cases arise:
Using the same notation as before, we thus get:
![]() |
Note that the node added is always a leaf. The resulting tree is once again a binary search tree. This can be rigorously proved via an inductive argument.
There is something that should be emphasized here. The procedure that we are describing creates a new tree out of a given tree, with the value inserted at the right position. In a way, the given tree is not modified, it is just inspected. When the tree represents a large database, it would be better to modify the given tree rather than to construct a new tree again. This involves the use of pointers (as you have seen in linked lists). For the moment, we shall not be concerned with such details. It seems preferable to introduce only a few concepts at a time.