Classify Tree Traversal Algorithms. Provide some visual explanation.

Technology CommunityCategory: Binary TreeClassify Tree Traversal Algorithms. Provide some visual explanation.
VietMX Staff asked 3 years ago

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:

  1. Preorder Traversal (current-left-right)— Visit the current node before visiting any nodes inside left or right subtrees.
  2. 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.
  3. 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:

  1. Level Order Traversal — Visit nodes level-by-level and left-to-right fashion at the same level.

tree-traversal-algorithm