Post-order traversal

O(n)

Post-order traversal visits a node only after both its subtrees: left, then right, then the node. Since children are processed before their parent, it's used to free/delete a tree safely and to evaluate expression trees (operands before the operator).

Binary search tree
Press ▶ to run
Edit the input and press Play

How it works

  1. Recurse into the left subtree.
  2. Recurse into the right subtree.
  3. Visit the current node last.
  4. Children are always processed before their parent.

Pseudocode

1postorder(node):                    # O(n)2  if node = null: return3  postorder(node.left)4  postorder(node.right)5  visit(node)                        # children before root