Pre-order – 1 2 3 4 5 6 7
In-order – 4 2 5 1 6 3 7
Post-order – 4 5 2 6 7 3 1
Answer: To create a tree form traversing sequence we compare pre-order and in-order or post-order and in-order.
- First take one item form pre-order (1), make it root (in in-order traverse 1st item is always is root)
- Choose 2nd item (2), check this item in in-order traverse where it is; left or right side, make child of root as its position in in-order.
- Now take next item (3), again check its position in in-order traverse, put in tree as its position.
0 comments:
Post a Comment