Hello. Tell me, please, how to find in the tree the number of branches from the root to the given vertex.
Used tree:
( 3 ) / \ / \ ( 2 ) ( 5 ) / \ \ / \ \ ( 1 ) ( 2 ) ( 8 ) / / ( 9 )
Recursive tree pass code:
domains treetype = tree(integer, treetype, treetype); empty() predicates traverse(treetype) clauses traverse(empty). traverse(tree(Name, Left, Right)) :- write(Name,'\n'), traverse(Left), traverse(Right). goal traverse(tree(3, tree(2, tree(1, empty, empty), tree(2, empty, empty)), tree(5, empty, tree(8, tree(9, empty, empty), empty)))).
You need to somehow add the code so that it can count the number of branches. For example, between point 3 and 9, the result should be output 3. Between 3 and 8, the result should display 2.
Thank you in advance.