Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL 10 High Performance Expert Techniques For Query Optimization High Availability And Efficient Database Maintenance

Authors: Ibrar Ahmed ,Gregory Smith ,Enrico Pirozzi

3rd Edition

1788474481, 978-1788474481

More Books

Students also viewed these Databases questions