Watch postorder traversal visit left, right, then the root on a binary tree. Worked example on a five node tree, a stack version, and a tree you can change.
About this algorithm
Post-order traversal finishes a node's left subtree and right subtree before it records the node. Every node comes after all of its descendants, so each node can use answers already worked out for its children. That is the shape of most tree calculations: height, size, subtree sums, and freeing a tree's memory.
Use post-order when a node's answer is built from its children's answers: a tree's height is one more than its taller child's height, a subtree's sum is the node plus both children's sums, and the diameter and the is-it-balanced check are both worked out from the bottom up. It is also the safe order for deleting a tree, since children go before the parent that points to them. Pick pre-order to act before the children, in-order for sorted output from a binary search tree, and level order for anything about depth.
From the current node, run post-order on the left child first. A missing child returns straight away, often with a starting value such as a height of 0.
Then run post-order on the right child.
Only now record the node, or combine its children's results into its own. The root is always the last value in the output.
One simple way without recursion: run a root, right, left traversal with a stack (pre-order with the children swapped) and reverse the output at the end. Root, right, left read backwards is left, right, root.
The page's tree has root 0 with children 1 and 2; 1 has a left child 3, and 2 has a right child 4. From 0 go left to 1, then left to 3. 3 has no children, so record 3. Back at 1, its right side is empty, so record 1. Back at 0, go right to 2: its left is empty, so go right to 4, record 4, then record 2. Finally record 0. The output is 3, 1, 4, 2, 0. Heights come out in the same order: 3 and 4 are leaves with height 1, so 1 and 2 have height 2, and 0 has height 3.
In code, a post-order function usually returns a value. A height function returns 0 for a missing node and otherwise returns 1 + max(height(left), height(right)). The two calls inside it are the left and right traversals, and the return line that combines them is the visit.
Time: each node is visited once, after its two children return, so the work is proportional to N. Space: the call stack holds the path from the root to the current node, at most the height H; the reverse-the-output version with a stack also stores all N values before reversing them.