Traversing a Tree

Traversing a tree means visiting all the nodes in the tree recursively. "Visiting" a node generally means performing some function on the node & its data.




	traverse(node)
	{
	 visit(node)
	 for each child of node
		traverse(child)
	}
        visit(A)
visit(B)
visit(D)
visit(E)
visit(F)
visit(C)



Traversals can be pre-order, post-order, or in-order - this refers to when visit() is called relative to traversing the children.
The relative order that siblings are visited may or may not be guaranteed, depending on the software.




Last modified 24 January 2000.
Dave Pape, pape@evl.uic.edu