Understanding construction from a sorted array
We know that the inorder traversal of a binary search tree generates a sorted sequence. However, reconstructing a height-balanced binary search tree (a tree where, for every node, the heights of its left and right subtrees differ by at most one) from this sorted sequence is also possible. This is only true for a binary search tree because of its special properties.
Resolving ambiguity
Using just the inorder traversal sequence to reconstruct a generic binary tree is impossible. We cannot identify the root by looking at the inorder traversal sequence. This ambiguity is generally resolved by using either the preorder or postorder traversal sequence in tandem with the inorder sequence, as for them, the position of the root is always at the beginning or the end, respectively.
Ambiguity in tree construction just from inorder traversal sequence
This means that for reconstructing a binary tree from the inorder traversal sequence, the other sequence(preorder or postorder) is just used to identify the location of the root node for every subtree.
Liking the course? Check our discounted plans to continue learning.