Data Structures and Algorithms
with Object-Oriented Design Patterns in Java
The second depth-first traversal method we consider is
postorder traversal .
In contrast with preorder traversal,
which visits the root first,
postorder traversal visits the root last.
To do a postorder traversal of a general tree:
- Do a postorder traversal each of the subtrees of the root
one-by-one in the order given; and then
- visit the root.
To do a postorder traversal of a binary tree
- Traverse the left subtree; and then
- traverse the right subtree; and then
- visit the root.
A postorder traversal of the tree shown in Figure
visits the nodes in the following order:

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