Depth-First Order: Recursive Default
Depth-first search ( DFS) is so named because the recursion goes deep in the tree before it goes across. The diagram shows the order in which nodes are examined.
Sometimes, the search will quit and return an answer when a node is either a terminal failure node or a goal node. In other cases, the entire tree will be traversed.
A stack composed of stack frames is used to contain variables of the current node and all of its ancestors, back to the top of the tree. This stack will grow and contract as the tree is traversed, with a maximum stack size equal to tree depth.
Depth-first search is often preferred because of its low O(log(n)) storage requirement. We will never run out of storage in any reasonable amount of computer time.
A recursive program typically uses a depth-first order.