Let be the set of all integers from to . Consider any order of insertion of the elements of into a binary search tree that creates a complete binary tree.
Which one of the following elements can NEVER be the third element that is inserted?
View worked solution
Answer: D
A complete binary tree with nodes is a perfect binary tree of height . Since it is a Binary Search Tree (BST) containing the keys to , its structure is uniquely determined by the sorted order of the keys:
- Level 0 (Root):
- Level 1: (left child of ), (right child of )
- Level 2:
- Children of : and
- Children of : and
- Level 3 (Leaves):
- Children of : and
- Children of : and
- Children of : and
- Children of : and
For any element to be inserted into the BST, all of its ancestors must be inserted before it. Let's analyze the options:
- To insert : Ancestor is . Insertion sequence can be: (where is ).
- To insert : Ancestors are and . Insertion sequence can be: (where is ).
- To insert : Ancestors are and . Insertion sequence can be: (where is ).
- To insert : Ancestors are , , and . All three of these must be inserted before . Thus, can be inserted at earliest as the element.
Therefore, can never be the third element inserted.
Free practice · Your answers on this page are not saved.
