We all know that different binary trees can have the same inorder, preorder, or postorder traversal. But if we were to include null
elements into a preorder traversal, then result of the traversal would be unique as long as the trees are unique. Consider these two trees:
3 3
/ \
4 vs. 4
Their normal preorder traversal would be {3,4}
for both, but if we were to include null
elements, then their traversal would be {3,4,null,null,null}
and {3,null,4,null,null}
respectively, making the traversal unique.
My question is, would this be true for inorder and postorder traversals as well? And how can we prove it?