Lab 12, Task 5 -------------- 1. The tree from Task 1 is *not* a search tree. One way that we know this is that an inorder traversal does *not* visit the keys in alphabetical order. We can also point out places in which the search tree in equalities don't hold: * D and A are both less than E, but they are in E's right subtree when they should be in its left subtree. * F is less than both G and H, but it is in their right subtrees when it should be G's left subtree. 2. The tree from Task 1 is *not* balanced, because the subtree of which H is the root is not balanced: * H's left subtree is empty, which means its height is -1. * H's right subtree has a height of 1. * Thus, the heights of its two subtrees differ by more than 1, and it is not balanced. The tree that results from the insertions in Task 2 *is* balanced: * Node 15: both subtrees have a height of 2 * Node 10: left subtree has a height of 1, right subtree a height of 0 * Node 6: left subtree has a height of -1, right subtree a height of 0 * Node 23: both subtrees have a height of 2 * Nodes 20 and 35: left subtrees have a height of 0, right subtrees -1 * Nodes 9, 13, 18, 24: leaf nodes in which both subtrees are height -1 3. In order for 30 to be the root of the tree, it must be inserted first. The order of the next two insertions doesn't matter. That's because one of the two keys (the 45) is greater than 30, and the other key (the 15) is less than 30. As a result, inserting these two items in either order won't affect where they end up: 45 as the right child of 30, and 15 as the left child of 30. Thus, this sequence of insertions will produce the same tree: insert 30, insert 15, insert 45 To make 15 the root, we can put its insertion first. And because the 30 and 45 are both greater than 15, the order of their insertions will matter: * insert 15, insert 30, insert 45 gives one tree with 15 at the root * insert 15, insert 45, insert 30 gives another tree with 15 at the root To make 45 the root, we can put its insertion first. And because the 30 and 15 are both less than 45, the order of their insertions will matter: * insert 45, insert 30, insert 15 gives one tree with 45 at the root * insert 45, insert 15, insert 30 gives another tree with 45 at the root