0

In a binary search tree if you are along a certain search path, what keys are considered to be on the left of the path and which on the right?

For example if my tree is :

              25
      12             30
   10    15       28   32
       14  20

And lets say my current search path is 20->12->15->20.

1) Are both 10 and 14 considered to be on the left of this search path or is only 10?

2) Also are all 3 numbers 30, 28 and 32 considered on the right of the search path?

user1782677
  • 1,963
  • 5
  • 26
  • 48

1 Answers1

2

Assuming you meant the path 25-12-15-20, I would say both 10 and 14 are left of this path. That's because in order to find either of them, you have to backtrack up the tree (to either 15 or 12) and take a left branch where the path goes right.

Same deal for the three numbers 30, 28 and 32. Since you have to backtrack up to 25 and then go right instead of left, they can be considered on the right of that path:

enter image description here

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953