Traversal of binary trees
- The basic concept
- The former sequence traversal
- In the sequence traversal
- After the sequence traversal
- Level traversal
The basic concept
-
The ergodic general of binary trees is divided into two categories:
-
Depth traversal:
- Pre-order traversal: root node -> left subtree -> right subtree
- Middle order traversal: left subtree -> root node -> right subtree
- Subsequent traversal: left subtree -> right subtree -> root node
-
Breadth traversal:
- Hierarchy traversal: Traversal from top to bottom and left to right according to the hierarchy
-
The former sequence traversal
- Pre-order traversal: root node -> left subtree -> right subtree
- Preorder traversal Java code implementation
In the sequence traversal
- Middle order traversal: left subtree -> root node -> right subtree
- Sequence traversal Java code implementation
After the sequence traversal
- Back-order traversal: left subtree -> right subtree -> root node
- After the sequence traversal Java code implementation
Level traversal
- Hierarchical traversal: Traversal from top to bottom and left to right according to the hierarchy
- Hierarchical traversal Java code implementation