As a very optional suggestion, consider how you might do this using the built-in predicate bagof/3.
Depth-first search will only need to keep around a maximum of 3 nodes as it only has to `remember' the path from the root node to the current position. On the other hand, breadth-first search will need to keep around up to 9 nodes when searching at the depth of three.
The figure, for depth-first search is usually given as (the depth
of the tree being searched) whereas the figure for breadth-first
search is given as
where
is the branching rate (a
measure of how many direct successors a node has) and
the depth of
the tree.
In the example, as is usually the case, the branching rate varies. It
is between 2 and 3. If we take it as 3 then we get .