Postorder by reversing a walk
transcript
Postorder visits a node last. It comes after both of its sides. A plain pop visits a node first. So how does a stack do it?
Walk the tree as node, then right side, then left side. That is the preorder loop with the left child pushed first. Then reverse the output.
Walk node, right side, left side on six nodes. It reads four, two, eight, nine, one, seven. Reverse it: seven, one, nine, eight, two, four. Left side, right side, node.
Before the reversal, the node comes first. After the reversal, the node comes last. Left side first, then right side. That is postorder. The node comes last.
The recursive version gives the same list. Seven, one, nine, eight, two, four. No recursion, so a chain of a hundred thousand works.
Walk node, right side, left side. Reverse the output. No recursion is needed. Full breakdown in the lecture.