How do I find a cycle in a directed graph using topological sort? -


I have implemented this program in order to detect whether the guided article is Acyclic:

  L. The empty list containing the sorted elements will be. S set all the nodes with no inward edges, while S is not empty, remove the n n from the n and the n is for the nodes of the L. poo and on the edges of the edge of the grid then the mistake (at least in the graph One cycle is returned) and returns L (sequence from top level)  

This works great, but I need to output the actual cycle if the graph is not acyclic . Is it possible to do this "inside" code, or do I need to completely change my algorithm? I have tried to find a solution, and I got this answer (), but I can not understand how to actually do it. Does anyone have some pseudocode that can help me?

First of all, what you are trying to do is slightly problematic, because it could be more More than a chakra theoretically, every node of the graph can have a self-sustaining edge, then the N Chakra can occur.

However, there will be an easy way to catch any edge in the graph, then until you revert to the same edge, output it as a circle, as a result of the edges dead-end Should be removed, and all the circle edges should be removed from the graph by mixing any chakras. As long as there is no edge in the graph, keep doing it and it should produce all the chakras in the graph, although there should not be any special order or adaptation, and may leave some chakras when performed in certain order. .


Comments