5 O& h/ E: }) a% a
not really, think about the case: the first tree is [1, 2, 3, 4, #, #, 5], the second one is [6, 2, 3, 4, #, #, 5], the left and right subtrees are both largest common sub-structs with two nodes, the algs you propose will return a tree whose inorder sequence is [4, 2, 3, 5], preorder sequence is [2, 4, 3, 5], thus construct a tree of [2, 4, 3, #, #, #, 5] |