Given a binary tree with an integer, Left & Right pointers, how can one traverse the tree in O(n) time and O(1) extra memory (no stack/queue/recursion)?
This guy gave a solution which is not O(n) total time that encoded the current path as an integer (and thus works on for trees of limited depth).
I am looking for the classical solution
(SPOILER)
that encoded the parent of each node in the children.
Any good algorithm book will have this algorithm, look e.g. in Knuth (TAOCP I.2.3.1 Traversing binary trees, excercise 21). However, because this algorithm modifies the tree in place, you must use extreme caution in a multi-threaded environment.
You might also use threaded trees (see in Knuth).