Modeling graphs and finding cycles

K

Karsten Wutzke

Hi all!

Can anyone recommend some classes in the JDK which are best used to
model graphs? I have to check this graph for cycles. Maybe someone can
even point me into the direction of where to find such an algorithm,
since I think this should be well documented and is relatively trivial.

TIA!

Karsten
 
M

Michael Borgwardt

Karsten said:
Hi all!

Can anyone recommend some classes in the JDK which are best used to
model graphs? I have to check this graph for cycles. Maybe someone can
even point me into the direction of where to find such an algorithm,
since I think this should be well documented and is relatively trivial.

You'll probably want to model your graph as a Map of nodes, with the
node name as a key and an adjacency list (i.e. a List of all the
nodes which are directly reachable from that node) as value. Then,
do a BFS or DFS to find cycles.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top