Computer Science, asked by anithamurimuri, 3 months ago

Constructabinarytreehavingthefollowingtraversalsequences:

Preordertraversal:ABCDEFGHI

Inordertraversal:BCAEDGHFI

Answers

Answered by sheefaParveen04
0

Answer:

Construct Tree from given Inorder and Preorder traversals

Let us consider the below traversals:

Inorder sequence: D B E A F C

Preorder sequence: A B D E C F

Recommended: Please solve it on “PRACTICE” first, before moving on to the solution.

In a Preorder sequence, leftmost element is the root of the tree. So we know ‘A’ is root for given sequences. By searching ‘A’ in Inorder sequence, we can find out all elements on left side of ‘A’ are in left subtree and elements on right are in right subtree. So we know below structure now.

Similar questions