Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We want to develop a method to reconstruct a binary tree from an inorder and preorder traversal sequence of the unknown tree. Please write a

We want to develop a method to reconstruct a binary tree from an inorder and preorder traversal sequence of the unknown tree. Please write a program, which lets the user input the inorder and preorder traversal sequences and from this reconstructs the corresponding binary tree and outputs it using the print() method.

Please note: - All nodes of the tree contain a single character and the inorder and preorder traversal sequences are strings formed by these characters in the corresponding order. - You can assume that all characters are different. The examples above have some duplicate characters but should still work if your implementation uses the indexOf method (i.e. uses the first occurrence of a character in a string). - Note that in our examples the reconstructed tree is a binary tree, but not a binary search tree - Please construct the tree using a list-of-list representation and use the supplied file. It has to write in python Example:

Binary Tree reconstructed:

Please enter the inorder sequence: abcdefghijklmn

Please enter the preoder sequence: hcabedgfkijnlm

[h, [c, [a, None, [b, None, None]], [e, [d, None, None], [g, [f, None, None], None]]], [k, [i, None, [j, None, None]], [n, [l, None, [m, None, None]], None]]]

Result:

image text in transcribed

Please write in python or other program. Thank you.

C a e n m f

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

Demystifying Databases A Hands On Guide For Database Management

Authors: Shiva Sukula

1st Edition

8170005345, 978-8170005346

More Books

Students also viewed these Databases questions

Question

5. What decision-making model would you advocate to this person?

Answered: 1 week ago

Question

6. What data will she need?

Answered: 1 week ago

Question

1. How did you go about making your selection?

Answered: 1 week ago