If in-order traversal of two binrary trees (not binary search trees) are the same, does it guarantee that the two trees are the same?
if answer is no, then what about both in-order and pre-order traversal are the same?
Solution Breakdown Two trees 'A' and 'B' are identical if: data on their roots is the same or both roots are null. left sub-tree of 'A' is identical to the left sub-tree of 'B' right sub-tree of 'A' is identical to the right sub-tree of 'B'
Two binary trees are identical if: their root nodes have the same value, their left subtree is identical, their right subtree is identical.
Definitely not. The two trees
b
/ \
a d
/ \
c e
and
d
/ \
b e
/ \
a c
both have an inorder traversal of a b c d e
. They are, in fact, rotations, an operation which preserves inorder traversal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With