Data Structures and Algorithms
with Object-Oriented Design Patterns in C# |
Whereas the depth-first traversals are defined recursively, breadth-first traversal is best understood as a non-recursive traversal. The breadth-first traversal of a tree visits the nodes in the order of their depth in the tree. Breadth-first traversal first visits all the nodes at depth zero (i.e., the root), then all the nodes at depth one, and so on. At each depth the nodes are visited from left to right.
A breadth-first traversal of the tree shown in Figure visits the nodes in the following order: