Fall 2000

Ileana Streinu

Lecture 21

- Definition of binary search trees.
- Application of binary tree traversal for search trees: Sorting using binary search trees.
- Tree traversal algorithms, sketch. Left node Right, Left Right node traversals.
- Recursive definition of tree traversal functions: Prefix, Infix and Postfix traversals.
- Review: How recursive calls are being implemented using a stack.
- Example. The stack behavior for the recursive calls of a Prefix traversal of a small binary tree.
- In-class exercise (from an old exam ): recursive algorithm for computing the depth of a binary tree.
- Lab: implement sorting using binary search trees. Need to write a function to construct the binary search tree from an input array of numbers, then traverse the tree in infix order.
- Discussion: doubly linked lists; binary trees with pointers to parent, general (non-binary) trees.
- If time allows (otherwise, look at this on your own and be prepared for a discussion on Th): preparation for final exam, old final exam.
- Start designing the BSearchTree class. Discussion, in class: how to implement the node; what is in the private and in the public part of the class.
- Private: a pointer to the root ("root").
- What member functions are needed; types of functions in the BSearchTree class: constructor (destructor?); Discussion: which of the following do we need to implement Binary Search Trees?: navigation (GoToRoot, MoveLeft, MoveRight); insertion (InsertRoot, InsertLeft, InsertRight); deletion (DeleteRoot, DeleteLeft, DeleteRight); Miscellenia: IsEmpty, IsEmptyLeft, IsEmptyRight; Printing: Print and PrintCrt.
- To implement Printing you need to traverse the tree.

Ileana Streinu