A / B --> C
In this case, simply sorting the graph to get A B C and then pointing the AC and AB edges backwards does not reveal the cycle.
Asked By : dspyz
Answered By : Emil Jeřábek
- for every directed edge $e=(a,b)in E$, and for every orientation $(a,b)$ of an undirected edge $e={a,b}in E$:
- if there is a path (directed where applicable) from $b$ to $a$ in $(V,Esmallsetminus{e})$:
- find such a path $p$
- make sure the path is simple by deleting subcycles
- output any orientation of the undirected edges that agrees with the cycle $e,p$ and stop
- if there is a path (directed where applicable) from $b$ to $a$ in $(V,Esmallsetminus{e})$:
- if no edge worked, reject
Note that the simplicity of $p$ in particular ensures that no undirected edge appears twice in $e,p$, hence it gives a consistent orientation. Thus, if the algorithm accepts, it is correct. On the other hand, if there exists an orientation of $G$ that includes a (wlog simple) cycle $c$, and $e=(a,b)$ is any edge in $c$ (properly oriented), then $a$ is reachable from $b$ in $(V,Esmallsetminus{e})$ by means of the rest of the cycle. Thus the algorithm will accept sooner or later. In terms of complexity, both problems are NL-complete as decision problems, and the search problem versions are in FNL.
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/33949 Ask a Question Download Related Notes/Documents