Answered step by step
Verified Expert Solution
Question
1 Approved Answer
S O UCIOIULILEIL. 3. (5 pts.) Suppose a binary tree T has ten nodes and they are labeled 1,2,..., 10. We ran the inorder and
S O UCIOIULILEIL. 3. (5 pts.) Suppose a binary tree T has ten nodes and they are labeled 1,2,..., 10. We ran the inorder and postorder traversals on T and the nodes were processed in the following order: inorder traversal: 3,1,2,10, 4.6,5,9, 8,7 postorder traversal: 1.2,3,4,5, 6, 7, 8, 9, 10 al. What is the root node of T'? Which nodes are on the left and right subtrees of the root node of T? a2. Draw I' with its nodes labeled. Let's generalize. Suppose T is a binary tree with n nodes labeled 1, 2, ... n. The ar- rays I 1...n and P1...n store the order in which the nodes are traversed in an in- order traversal and postorder traversal of T respectively. Thus, in the above example, I[1..., 10) = (3, 1, 2, 10,4,6,5,9, 8, 7] while P[1...10] = [1,2,3,4,5,6,7,8,9,10). b. Given arrays Il...n and P[1...n), design an algorithm that outputs the binary tree T. The output should be an array T[1 ...n], where T[i] stores the parent of the node labeled i. Explain how your algorithm works. What is the running time of your algorithm? (Hint: Do a recursive algorithm.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started