# Tree - Order

The term tree order describes how a tree is traversed.

It can also be a graph data structures, selecting an arbitrary node as the root.

## 3 - Type

           h
/  |  \
/    |   \
d      e    g
/|\          |
/ | \         f
a  b  c

The traversals are classified by the order in which the nodes are visited:

• breadth-first order (hdegabcf). Breadth-first_search - All the nodes of depth 0 are returned, then depth 1, then 2, and so on.
• closest-first order (degcfab)
• depth-first order
• pre-order left (h d a b c e g f),
• pre-order right (h g f e d c b a)
• post-order left (a b c d e f g h),

Not for a tree (directed algorithm)

## 4 - Example

### 4.1 - Java

/* Node is an object of your implementation with a getChildren function */
TreeTraverser<Node> traverser = new TreeTraverser<Node>() {
@Override
return node.getChildren();
}
};
Node root = ....

Then you can iterate over the tree with a for loop:

for (Task task : traverser.breadthFirstTraversal(root)) { ... }
for (Task task : traverser.preOrderTraversal(root)) { ... }
for (Task task : traverser.postOrderTraversal(root)) { ... }