Euler Cycle in directed cycle

discrete mathematicseulerian-pathgraph theory

I am trying to solve a problem which boils down to find whether all non-zero degree nodes in a directed graph form a simple cycle.This can be solved by checking whether there is euler cycle in directed graph or not. But the solution given follows two steps:

  1. Check indegree = outdegree for all nodes,
  2. Check if simple dfs starting from any non-zero degree vertex, can cover all the non-zero nodes in graph.

But my doubt is that as we need to find euler circuit, which has same step 1 as mentioned above.But in step 2 if euler circuit we check whether the graph is strongly connected or not.But above step 2 is not sufficient to detect that.So how come the solution is correct?

I mean can we say that if indegree=outdegree and a simple dfs from any non-zero degree node can cover all the vertices(checking connectivity instead of strongly connected) is sufficient to say graph has euler cycle?

Best Answer

If a directed graph $D=(V,E)$ has a DFS tree that is spanning, and has in-degree equal out-degree, then it is Eulerian (ie, has an euler circuit). So this algorithm works fine.


Proof


Assume it does not have an Eulerian circuit, and let $C$ be a maximal circuit containing the root, $r$, of the tree (such circuits must exist, just start at the root and keep following edges until you get back to the root). By assumption, there is a directed edge $u\rightarrow v$ that does not belong to $C$. Since there's a DFS tree, we can pick an edge of $E(D)-E(C)$ that is incident with a vertex of $C$. To do this: follow a path $P$ of the DFS tree from $r$ to $u$, and then add the edge $u\rightarrow v$ to this path. The first edge, call it $e = x\rightarrow y$, of this path $P+(u\rightarrow v)$ that does not belong to $C$ is incident with a vertex $x$ of $C$.

Since both $D$ and $C$ have indegree = outdegree, the graph $D-E(C)$ (ie, the directed graph formed from $D$ by removing all edges of $C$) still has indegree = outegree. So starting with the edge $e$, you can find a directed circuit $C_e$ in $D-E(C)$ by just following edges until you get back to $x$.

But now the union $C\cup C_e$ is a bigger circuit, contradicting maximality of $C$!

enter image description here