Javatpoint Logo
Javatpoint Logo

Post-order traversal

Steps

  • Traverse the left sub-tree in post-order
  • Traverse the right sub-tree in post-order
  • visit the root

Algorithm

  • Step 1: Repeat Steps 2 to 4 while TREE != NULL
  • Step 2: POSTORDER(TREE -> LEFT)
  • Step 3: POSTORDER(TREE -> RIGHT)
  • Step 4: Write TREE -> DATA
    [END OF LOOP]
  • Step 5: END

C Function

Example

Traverse the following tree by using post-order traversal


binary tree Post-order traversal
  • Print the left child of the left sub-tree of binary tree i.e. 23.
  • print the right child of the left sub-tree of binary tree i.e. 89.
  • print the root node of the left sub-tree i.e. 211.
  • Now, before printing the root node, move to right sub-tree and print the left child i.e. 10.
  • print 32 i.e. right child.
  • Print the root node 20.
  • Now, at the last, print the root of the tree i.e. 18.

The printing sequence will be 23, 89, 211, 10, 32, 18.


Next TopicDoubly Linked List




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA