Re: hacker challenge - traverse a list



On Feb 29, 12:56 pm, c...@xxxxxxxx (Richard Harter) wrote:
Here is a little challenge - print the contents of a binary tree
in order only using O(1) additional memory. In other words you
can't use recursion or simulate it with a stack. As far as I
know you can't do this without some kind of hack. Also AFAIK
there is no way to do this that should ever be used in real code.
Rules? We don't need no steenking rules! Use whatever language
you like, though I suppose this is a natural for C based
languages. Tag bit solutions (i.e. mark a link as visited when
we go down it and unmark it when we come back up) don't count
because (a) everyone thinks of it, and (b) it (debatably) uses
O(log n) memory. Platform dependencies are okay - this a hack,
after all.

I notice you didn't mention that the structure of the tree can't
change, so why not rotate away the left branches as you traverse? Even
better, once you're done you can make a second pass that balances the
tree. ;-)
.



Relevant Pages

  • Re: hacker challenge - traverse a list
    ... in order only using Oadditional memory. ... We don't need no steenking rules! ... Use whatever language ... I notice you didn't mention that the structure of the tree can't ...
    (comp.programming)
  • Re: hacker challenge - traverse a list
    ... in order only using Oadditional memory. ... can't use recursion or simulate it with a stack. ...  We don't need no steenking rules! ...  Use whatever language ...
    (comp.programming)
  • hacker challenge - traverse a list
    ... in order only using Oadditional memory. ... know you can't do this without some kind of hack. ... We don't need no steenking rules! ... Use whatever language ...
    (comp.programming)
  • Re: role of language in human though process
    ... knowledge of language is prerequisite for thinking. ... Is language anything other than memory and sound? ... When we see a tree ... I prefer to think of it as a method for connectiing brains - rather ...
    (comp.ai.philosophy)
  • Re: role of language in human though process
    ... knowledge of language is prerequisite for thinking. ... Is language anything other than memory and sound? ... When we see a tree ... I prefer to think of it as a method for connectiing brains - rather ...
    (comp.ai.philosophy)