 # Prolog tree program

Hi everyone, can someone help me with this question please :

The empty binary tree will be represented by the abvide constant symbol.

A non-empty binary tree will be of the form ab (label, left_sub_tree, right_sub_tree).

Defining the flattened predicate / 2 which is such that flattened (A, L) is true if the list L is the set of labels of a binary tree A. (The order of the elements in the list L is irrelevant.)

Example: flattened (ab (a, ab (1, abvide, ab (a, abvide, abvide)), abvide), [a, 1, a]) is true.

Your homework is asking you to walk the binary tree and collect the terminal label values from it.
This is an exercise in tree walking and accumulator passing.

First figure out how to walk the tree. You have in-order, pre-order, post-order to choose from. The question says final order doesn’t matter so find out what they mean and do the simplest one. In all honesty there is not much between them.

Think of base case and recursive cases when walking the tree.

As a first step, work out how to walk the tree and print out each node.

Good luck 