COP4530 Fall 2004: Assignment 6
Due: 23 Nov 2004
1. 1. In the following questions, show the max-heap using
both, pointer and array representations, after each of the following sequence
of operations is completed.
(a)
Initialize a heap with
the following initial data: 5 6 4 2 8 1.
(b)
To the heap above:
push(5), push(9), push(1)
(c)
To the heap above:
pop(), pop()
2.
2. Show the state of
the binary search tree after the operations in (a) are complete, and also after
those in (b) are complete.
(a)
insert(9),
insert(4), insert(2), insert(7), insert(8), insert(5), insert(6)
(b)
delete(4),
delete(2)
(c)
Show the order in which
nodes are visited in a pre-order traversal of the tree in (a).
3.
3. Show the state of an
AVL tree after the operations in (a) are complete, and also after those in (b)
are complete.
(a)
insert(9),
insert(4), insert(2), insert(7), insert(8), insert(5), insert(6)
(b)
delete(4),
delete(2)
4. 4. We know that an inorder traversal of a binary search tree visits its nodes in
sorted order. However, an inorder traversal of a min-heap does not necessarily visit nodes in sorted order. In
fact, neither do the other three traversals that we discussed in class. We
might wonder if there is some other traversal taking O(N) time that visits the nodes of a min-heap in sorted
order. Either describe a linear time algorithm for visiting the nodes of a min
heap in sorted order, or prove that such a traversal does not exist. You may
use the fact that comparison based sorting requires W(N log N)
time.
5. 5. If we start at the root of a BST and keep taking the right child of each node (if the
right child is not null) until we can go no further, then prove that the last
node reached has the largest value among all nodes in the BST.