Re: Red Black Guaruntees
- From: "jehugaleahsa@xxxxxxxxx" <jehugaleahsa@xxxxxxxxx>
- Date: Wed, 31 Oct 2007 01:31:01 -0000
On Oct 30, 6:13 pm, Ben Pfaff <b...@xxxxxxxxxxxxxxx> wrote:
"jehugalea...@xxxxxxxxx" <jehugalea...@xxxxxxxxx> writes:
By the way, is it possible to do efficient in-order iterators for a
tree if it doesn't have parent pointers?
If you don't mind taking a performance hit whenever the tree
changes, then your iterator can contain an array of the ancestors
of the current node. You can use serial numbers in the iterator
and the tree to detect when the tree has changed and thus that
the array of ancestors needs to be refreshed.
Example implementation:
http://adtinfo.org/libavl.html/Traversal-of-an-AVL-Tree.html
--
Ben Pfaffhttp://benpfaff.org
I meant, is it possible to do a in-order traversal without a parent
pointer. With the parent pointer, one can go from a right-most child
and work their way *up* to the next-in-order node.
While you can retain your ancestors on one route down the tree, it
doesn't help you view the tree (as a whole) in sorted order later on.
The only way I can see it being done is to maintain a stack of nodes
as you navigate down the tree and to pop off the stack when you move
to the next node. However, this would require copying the entire tree
while iterating over the elements . . . it seems extreme. However,
since there is one pointer for each node in the tree for parent
pointers, I suppose the classic approach is fairly extreme as well.
.
- Follow-Ups:
- Re: Red Black Guaruntees
- From: CBFalconer
- Re: Red Black Guaruntees
- References:
- Red Black Guaruntees
- From: jehugaleahsa@xxxxxxxxx
- Re: Red Black Guaruntees
- From: Ben Pfaff
- Red Black Guaruntees
- Prev by Date: Re: Red Black Guaruntees
- Next by Date: Re: Red Black Guaruntees
- Previous by thread: Re: Red Black Guaruntees
- Next by thread: Re: Red Black Guaruntees
- Index(es):
Relevant Pages
|