We'll look three of the most common traversal paths through the tree.

Inorder traversal visits nodes in sorted order.

At each node we do the three action options in this order:

  • Traverse to Left
  • Visit Data
  • Traverse to Right

In short: (left, visit, right).

This should be the order in which we visit the data for the tree shown:

  10, 20, 30, 40, 50, 60, 70
                 50
                  |
          --------+--------
          |               |
          20              70
     -----+-----      -----+
     |         |      |
     10       40      60
         -----+
         |
        30
For preorder we visit first (before traversing left and right).

At each node we do the three action options in this order:

  • Visit Data
  • Traverse to Left
  • Traverse to Right

In short: (visit, left, right). Or think "pre" meaning visit pre/before.

This should be the order in which we visit the data for the tree shown:

  50, 20, 10, 40, 30, 70, 60
                 50
                  |
          --------+--------
          |               |
          20              70
     -----+-----      -----+
     |         |      |
     10       40      60
         -----+
         |
        30
For postorder we visit last (after traversing left and right).

At each node we do the three action options in this order:

  • Traverse to Left
  • Traverse to Right
  • Visit Data

In short: (left, right, visit). Or think "post" meaning visit post/after.

This should be the order in which we visit the data for the tree shown:

  10, 30, 40, 20, 60, 70, 50
                 50
                  |
          --------+--------
          |               |
          20              70
     -----+-----      -----+
     |         |      |
     10       40      60
         -----+
         |
        30