Explore BrainMass
Share

# Binary Tree Data Structure Questions using C++ and STL

Binary Trees:
10.26

Use the following tree, in its original from, for each part of this question:

----
See Attached.

---

(a). If the value 33 is inserted into the tree, which node would be its parent?
(b). If the value 72 is inserted into the tree, which node would be its parent?
(c). If the root node 50 is deleted, the erase algorithm selects which node as the replacement node?
(d). If the node 30 is deleted, the erase algorithm selects which node as the replacement node?
(e). Traverse the tree, and list the nodes, via a preorder scan.
(f). Traverse the tree, and list the nodes, via an inorder scan.
(g). Traverse the tree, and list the nodes, via an postorder scan
(h). Traverse the tree, and list the nodes, via an level-order scan

#### Solution Preview

(a). If the value 33 is inserted into the tree, which node would be its parent?

Starting at the root we can find where 33 should go. Since 33 is less than 50 it must go on the left-hand subtree. Since it is greater than 25 it goes to the right child of the 25 node. Since 33 is less than 35 it goes to the left. And finally, since 30 is a leaf node, 33 is added below it. So the parent for 33 is 30.

(b). If the value 72 is inserted into the tree, which node would be its parent?

Using the same method as above we find ...

#### Solution Summary

This solution provides detailed answers to several questions related to a binary tree. This includes tree inserts, deletes, and various tree traversals.

\$2.19