8

I wonder if you could help me with a simple implementation for detecting cycles in a directed graph in C#.

I've read about the algorithms but I'd like to find something already implemented, very simple and short.

I don't care about the performance because the data size is limited.

Community
  • 1
  • 1
Homam
  • 23,263
  • 32
  • 111
  • 187

2 Answers2

3

Check out QuickGraph - it has loads of the algorithms implemented and it's quite a nice library to use.

Mike Goatly
  • 7,380
  • 2
  • 32
  • 33
3

Run a DFS on G and check for backedges.

At every node you expand just check if it is already in the currrent path.

Patrick
  • 1,138
  • 7
  • 13