codeintuition-logo

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 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. 

Liking the course? Check our discounted plans to continue learning.