How to detect if a directed graph is cyclic?

后端 未结 6 1805
鱼传尺愫
鱼传尺愫 2020-12-05 07:32

How can we detect if a directed graph is cyclic? I thought using breadth first search, but I\'m not sure. Any ideas?

6条回答
  •  醉话见心
    2020-12-05 07:57

    Testing for Topological sort over the given graph will lead you to the solution. If the algorithm for topsort, i.e the edges should always be directed in one way fails, then it means that the graph contains cycles.

提交回复
热议问题