Write down the algorithm of a Inorder Tree Traversal.
Anoniem
After he finished that question, I told him I already know how to do that if he wants to ask a different question. But he wanted me to write it. So I told him, what are the requirements? Do we have unlimited CPU, Memory, Disk storage. The reason why I told him that is because there are Recursive Algorithms and Iterative algorithms. So I wrote him an recursive algorithm in couple of minutes. Then he told me to write down an iterative algorithm. I told him sure I could use a stack like how they teach you in school, but it still doesn't make any difference than recursive,we still using a stack to put all the function calls. So I told him to do a real iterative algorithm, we need to change the data structure a bit, where each node knows their parent. By knowing the parent, you can walk up the tree instead of maintaining a stack. That makes it really efficient.