Science, asked by wwwaryajain4786, 11 months ago

If you are given two traversal sequences, can you construct the binary tree?

Answers

Answered by itzlisa91331
1

It depends on what traversals are given. If one of the traversal methods is Inorder then the tree can be constructed, otherwise not.

Mirror

Therefore, following combination can uniquely identify a tree.

Inorder and Preorder.

Inorder and Postorder.

Inorder and Level-order.

And following do not.

Postorder and Preorder.

Preorder and Level-order.

Postorder and Level-order.

For example, Preorder, Level-order and Postorder traversals are same for the trees given in above diagram.

Preorder Traversal = AB

Postorder Traversal = BA

Level-Order Traversal = AB

So, even if three of them (Pre, Post and Level) are given, the tree can not be constructed.

Attachments:
Answered by steffiaspinno
0

Yes, if tranversals are provided

Explanation:

It all relies on the traversals that are provided. The tree can be created if one of the traversal techniques is Inorder; otherwise, it cannot.

Mirror

As a result, the following combination may be used to identify a tree.

There are two types of orders: in-order and pre-order.

There are two types of orders: in-order and out-of-order.

The terms "inorder" and "level-order" are used interchangeably.

And those who come after do not.

There are two types of preorders: postorder and preorder.

Pre-orders and Level-orders are both available.

The terms "postorder" and "level-order" are used interchangeably.

For the trees shown in the diagram, Preorder, Level-order, and Postorder traversals are all the same.

Traversal Traversal Traversal Traversal Traversal Traversal Traversal Travers

BA = Postorder Traversal

Traversal of Levels = AB

As a result, even if three of them are supplied (Pre, Post, and Level), the tree cannot be built.

Similar questions