Did you know ... Search Documentation:
Pack prolog_library_collection -- prolog/tree.pl
PublicShow source

Support library for working with tree data structures.

A tree is represented by a compound term with the following components:

  • Label :: A (compound) term that describes the relationship between the Parent node and the Children subtrees.
  • Parent :: A (compound) term that represents the parent node.
  • Children :: A list of trees. Empty if Parent is a leaf node.

Here are some examples of tree terms:

tree(leaf, 'Electra', [])

     [tree(leaf, 'Electra', []),
      tree(leaf, 'Orestes', [])])

tree('Modus ponens',
     'Socrates is mortal',
     [tree(premise, 'Sorcrates is a man', []),
      tree(premise, 'Men are mortal', [])])
- Wouter Beek
- 2021-03-18
 depth(+Tree:compound, +Depth:nonneg) is semidet
depth(+Tree:compound, -Depth:nonneg) is det
Succeeds for the Depth of the Tree.

The depth of a tree is defined inductively:

  • 0 for leaf nodes.
  • 1 plus the maxium of the depth of the children.
 shortest(+Trees:list(compound), +Tree:compound) is semidet
shortest(+Trees:list(compound), -Tree:compound) is det
Succeeds if Tree is the shotests of Trees.