Write a non-recursive traversal of a Binary Search Tree using constant space and O(n) run time

后端 未结 10 2224
刺人心
刺人心 2020-12-07 11:44

This is not homework, this is an interview question.

The catch here is that the algorithm should be constant space. I\'m pretty clueless on how to d

10条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 12:01

    If you are using a downwards pointer based tree and don't have a parent pointer or some other memory it is impossible to traverse in constant space.

    It is possible if your binary tree is in an array instead of a pointer-based object structure. But then you can access any node directly. Which is a kind of cheating ;-)

提交回复
热议问题