<< Previous exercise (2.62) | Index | Next exercise (2.64) >>
a. both procedures produce the same results. because they both are inorder-traversal.
b. assume n is the number of nodes in the tree, T(n) is the total time costed by the procedure.
for tree->list-1:
T(n) = 2*T(n/2) + O(n/2) (considering the procedure "append")
solved above equation, T(n) = O(n*logn)
for tree-list-2:
T(n) = 2*T(n/2) + O(1)
we can get T(n) = O(n)
a. The trees shown in figure 2-16 can be written as:
Using either function, the trees all evaluate to the same list:
b. The first function is of O(n log n) complexity.
The second function is of O(n) complexity.