Saint Louis University |
Computer Science 180
|
Dept. of Math & Computer Science |
Topic: Trees
Related Reading: Ch. 7.
Most relevant for these questions will be 7.2.2, 7.2.3, and 7.3.6.
Due:
Wednesday, 9 April 2014, 10:00am
For this assignment, you must work individually.
Please make sure you adhere to the policies on academic integrity in this regard.
For the tree in Figure 7.11 (on page 285), what order will nodes be visited during a postorder traversal?
Draw a (proper) binary tree T such that simultaneously,
The structure of a tree cannot be unambiguously reconstructed having only a preorder listing of its contents. Therefore, the output of the preorderPrint function on page 279 cannot be used to ambiguously reconstruct the tree. They suggest the parenPrint method on page 280 as a way to represent the structure of a tree unambiguously.
However, for a proper binary tree the preorder listing of the contents does suffice if we also designate whether each node is internal or external. That is, consider the following pseodocode:
void dump(const BinaryTree& T, const Position& p) { if (p.isExternal()) cout << "0 " << *p << endl;; else { cout << "1 " << *p << endl;; dump(T, p.left()); dump(T, p.right()); } }Draw a picture of the tree represented by the following output of such a dump.
1 A 1 B 0 C 1 D 0 E 0 F 1 G 1 H 0 I 0 J 0 K
Creativity Exercise C-7.18(b) on page 315 of the text. Note well, you only need to do part (b) of that problem, producing a new rendering of the tree from Figure 7.20
Creative Exercise C-7.25 on page 316 of the text.