Re:Space Requirements for Tree Traversal
by userbinator on Sunday October 09, 2016 @01:24PM
(#12672177)
If the nodes have parent pointers, which does tend to be somewhat common, then depth-first can be done in constant space. I haven't implemented it before, but I believe breadth-first should also take constant space in this case.
[ Parent
| on HN ]
Re:Space Requirements for Tree Traversal
by catnaroek on Sunday October 09, 2016 @01:27PM
(#12672196)
If the nodes have parent pointers, everything is paying extra O(n) space.
Re:Space Requirements for Tree Traversal
by perfmode on Sunday October 09, 2016 @02:07PM
(#12672426)
Space is already O(n)
Related: Morris Traversal (no parent link required).
https://en.wikipedia.org/wiki/Tree_traversal#Morris_in-order...
Trying to reimplement it without looking at the solution is fun.