[   ^ to index...   |   next -->   ]

CSE 143/AE : 15 August 2000


Trees and tree operations

Definitions of a binary tree

A binary tree is either

struct TreeNode { int key; TreeNode *left, *right; };

The nil tree, in this case, would be a NULL pointer (that is, a pointer to no node).

Binary search trees

A binary search tree is simply a tree which satisfies the following invariant:

We can define a class for a binary search tree as follows:

class BinaryTree { public: BinaryTree() : root(NULL) {} void insert(int value); bool find(int value); bool delete(int value); bool isEmpty(); int size(); private: TreeNode *root; };

Notice that nothing in particular distinguishes this class interface from that of, say, a Vector. The chief difference is that, since this class is documented to be a binary tree, the user will expect that its operations have typical binary tree performance characteristics.


Last modified: Tue Aug 15 10:18:31 PDT 2000