> Hi all, I'm doing something similar to a graph traversal. And in this
> instance this graph type structure could have cycles. I want to ensure
> I don't revisit old nodes and was wondering if anyone could think of an
> efficient way to store nodes/locations/names that have already been
> visited.
...
java.util.HashSet
Patricia
> > Hi all, I'm doing something similar to a graph traversal. And in this
> > instance this graph type structure could have cycles. I want to ensure
[quoted text clipped - 6 lines]
>
> Patricia
Well, at the risk of pointing out the obvious, why not ue a 'visited' flag
in the actual nodes and check for these during traversal.
Remon
Thomas Weidenfeller - 23 Jun 2005 08:33 GMT
> Well, at the risk of pointing out the obvious, why not ue a 'visited' flag
> in the actual nodes and check for these during traversal.
It only works in limited circumstances. E.g. it doesn't work in any
setup where you have concurrent (overlapping ) traversals of the graph
going on.
It also requires an extra step to clear all flags prior to traversal if
you do more than one traversal. Which means you better have all your
nodes arranged in some other data structure, like a list, too. Otherwise
you end up in the situation where you would have to do a traversal to
clear the flags to prepare for a traversal. However, the
preparation-traversal can't work if you need the flags for loop
detection during traversal.
/Thomas

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq