Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

NO ANSWERS FROM GOOGLE Write a program that reads the preorder and inorder trave

ID: 3530052 • Letter: N

Question

NO ANSWERS FROM GOOGLE Write a program that reads the preorder and inorder traversals of a binary tree, constructs an internal linked representation of the tree, and then outputs the corresponding postorder traversal. You must implement your own binary tree node and tree


input: DBACEGF

ABCDEFG (The program should read from the standard input two lines. The first line contains a string representing the preorder traversal of a binary tree, and the second contains a string representing the inorder traversal of the same tree. Nodes of the tree are identified by unique capital letters. )


output: ACBFGED

(Your program must print a string representing the postorder traversal of the tree followed by a newline character.)

Explanation / Answer

Please rate with 5 stars :)

Let us consider the below traversals:

Inorder sequence: D B E A F C
Preorder sequence: A B D E C F

In a Preorder sequence, leftmost element is the root of the tree. So we know