GATE / CS ARCHIVE

GATE CSE 1996 / QUESTION 4(c)

Test a binary-search-tree probe sequence

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

GATE 1996, Q4(c) Descriptive
Report issue

Binary Search & Balanced Trees

Question 4(c), GATE 1996: A BST is searched for key 43. Determine whether the probe sequence 10, 65, 31, 48, 37, 43 can occur, and explain.
Question 4(c), GATE 1996: A BST is searched for key 43. Determine whether the probe sequence 10, 65, 31, 48, 37, 43 can occur, and explain.
Tap to enlarge
Answer & solution

Answer: Possible. (no official key was published)

A search path obeys every ancestor constraint, not merely the immediately preceding comparison. Maintain an open interval of permissible keys, initially (−∞,+∞). When a probe is below 43, searching right raises the lower bound to that probe. When a probe is above 43, searching left lowers the upper bound.

After 10, every later probe must lie in (10,+∞).
After 65, every later probe must lie in (10,65).
After 31, every later probe must lie in (31,65).
After 48, every later probe must lie in (31,48).
After 37, every later probe must lie in (37,48).
The final probe is 43, so the search succeeds.

All probes meet the bounds. A witnessing BST can be built as a chain with these keys, taking the left or right child according to each comparison with 43. Thus the bound test proves existence, rather than just failing to find an error.

Original paper, page 7