I am reading the tour of Go, it has a problem of equivalent binary tree. The article said A function to check whether two binary trees store the same sequence is quite complex in most languages.
https://tour.golang.org/concurrency/7
I am a little confused, could we just use any traversal method like inorder traversal the tree and verify the resulted sequence is same. I think it is pretty simple. Anyone could let me know if my understanding is wrong?
It's implicit in the problem definition that you're comparing whether two binary search trees contain the same multiset of elements, and while an in-order of a BST will give you the elements in sorted order, the same is not true of any other traversal. E.g. the tree ¹\₂ has preorder 12 while the tree ₁/² has preorder 21, despite that both contain the same elements.