Search code examples
data-structureslanguage-agnosticbinary-search-tree

Find possible routes to locate a number in a tree


Prompt :
Assuming there is a binary search tree that stores the integers from 1 to 1000 and we are looking for the number 363. Which of the following sequences of nodes CANNOT be applied to the tree?
a. 2,252,401,398,330,344,397,363
b. 924,220,911,244,898,258,362,363
c. 925,202,911,240,912,245,363
d.2,399,387,219,266,382,381,278,363
d. 2 ,399,387,219,266,382,381,278,363
e. 935,278,347,621,299,392,358,363

Thanks for any help.I really need it.


Solution

  • The problem will be in the last option (e) wherein the binary search property gets violated - it doesn't hold for nodes 347 and 299 since 621 is a right child of 347, all nodes to the right of 347 are supposed to be greater than itself, but 299 isn't.

    Hope the below image clarifies.

    The binary search property doesn't hold for the nodes 347 and 299