Tree Traversal algorithms can be classified broadly in two categories:
- Depth-First Search (DFS) Algorithms
- Breadth-First Search (BFS) Algorithms
Depth-First Search (DFS) Algorithms have three variants:
- Preorder Traversal (current-left-right)— Visit the current node before visiting any nodes inside left or right subtrees.
- Inorder Traversal (left-current-right)— Visit the current node after visiting all nodes inside left subtree but before visiting any node within the right subtree.
- Postorder Traversal (left-right-current) — Visit the current node after visiting all the nodes of left and right subtrees.
Breadth-First Search (BFS) Algorithm has one variant:
- Level Order Traversal — Visit nodes level-by-level and left-to-right fashion at the same level.