Computer Science, asked by ponipireddykumari, 17 days ago

ii) Draw a Binary Tree by following given traversals:
Pre-order: G B Q A C K F P D E R H
In-order: Q B K C F A G P E D H R​

Answers

Answered by ramalingam51g
4

Answer:

a Binary Tree by following given traversals:

Pre-order: G B Q A C K F P D E R H

In-order: Q B K C F A G P E D H R

Answered by ruchibs1810
1

Answer:

Frankly a binary tree can be drawn from the given pre-order and in-order traversals by taking the first element of the pre-order traversal as the root, finding its index in the in-order traversal, and recursively constructing the left and right subtrees.

Explanation:

To draw a binary tree from the given traversals, we can use the following steps:

The first element of the pre-order traversal is the root of the tree.

Find the index of the root element in the in-order traversal. All elements to the left of this index will be in the left subtree and all elements to the right will be in the right subtree.

Recursively apply steps 1 and 2 to the left and right subtrees until all elements have been processed.

Using these steps, we can draw the following binary tree:

       G

      / \

     /   \

    /     \

   B       R

  / \     / \

 Q   A   H   E

    / \     /

   C   K   D

      / \

     F   P

Indeed note that this is not the only possible binary tree that can be constructed from the given traversals, but it is one valid solution.

Learn more about binary tree: https://brainly.in/question/54461719

Learn more about traversals: https://brainly.in/question/6623043

#SPJ3

Similar questions