Trees: Traversal Methods
What are the traversal methods for a tree? Which are DFS and which are BFS?
Answer
Tree traversal is the process of visiting each node in a tree exactly once in a specific order.
There are two main categories of tree traversal:
Depth-First Search (DFS)
Breadth-First Search (BFS)
Depth-First Search (DFS):
Preorder: root, left, right
Inorder: left, root, right
Postorder: left, right, root
Breadth-First Search (BFS):
Level-order: top to bottom, left to right