Tree
A tree is a data structure that consists of nodes, where each node has a value and links to its children nodes. Compared to a linked list, each node might link to many children.
Depth first search (DFS)
DFS goes as deep as it can along one child before it moves on to the next one.
When we visit the node before its children, it is called a pre-order traversal. When we visit the node after its children, it is called a post-order traversal.
The traversal can be implemented recursively with a function that calls itself for every child.
Pre-order traversal
Post-order traversal
Breadth first search (BFS)
BFS visits the tree level by level: first the root, then all its children, then all their children, and so on.
It adds each node's children to a queue, and visits the nodes from it in order, so a level is finished before the next one starts.
Build it
Implement pre_order, post_order and level_order in the class below.