# Even cycle in a simple graph

$G=(V,E)$ is a simple graph, decide if there exist a cycle of even length in $G$.

The problem comes from 2014 Spring UIUC Theory Qualify Exam.

# 1 Characterizations

Let $λ(u,v)$ denote the local edge connectivity of vertices $u$ and $v$. It’s the same as the largest number of edge disjoint paths connecting $u$ and $v$. $λ(G)=max_{u,v∈V}{λ(u,v)}$. Similarly, $κ(u,v)$ is defined as local vertex connectivity, and $κ(G)=max_{u,v∈V}{κ(u,v)}$

If $κ(u,v)≥3$ for some $u,v∈V$, then there exist an even cycle.

There are 3 vertex disjoint paths $p_{1},p_{2},p_{3}$ from $u$ to $v$, thus it contains cycle $p_{1}p_{2}$,$p_{1}p_{3}$ and $p_{2}p_{3}$. One of them will have even length.

If $λ(G)≥3$, then $κ(G)≥3$.

If $λ(u,v)≥3$, we consider the 3 edge paths between $u,v$. Let them be $p_{1},p_{2},p_{3}$. Notice if none of them intersect at a vertex, $κ(u,v)≥3$.

If $p_{1},p_{2}$ intersects and has their first intersection at $v_{′}$. Let $p_{1},p_{1}$ and $p_{2}$ be the paths following $p_{1}$ from $u$ to $v_{′}$ and $v_{′}$ to $v$, and the paths following $p_{2}$ from $u$ to $v_{′}$. $p_{1}p_{2}$ is a cycle that contains $u$ and $v_{′}$. $λ(u,v_{′})≥3$ because there is an additional edge disjoint path $p_{3}p_{1}$ from $u$ to $v_{′}$.

So now we can consider $u,v_{′}$, where $λ(u,v_{′})≥3$ and $u,v_{′}$ is in some cycle $C$. Consider another path $P$ from $u$ to $v_{′}$ that is edge disjoint from the cycle. Let $t$ be the first vertex where $P$ intersects $C$. Clearly, $κ(u,t)≥3$.

It should be easy to show that

If $λ(G)=2$, then all cycles in the graph are edge disjoint.

# 2 A complicated yet obvious algorithm

- Compute if $λ(G)>2$, if so, return true.
- Compute if there is an even cycle in linear time.

We first sparsify the graph with Nagamochi and Ibaraki’s linear time algorithm that preserves the edge connectivity up to $3$. After spending $O(n+m)$ time, the graph has at most $3n$ edges. We want to find a global maximum min-cut in the resulting graph. Either $s−t$-min-cut is the global maximum min-cut, or $s,t$ are in the same component of the global maximum min-cut. One can modify Stoer-Wagner algorithm to find $λ(G)$ in $O(nm+n_{2}gn)=O(n_{2}gn)$ time. Since our graph is unweighted we can do it better in $O(n_{2})$ time.

Another approach is to show the graph cannot contain a diamond graph as a minor and use any general graph minor recognition algorithm. The fastest I know is the $O(n_{3})$ one from the original Robertson–Seymour paper. There are some discussion on cstheory on what is know about this algorithm.

However we can do it better, because we can easily check graphs without a diamond as a minor has treewidth two. So we can first check if the graph have a fixed treewidth in linear time[1]. Next, we can then apply a linear time minor testing algorithm on graphs with bounded branch width(which is implied by bounded treewidth)[2].

The second step is computationally easy. Do a DFS, whenever we find a cycle, check if the cycle is even, delete all those edges, and keep going. The number of steps we take is at most $O(n+m)$ time. In fact, we don’t really need to delete the edges once we find a cycle, as we know they will never get used by another cycle.

# 3 A much simpler algorithm

Our algorithm above is pretty general and uses some heavy machinery. That’s the kind of solution I would give during a qualify exam due to time constraints(well, always use the most powerful technique possible).

The theorems we proved implies one nice corollary

If a graph has no even cycles, then all cycles in the graph are edge disjoint.

This kind of graph has a name, a cactus graph. It is so special we can recognize it in linear time. A graph is a cactus if once we build a DFS tree, every vertex has at most one back edge.

This implies a extremely simple algorithm

- Run a DFS to build a DFS tree. Let $d(v)$ be the depth of a vertex $v$ in the tree.
- Assume there is a back edge between $x$ and $y$, check if there is any back edge end at some node in the unique path from $x$ to $y$.
- For every vertex $v$, if it has a back edge to some vertex $u$, then check if $d(v)−d(u)$ is odd. If it is, return true.
- Return false.

# References

**A linear-time algorithm for finding tree-decompositions of small treewidth**, SIAM Journal on Computing. 25 (1996) 1305–1317 10.1137/S0097539793251219.