I see several messages on how to determine if two trees are the same in terms of its structure, but have not found an answer on how to find whether two trees are the same in terms of content.
Let's say a node tree is defined as follows.
TreeNode {
string data;
TreeNode* left;
TreeNode* right
};
Now I have two binary trees and I need to find out if the two trees are the same in content. The two cannot be structurally identical, and we cannot assume that the data row is identical in words.
For example, we can have two trees. These two trees can be considered identical in terms of content when we take a walk. To be clear, when we concatenate all node strings from these two trees, they are the same. i.e. abcdedfg
(abc)
| \
(d) (efg)
(a)
| \
(b) (cdefg)
, inorder, , , , , - . , , , , .
.