Binary Tree Traversal – Depth First Search and Breadth First Search

Lets explore Tree Traversal (Breadth First Search and Depth First Search). Also, we will explore preorder, inorder and postorder technique.

Breadth First Search – Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data structures. It starts at the tree root and explores the neighbor nodes first, before moving to the next level neighbours.

Depth First Search – Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. One starts at the root (selecting some arbitrary node as the root in the case of a graph) and explores as far as possible along each branch before backtracking.

Tree Traversal – Process of visiting each node in the tree exactly once in some order.

Visit – Reading/Processing data in a node.

Preorder – Root -> Left -> Right
Inorder – Left -> Root -> Right
Postorder – Left -> Right -> Root