In all cases a parent pointer eliminates the need for a stack to traverse the tree. However, parent traversals require at least one extra bit per node to keep track of revisits, which is an O(n) amount of extra space for a tree with n nodes vs odrlgn() extra space for a stack (assuming a balanced tree; O(n) stack space otherwise).
All the values in the left child of the root of a binary-search are less than (let us say) the value at the root and all the values in the root's right child are at least the root's value. All the values of both children of the root of a heap are at least (let us say) the root's value. If T is both a heap and a binary search tree, it must be the T has no left child because otherwise the heap property would be violated.
A heap is balanced; that is, the absolute difference between the heights of the children of a node is at most 1. Because T is a heap and has no left child, it either has no right child or its right child is a leaf.
Because T has one or two nodes, the worst-case search time is constant.
Heap node i's children are at 2i + 1 and 2(i + 1); that is, they are adjacent to one another in the array. Heap node i's sibling's children are laid out adjacent to node i's children via their common parent at 2(i - 1) (because node i has a sibling, it can't be the root and must have a parent). Children of nodes at a particular level are laid out adjacent to one another on the next level, filled in from to left to right. Not only does this balance the heap, it left balances it because there are not gaps in the occupied array elements.
Label each node in the tree with the amount of money in each wallet ($10 or 0). Your initial pick is indicated by an under bar; your colleague's response is indicated by an over bar; a double under bar indicates your changed choice.
If you don't change, you have a one in three chance of picking the right wallet; if you do change you have a two in three chance. Your odds are better if you change your mind (remember, the more you know, the smarter your choice).
This page last modified on 10 April 2006.