| |
Preorder and Postorder Tree Traversals | page 4 of 8 |
A preorder tree traversal processes each node in a different order.
Visit the node
Process the left subtree preorder
Process the right subtree preorder
The only difference is that we will visit first, then go left, then right. The preorder output of the same binary tree will be:
26 14 9 21 79 53 35 99 87
A postorder tree traversal has this order:
Process left subtree postorder
Process right subtree postorder
Visit the node
The prefix "post" refers to after, hence the location of visiting the node after the recursive calls. The printout of the same tree will be as follows:
9 21 14 35 53 87 99 79 26
|