There are two kinds of traversal for (binary) trees: Depth First Search(DFS) and Breadth First Search(BFS). Depth First Search visits the tree by proceeding deeper and deeper until it reaches the leaf nodes, including pre-order, in-order, post-order tree traversal. DFS uses a data structure called Stack.
Breadth First Search is the most natural solution for level-order traversal, since it visits the nodes level by level. BFS requires the use of a data structure called Queue, which is a First In First Out (FIFO) structure.
For the complete C++ source code used in this article, please refer to: https://github.com/bo-yang/BinaryTree.
- Data Structure
- Build Binary Tree
- Preorder Traversal
- Inorder Traversal
- Postorder Traversal
- Breadth First Traversal
- Zigzag Traversal
- Binary Tree Comparison