Question: Should be done in java and you can use any structure.... thanks 2. [Adapted from the Valladolid archives] Consider binary trees whose nodes are labeled

 Should be done in java and you can use any structure....Should be done in java and you can use any structure.... thanks

2. [Adapted from the Valladolid archives] Consider binary trees whose nodes are labeled with single digits and letters (upper- and lowercase, case-sensitive). Given the preorder (root, left subtree, right subtree) node order and the inorder (left subtree, root, right subtree) node order for the same tree, it is possible to reconstruct the tree, assuming no two nodes in the tree have the same label. For example, given the preorder traversal order "DBACEGF" and the inorder traversal order ABCDEFG, you can compute that the tree these corne from is A C G You are to write a program to do this reconstruction on any such tree. The input consists of one or more cases in free format. Each case consists of two non-empty strings PRE and IN, representing the preorder traversal and inorder traversal of a non-empty binary tree, and consisting of letters and digits. Case is significant. For each test case, print the reconstructed tree's postorder traversal (left subtree, right subtree, root), using the format shown in the example. Example: Input Output DBACEGF Case 1: ACBFGED ABCDEFG BCAD CBAD Case 2: CDAB

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!