Directed Graph

Hi,

I'm trying to write a directed graph class.

My graph is stored in a hash map, with key being an Object that describes the node (eg A) and the value being a list of Ojects (linked list) describing its neighbours (eg if A->B and A->C, value would contain B and C)

I need a method which returns true if theres a loop (i.e. if there is a path from node A back to node A eg. A->B->A). This needs to be as efficient as possible (i.e. should only go through graph once)

Any suggestions?

Thanks

[540 byte] By [marky5uka] at [2007-9-29 17:25:56]
# 1
[url= http://forum.java.sun.com/thread.jsp?forum=31&thread=467539&tstart=0&trange=15]Cross-post[/url]
andiha at 2007-7-15 16:18:51 > top of Java-index,Other Topics,Algorithms...
# 2
Try sorting your nodes topologically. If that fails, you know there is a cycle. Topological sorting can be done using DFS variants.Regards, Sebastian Mueller
SebastianMa at 2007-7-15 16:18:51 > top of Java-index,Other Topics,Algorithms...