GATE / CS ARCHIVE

GATE CSE 1991 / QUESTION 4(iii)

Optimal search tree for three equally likely identifiers

Data Structures · Binary Search & Balanced Trees · Full GATE CSE 1991 paper

GATE 1991, Q4(iii) 2 marks · Descriptive
Report issue

Binary Search & Balanced Trees

Question 4(iii), GATE 1991: Construct an optimal binary search tree for ordered identifiers if, stop, while with equal successful-search probabilities.
Question 4(iii), GATE 1991: Construct an optimal binary search tree for ordered identifiers if, stop, while with equal successful-search probabilities.
Tap to enlarge
Answer & solution

Answer: Root stop; left child if; right child while (no official key was published)

The alphabetic order is if<stop<while. Placing the middle identifier at the root preserves search-tree ordering with the other two as its children. Successful search takes one comparison at the root and two at either child, for mean (1+2+2)/3=5/3. Any endpoint root forces the remaining two into one subtree, creating depths corresponding to comparison counts 1, 2, 3 and mean 2. Thus the balanced tree is optimal. The calculation uses equal successful-search probabilities; unspecified unequal unsuccessful-search gap weights would define a different optimization problem.

Original paper, page 5