Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The most obvious way is to just run a DFS, if you ever come back to a node you’ve seen then you have a cycle (and by storing parent pointers you can get the cycle back). That’s like CS 101 level.

However in the article it’s actually a graph being modified. If you don’t want to run a full dfs every time, there are better ways. This problem is called “online cycle detection” and you can google some other algorithms.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: