GATE / CS ARCHIVE

GATE CSE 1996 / QUESTION 4(b)

Test a binary-search-tree probe sequence

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

GATE 1996, Q4(b) Descriptive
Report issue

Binary Search & Balanced Trees

Question 4(b), GATE 1996: A BST is searched for key 43. Determine whether the probe sequence 2, 3, 50, 40, 60, 43 can occur, and explain.
Question 4(b), GATE 1996: A BST is searched for key 43. Determine whether the probe sequence 2, 3, 50, 40, 60, 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 2, every later probe must lie in (2,+∞).
After 3, every later probe must lie in (3,+∞).
After 50, every later probe must lie in (3,50).
After 40, every later probe must lie in (40,50).
Probe 60 violates the inherited interval (40,50); 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