Hi,
How can I write a predicate for tree_height(Tree,Height) that binds Height to the number of nodes on the longest path from the root to a leaf in a binary tree. Trees are represented either "empty" or as "tree(L,Data,R)", where L and R are the left and right are the left and right subtrees. Trees must be instantiated at the time of the call.
Example:
:tree_height(tree(tree(empty,,a,empty),b,tree(empty,c,tree(empty,d,empty))),Z)
Z=3
It is quite complicated for me to solve. Any idea? Thanks.
Kind Regards,
Yupar
How can I write a predicate for tree_height(Tree,Height) that binds Height to the number of nodes on the longest path from the root to a leaf in a binary tree. Trees are represented either "empty" or as "tree(L,Data,R)", where L and R are the left and right are the left and right subtrees. Trees must be instantiated at the time of the call.
Example:
:tree_height(tree(tree(empty,,a,empty),b,tree(empty,c,tree(empty,d,empty))),Z)
Z=3
It is quite complicated for me to solve. Any idea? Thanks.
Kind Regards,
Yupar