The Order of Tree Traversal

Preorder

  • Basic recursive steps (Center => Center.left => Center.right)
    1. Check if the current node is empty or null.
    2. Display the data part of the root (or current node).
    3. Traverse the left subtree by recursively calling the pre-order function.
    4. Traverse the right subtree by recursively calling the pre-order function.

Inorder

  • Basic recursive steps (Center.left => Center => Center.right)
    1. Check if the current node is empty or null.
    2. Traverse the left subtree by recursively calling the in-order function.
    3. Display the data part of the root (or current node).
    4. Traverse the right subtree by recursively calling the in-order function.
  • In a binary search tree, in-order traversal retrieves data in sorted order.

Postorder

  • Basic recursive steps (Center.left => Center.right => Center)
    1. Check if the current node is empty or null.
    2. Traverse the left subtree by recursively calling the post-order function.
    3. Traverse the right subtree by recursively calling the post-order function.
    4. Display the data part of the root (or current node).