Path between nodes of a binary search tree

2

I need to create an algorithm that will define if a path between the value a and b are valid, my doubt is in relation to these rules, for example between node 3 and 7 there is a valid path, but between nodes 3 and 10 I would need to take a turn, does that still make it valid ?! and between nodes 1 and 7 there is also a valid path?!

    
asked by anonymous 14.10.2015 / 04:29

1 answer

2

It's probably an exercise, right? It is difficult to say whether something is valid without the context and rules that can be applied in this case.

The first question you should ask is if this tree supports navigation from a "child" (descending) element to its "parent" (ascending). Some data structures store only descendants and there would be no viable path between 3 and 10 .

However, if the search starts at the root of the tree, you can scroll through the tree twice, one by looking at 3 and another searching 10 . The path will be the combination of the two paths from the root.

Anyway, that's why I hate abstract college exercises.

    
14.10.2015 / 06:54