GATE / CS ARCHIVE

GATE CSE 1996 / QUESTION 4(e)

Test a binary-search-tree probe sequence

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

GATE 1996, Q4(e) Descriptive
Report issue

Binary Search & Balanced Trees

Question 4(e), GATE 1996: A BST is searched for key 43. Determine whether the probe sequence 17, 77, 27, 66, 18, 43 can occur, and explain.
Question 4(e), GATE 1996: A BST is searched for key 43. Determine whether the probe sequence 17, 77, 27, 66, 18, 43 can occur, and explain.
Tap to enlarge
Answer & solution

Answer: Impossible. (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 17, every later probe must lie in (17,+∞).
After 77, every later probe must lie in (17,77).
After 27, every later probe must lie in (27,77).
After 66, every later probe must lie in (27,66).
Probe 18 violates the inherited interval (27,66); the sequence is impossible.

The violated bound comes from an earlier ancestor. A later comparison cannot discard it: every node subsequently visited remains inside that ancestor’s chosen subtree. No choice of unvisited nodes can repair this path.

Original paper, page 7