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

后端 未结 10 2269
刺人心
刺人心 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条回答
  •  猫巷女王i
    2020-12-07 11:51

    We can traverse the binary tree without modifying the tree itself (provided nodes have parent pointer). And it can be done in constant space. I found this useful link for the same http://tech.technoflirt.com/2011/03/04/non-recursive-tree-traversal-in-on-using-constant-space/

提交回复
热议问题