What would be the efficient algorithm to find if two given binary trees are equal - in structure and content?
Since it's a proven fact that - it is possible to recreate a binary tree as long as we have the following:
If two binary trees have the same in-order and [pre-order OR post-order] sequence, then they should be equal both structurally and in terms of values.
Each traversal is an O(n) operation. The traversals are done 4 times in total and the results from the same-type of traversal is compared. O(n) * 4 + 2 => O(n) Hence, the total order of time-complexity would be O(n)