Why is it impossible to build a binary tree with rounds of pre-order, mail order and order level?

Considering:

  • Pre order.
  • Bypass after order.
  • Level bypass.

You cannot construct a binary tree with 12 or 23 or 31, or even if 123 are given! Why is this? and why is InOrder Traversal important for creating the source tree?

+4
source share
1 answer

We cannot build a tree without going around the order. What for? Say you are given only preliminary and post-orders. A simple example is shown below.
Consider two different trees,

TREE 1:

root=a;  
root->left=b;  
root->left->right=c;  

Tree 2:

root=a;  
root->right=b;  
root->right->left=c;  

Both trees are different from each other, but have the same sequence of preliminary and subsequent orders.

pre-order - a b c  
post-order - c b a  

, , .

, , , . , , node, , "" .

Post-order, , , . , , node, , "" .

In-order, , - , root, , , ( ), , , . ( )

. , , .
. , , , - , .

+5

Source: https://habr.com/ru/post/1611147/


All Articles