CS 112
Lecture 20
Today's topics
- 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.
- Memory leaks and dangling pointers.
- Destructors, and what they do.
Example for the Stack. Discussion.
- Discussion: the BTree destructor.
- Lab: implement destructor and tree traversal functions in the
BTree class.
- Extra credit: 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.
- Discussion, and informal homework (preparation for exam):
old final exam.
Ileana Streinu