Data Structures and Algorithms with Object-Oriented Design Patterns in C#
next up previous contents index

Binary Search Trees

Just as the binary tree is an important category of N-ary trees, the binary search tree  is an important category of M-way search trees.

Definition (Binary Search Tree)  A binary search tree    T is a finite set of keys. Either the set is empty, tex2html_wrap_inline62773; or the set consists of a root r and exactly two binary search trees tex2html_wrap_inline62929 and tex2html_wrap_inline62931, tex2html_wrap_inline62933, such that the following properties are satisfied:
  1. All the keys contained in left subtree, tex2html_wrap_inline62929, are less than r.
  2. All the keys contained in the right subtree, tex2html_wrap_inline62931, are greater than r.

Figure gif shows an example of a binary search tree. In this case, since the nodes of the tree carry alphabetic rather than numeric keys, the ordering of the keys is alphabetic. That is, all the keys in the left subtree of a given node precede alphabetically the root of the that node, and all the keys in the right subtree of a given node follow alphabetically the root of that node. The empty trees are shown explicitly as boxes in Figure gif. However, in order to simplify the graphical representation, the empty trees are often omitted from the diagrams.

   figure18038
Figure: A binary search tree.


next up previous contents index

Bruno Copyright © 2001 by Bruno R. Preiss, P.Eng. All rights reserved.