How To Traverse Binary Trees

There are three standard ways of traversing a binary tree T with root R. These three algorithms, called preorder, inorder and postorder, are as follows:

Preorder (Root Left Right)

  • Process the root R.
  • Traverse the left subtree of R in preorder.
  • Traverse the right subtree of R in preorder.


Inorder (Left Root Right)

  • Traverse the left subtree of R in inorder.
  • Process the root R.
  • Traverse the right subtree of R in inorder.

Postorder (Left Right Root)

  • Traverse the left subtree of R in postorder.
  • Traverse the right subtree of R in postorder.
  • Process the root R.
Powered by Blogger.