Tree traversal is a process of visiting each node in a tree exactly once. Unlike linear data structures such as array and linked list which are canonically traversed in linear order, tree may be traversed in depth first or breadth first order

Breadth First Traversal

Visit each node on a level before going to a lower level

For the above tree, assuming that the left subtree are chosen before the right subtree, breadth first traversal orders will be 7-2-9-1-3

Implementation example with Iterative algorithm


  • Using a queue to track which node to visit next

BSTByLinkedList is defined in Binary Search Tree Data Structure