- Traverse the left subtree.
- Traverse the right subtree.
- Visit the root.
When to Use
Node Deletion
When you delete nodes in a tree, deletion process will be in post-order. You will delete its left child and its right child before you delete the node itself.
Parsing mathematical expressions
It is easier to write a program to parse a post-order expression. Here is an example:
You can figure out the original expression with Inorder Traversal. But it’s not easy for a program to handle the expression since you have to check the priorities of operations.
With postorder, you can easily handle the expression using a Stack. Each time you meet an operator, you pop 2 elements from the stack for the operands, calculate the result and push the result back into the stack.