Iterating over a Binary Tree with O(1) Auxiliary Space

后端 未结 10 1257
广开言路
广开言路 2020-11-30 04:03

Is it possible to iterate over a binary tree in O(1) auxiliary space (w/o using a stack, queue, etc.), or has this been proven impossible? If it is possible, how can it be

10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 04:41

    Is it possible to iterate over a binary tree in O(1) auxiliary space.

    struct node { node * father, * right, * left; int value; };
    

    This structure will make you be able to move 1-step in any direction through the binary tree.
    But still in iteration you need to keep the path!

提交回复
热议问题