GATE / CS ARCHIVE

SIMILAR QUESTIONS / DATA STRUCTURES

Check BST search probes against ancestor bounds

5 questions solved the same way, newest first. Back to Data Structures

How these are solved

Maintain strict ancestor lower and upper bounds while following comparisons to target 43; reject first out-of-interval probe. Preserve five same-paper cases.

Descriptive
Report issue

Test a binary-search-tree probe sequence

Binary Search & Balanced Trees

Question 4(a), GATE 1996: A BST is searched for key 43. Determine whether the probe sequence 61, 52, 14, 17, 40, 43 can occur, and explain. GFG instead prints 11 in place of 17 at the fourth probe.
Question 4(a), GATE 1996: A BST is searched for key 43. Determine whether the probe sequence 61, 52, 14, 17, 40, 43 can occur, and explain. GFG instead prints 11 in place of 17 at the fourth probe.
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 61, every later probe must lie in (−∞,61).
After 52, every later probe must lie in (−∞,52).
After 14, every later probe must lie in (14,52).
After 17, every later probe must lie in (17,52).
After 40, every later probe must lie in (40,52).
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.

With 17 the sequence is valid. With 11 it is invalid, because after visiting 14 the search for 43 must stay in the right subtree of 14, whose keys exceed 14. The 11 variant therefore has the opposite answer.

Original paper, page 7

Descriptive
Report issue

Test a binary-search-tree probe sequence

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

Descriptive
Report issue

Test a binary-search-tree probe sequence

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

Descriptive
Report issue

Test a binary-search-tree probe sequence

Binary Search & Balanced Trees

Question 4(d), GATE 1996: A BST is searched for key 43. Determine whether the probe sequence 81, 61, 52, 14, 41, 43 can occur, and explain.
Question 4(d), GATE 1996: A BST is searched for key 43. Determine whether the probe sequence 81, 61, 52, 14, 41, 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 81, every later probe must lie in (−∞,81).
After 61, every later probe must lie in (−∞,61).
After 52, every later probe must lie in (−∞,52).
After 14, every later probe must lie in (14,52).
After 41, every later probe must lie in (41,52).
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

Descriptive
Report issue

Test a binary-search-tree probe sequence

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