I\'m looking at an interview book and the question is:
You have two very large binary trees:
T1, with millions of nodes, andT2
Here is a counter-example to the method.
Consider the tree T1:
B
/ \
A D
/ \
C E
\
F
And the sub-tree T2:
D
/ \
C E
The relevant traversals are:
T1 pre-order: BADCEFT2 pre-order: DCET1 in-order: ABCDEFT2 in-order: CDEWhile DCE is in BADCEF and CDE is in ABCDEF, T2 is not actually a sub-tree of T1. The author's definition of sub-tree must have been different or it was just a mistake.
Related question: Determine if a binary tree is subtree of another binary tree using pre-order and in-order strings