This preview shows page 1. Sign up to view the full content.
Unformatted text preview: p.88 3.21 Write routines to implement two stacks using only one array. Your stack routines should not declare an overflow unless every slot in the array is used. p.88 3.26 A "deque" is a data structure consisting of a list of items, on which the following operations are possible: Push(X,D): Insert item X on the front end of deque D. Pop(D): Remove the front item from deque D and return it. Inject(X,D): Insert item X on the rear end of deque D. Eject(D): Remove the rear item from deque D and return it. Write routines to support the deque that take O(1) time per operation. p.143 4.35 Write a routine to list out the nodes of a binary tree in "level-order". List the root, then nodes at depth 1, followed by nodes at depth 2, and so on. You must do this in linear time. Prove your time bound. p.144 4.42 Two trees, T1 and T2, are "isomorphic" if T1 can be transformed into T2 by swapping left and right children of (some of the) nodes in T1. For instance, the two trees in Figure 4.63 are isomorphic because they are the same if the children of A, B, and G, but not the other nodes, are swapped. a. Give a polynomial time algorithm to decide if two trees are isomorphic. *b. What is the running time of your program (there is a linear solution)? Figure 4.63: A___ A___ / \ / \ B C C B / \ / / / \ D E G G E D / / \ / F H H F p.145 4.45 Since a binary search tree with N nodes has N+1 NULL pointers, half the space allocated in a binary search tree for pointer information is wasted. Suppose that if a node has a NULL left child, we make its left child point to its inorder predecessor, and if a node has a NULL right child, we make its right child point to its inorder successor. This is known as a "threaded tree" and the extra pointers are called "threads". a. How can we distinguish threads from real children pointers? b. Write routines to perform insertion and deletion into a tree threaded in the manner described above. c. What is the advantage of using threaded trees? ...
View Full Document
This note was uploaded on 02/16/2011 for the course CS 136 taught by Professor Yuechen during the Winter '08 term at Zhejiang University.
- Winter '08