non recursive binary tree traversal in O(n) time and O(1) space# JobHunting - 待字闺中
r*e
1 楼
Question:
Write an O(n)-time nonrecursive procedure that, given an n-node binary tree,
prints out the key of each node. Use no more than constant extra space
outside of the tree itself and do not modify the tree, even temporarily,
during the procedure. Assume each node has a left pointer to its left child
, a right pointer to its right child, and no parent pointer.
Is this possible? Any ideas? Thanks.
Write an O(n)-time nonrecursive procedure that, given an n-node binary tree,
prints out the key of each node. Use no more than constant extra space
outside of the tree itself and do not modify the tree, even temporarily,
during the procedure. Assume each node has a left pointer to its left child
, a right pointer to its right child, and no parent pointer.
Is this possible? Any ideas? Thanks.