Skip to main content
ICT
Lesson AB30 - Binary Search Trees
 
Main   Previous Next
 

E. Preorder and Postorder Tree Traversals page 7 of 15

  1. 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 visit the root 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

  2. A postorder tree traversal has this order:

    • Process the left subtree postorder
    • Process the 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

 

 

Main   Previous Next
Contact
 © ICT 2006, All Rights Reserved.