Depth-first[edit]
See also: Depth-first search
There are three types of depth-first traversal: pre-order,[1] in-order,[1] and post-order.[1] For a binary tree, they are defined as operations recursively at each node, starting with the root node as follows:Pre-order[edit]
- Visit the root.
- Traverse the left subtree.
- Traverse the right subtree.
In-order (symmetric)[edit]
- Traverse the left subtree.
- Visit root.
- Traverse the right subtree.
Post-order[edit]
- Traverse the left subtree.
- Traverse the right subtree.
- Visit the root.
Breadth-first[edit]
See also: Breadth-first search
Trees can also be traversed in level-order, where we visit every node on a level before going to a lower level.
没有评论:
发表评论