<?xml version="1.0" encoding="windows-1252"?>
<node id="600538" title="Re: Tree traversal without recursion: the tree as a state machine" created="2007-02-16 17:54:36" updated="2007-02-16 12:54:36">
<type id="11">
note</type>
<author id="512600">
pKai</author>
<data>
<field name="doctext">
&lt;p&gt;It's no coincidence that stacks have a close relationship with trees.&lt;/p&gt;
&lt;blockquote&gt;&lt;i&gt;You can get rid of any stacks whatsoever by keeping a parent pointer in the tree node data structure. &lt;/i&gt;&lt;/blockquote&gt;
&lt;p&gt;I wouldn't say you "get rid of any stacks" here.&lt;/p&gt;
&lt;p&gt;While you don't implement the stack as a list in classical ways, the list of "parent pointer(s)" between the root and the current node at any given moment of the traversal forms a stack.&lt;/p&gt;
&lt;blockquote&gt;&lt;i&gt;While traversing, you need no memory other than the current and the previous node/state.&lt;/i&gt;&lt;/blockquote&gt;
&lt;p&gt;"previous node/state" obviously refers to the "top of stack", the single point where a stack is accessible.&lt;/p&gt;

</field>
<field name="root_node">
600456</field>
<field name="parent_node">
600456</field>
</data>
</node>
