Tree-based DFS
Basically, there are four ways to traverse a Tree:
- Level order
- Pre order
- In order
- Post order
We can use BFS to get the level order traversal. However, we need DFS to get the other three orders of traversal.
Traversal
- Level order (BFS)
- Pre order (root->left tree->right tree)
ABDECF
1 |
|
1 |
|
- In order (left tree->root->right tree)
DBEAFC
⭐️中序遍历是一个升序序列
1 |
|
1 |
|
- Post order
DEBFCA
1 |
|