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


Is it possible to iterate on binary trees in O (1) assisted space (w / o one stack, queue, etc.) , Or has it been proved impossible? If this is possible, how can it be done?

EDIT: When given the signs of parents' nodes, I am as much as possible about this, as interesting and I did not know that it can be done, but depends That's how you see it, it can be an O (n) auxiliary place. Apart from this, in my practical use, there is no sign of parental nodes. From now on, please answer it.

Geese, I really have to type it in solution, this solution Yusuf M. Morris has done [ inf. Proc. Letter 9 (1979, 1971-200) as far as I can tell, it runs in O (NLJN) time.

  static zero visitInO1 memory (node ​​root, action and lieutenant; node> preread widget) {node parent = root; node right = faucet; node; while (parent! = Zero) {curr = parent. Left; if (curr! = Null) {// searching for the thread (curr! = Right & curr.right! = Null) curr = curr.right; if (curr! = Right) {// Insert Thread curr.right == zero; Curr.right = parent; preeder visitor (guardian); parent = mother- Father; left; continue;; Else // remove thread, the left sub line of P passes in advance / / it restores the node to the original position on curr.right = null;} other preder visitor (guardian); correct = Parents; Parents = Parents. Wright;}} Square nodes {Public node left; Public node correct;}  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -