GO code

output

Is tree2 a subtree of tree1? true
Is tree3 a subtree of tree1? false

big-O time

O(A+B)

A : the number of nodes in the main tree
B : the number of nodes in the sub tree

Updated: