Assignment 7

Q1. The great tree-list recursion problem. A binary search tree and a circular doubly linked list are conceptually built from the same type of nodes - a data field and two references to other nodes. Given a binary search tree, rearrange the references so that it becomes a circular doubly-linked list (in sorted order). Nick Parlante describes this as one of the neatest recursive pointer problems ever devised. Hint: create a circularly linked list A from the left subtree, a circularly linked list B from the right subtree, and make the root a one node circularly linked list. Them merge the three lists. You do not need submit the solution for this problem. It is a reading assignment. Read the article at: http://cslibrary.stanford.edu/109/TreeListRecursion.html

Q2. BST reconstruction. Given the preorder traversal of a BST (not including null nodes), reconstruct the tree.

Q3. Write a function to check whether a binary tree is a binary search tree.

Q4. Write a function to check whether a binary search tree is "balanced". A balanced binary search tree satisfies the following condition: a tree is balanced if its left tree and right tree has height difference of at most one and both left tree and right tree are balanced.

Try to make your function as efficient as possible. Without careful coding, you may need to use two recursions: one to check balance and the other to compute the height. Try to merge the two into one.