Data Structures and Algorithms with Object-Oriented Design Patterns in C#
next up previous contents index

Breadth-First Traversal

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 gif visits the nodes in the following order:

displaymath62997


next up previous contents index

Bruno Copyright © 2001 by Bruno R. Preiss, P.Eng. All rights reserved.