Why is it necessary to keep visited flag for iterative post order traversal and not for inorder or pre order iterative traversal and is it possible to do post order traversal without keeping visited flag ?
Questions regarding Iterative Traversal Algorithm?



Best Answer
Here's a postorder visit:
It doesn't use any flags. Why do you think a flag is necessary? Maybe I don't understand the phrase, "iterative post order traversal". By symmetry, if you think that "iterative preorder traversal" doesn't need a flag, I contend you'd have to believe "iterative postorder traversal" is also flag free, and viceversa. EDIT: My bad, must be late at night. "Iterative" meaning "implement without recursion". OK, so you implement your own stack of nodes, and you have to implement what amounts to a stack of return addresses. I think the flag is simulating the effect of the return address knowing whether to go to L1 or L2 next. And since you need this for post order, by symmetry you need it for preorder. EDIT October 2010: My bad again, the algorithm provided wasn't postorder. Revised. 

comments:

Other Answer1
Postorder traversal iterative version could be implemented without using visited flags, it is just more difficult to implement. See here for two solutions for iterative postorder traversal without using any visited flags. http://www.leetcode.com/2010/10/binarytreepostordertraversal.html 
Other Answer2
I found a problem in the solution of user 1337c0d3r: it is simply a preorder in reverse order. My solution uses an "active list" to mark the nodes in the stack. (You could store the mark flag in the stack. Will post that solution separately. )

Other Answer3
I believe the algorithm show in previous posting for portorder traversal is in as it "processes" the node before visiting the left subtree. Postorder Traversal is essentially the same as Reverse Polish Notation in which the operands (leaf nodes or subtrees) precede the operator (the next higher subtree node). A corrected postorder traversal algorith would be:
This would visit the leaf or subtree nodes before visiting the root of the subtree. 
Relate
 Questions About Directory Traversal
 Spark Streaming Iterative Algorithm
 Questions regarding Quartz.net
 DFS Algorithm Traversal
 Convert Catalan recursive algorithm to iterative
 Questions regarding Domain driven Design
 questions regarding the use of A* with the 15square puzzle
 WP7: Questions regarding Touch Gestures
 Questions regarding automated git tagging
 Questions regarding log4net's AdoNetAppender
 Questions regarding XML request format
 Questions regarding TCP checksum calculation
 BST inordertraversal, iterative, parent pointer, no visited flag, no stack
 Regarding shell sort algorithm
 Algorithm to find similarity of questions