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
  • 22,486
  • 32
  • 107
  • 183

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,150
  • 1
  • 31
  • 30
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,128
  • 7
  • 13