Consider two algorithms for traversing a binary tree. Both are nonrecursive algorithms that use an extra ADT for bookkeeping. Both algorithms have the following basic form:
Put the root of the tree in the ADT
while (the ADT is not empty) {
Remove a node from the ADT and call it n
Visit n
if (n has a left child) {
Put the child in the ADT
} //end if
if (n has a right child) {
Put the child in the ADT
} //end if
} //end while
The difference between the two algorithms is the mediod for choosing a node n to remove from the ADT.
Algorithm 1: Remove the newest (most recently added) node from the ADT.
Algorithm 2: Remove the oldest (earliest added) node from the ADT.
a. In what order would each algorithm visit the nodes of the tree in Figure ?
b. For each algorithm, describe an appropriate ADT for doing the bookkeeping. What should the ADT data be? Do not use extra memory unnecessarily for the bookkeeping ADT. Also, note that the traversal of a tree should not alter the tree in any way.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.