Understanding the logic in iterative Postorder traversal implementation on a Binary tree
I was trying to understand how it is so intuitive to implement postorder traversal using 2 stacks. How did someone come up with it, is it just an observation or some particular way of thinking which helps one come up with such methods. If yes then please explain how to think in the right direction. Let me explain how I stumbled on the solution: You start off with this simple observation: prima facie, the pre-order and post-order traversal differ only in their order of operations : preOrder(node): if(node == null){ return } visit(node) preOrder(node.leftChild) preOrder(node.rightChild)