(Latest Revision: 03/29/2008)
Binary Search Trees
- binary trees, tables, and binary search trees.
- ADT binary tree -- the ADT is determined by these properties
- Organization -- A binary tree is empty, or consists of a
root with a left subtree and a right subtree. The subtrees
are binary trees.
- Elements -- any given homogeneous set
- Operations -- see the file BinaryTree.h in Carrano (pp.
520-522) for the list and the specs.
- ADT table -- see the specs in Carrano, Chapter 11.
- The table is important -- a basic data type for representing
many kinds of databases.
- We can use a simple array-based list or linked list to
implement a table, but neither of these implementations will
be very efficient if the number of items to be stored is
large. (Discuss)
- The table ADT can be implemented quite efficiently as a
binary search tree. This explains the importance of binary
search trees.
- Organization of the Table data type -- There is a
totally ordered set of keys. Each element of the
table contains a data field. Each element is also
assigned a unique key. Elements and the data in
them are accessed by key value.
- Elements of a Table data type -- data fields from any
homogeneous set -- typically each element of the table is a
certain kind of record which may contain many different
information fields -- an employee record for example.
- Major Table data type Operations
- Insert by key value
- Delete by key value
- Retrieve by key value
- Traverse Table
- What is the reason for using BST's? -- they provide a hybrid of
the array and linked list versions of a table in which all major
operations can be implemented efficiently.
- ADT binary search tree
- Organization -- A binary search tree is a binary tree in
which each node contains a key that is an element of a totally
ordered set. For every node N in the tree, all keys in the
left subtree of N are less than the key in N, and all keys in
the right subtree of N are greater than the key in N.
- Elements -- any given homogeneous set
- Operations -- see the file BST2.h for the list and the specs.
- Discuss implementation of retrieval.
- Discuss implementation of insertion.
- Discuss implementation of traversal.
- Discuss implementation of deletion.
- -- when the delete node is a leaf
- -- when the delete node has one child
- -- when the delete node has two children