<p>It can be done on $O(|E|\log |E|)$, nevertheless implementing it might be cumbersome. I won't get into details of how implement, but a general overview so we can analyze its running time:</p>

<p>For this we will need and adjacency list instead of an adjacency matrix.</p>

<p>Step 1.-, for each vertex split away the vertices, you can split away all the edges for each vertex, it can be done in $O(|E|)$ in total, by traversing each of the adjacency list of each vertex. Then do a DFS to find and store each cycle components in a doubly linked circular list. And we will need an array A of lists, such that list A[i] will have a pointer to each component such that vertex $i$ appears in that component. This can be done while doing DFS.</p>

<p>Step 2 and 3. For each of the lists at each vertex, we will take two adjacent components, and we will ask if both are the same, if they are, remove the first pointer, and continue. If both are different components, join the two lists, for this, in the list we should have a pointer to the position in the doubly linked list of such vertex. Then we can merge two components in $O(1)$. Then remove one of the entries and proceed until we have only one list, and remove it. Repeat for each vertex until only one list remains, such doubly linked circular list will be our eulerian cycle.</p>

<p>The tricky part, and where the $O(\log |E|)$ comes from is on finding if two components are the same. For this we can do relabeling the smallest component, and we will get an amortized time of $O(\log |E|)$, (see Cormen et al's chapter on Kruskal algorithm). Or maybe use a union-find data structure, in such case you can make it amortized $O(|E|\alpha(|E|))$, which is a little better time. It could be possible to get O(|E|) time but a clever use of pointers might be implied and escapes from my intuition currently.</p>

<p>Note that this operation to determine if two components are the same would be in function of $|E|$ instead of $n$, since we are duplicating vertices, but the number of vertices and its duplicates is bounded by $|E|$.</p>

<p>Notice that you are using a graph theory book and for the pure graph theory point of view the complexity is usually irrelevant, and even more irrelevant the implementation details, from that point of view is enough to show that it can be done systematically, and the focus is on how simple you can explain and prove that it is correct, it is very uncommon to find data structures mentioned in such a book, since that is usually out the book's scope.</p>

CC BY-SA 3.0
2015-05-20T13:56:45.700Z
The 2-regular detachment can be done by adding extra info into the adjacency list of each vertex. Let us assume that you have an edge between $u$ and $v$, and you want to detach it from $u$, then in the list for $u$, the node representing $v$ will need to have a reference to $v$ but also a pointer to the node in the list of $v$ representing $u$. Then to do the detach, create vertex $w$ add the edge in its adjacency list, and change the node representing $u$ in $v$'s list to be representing $w$. And remember that $w$ is a duplicate of $u$. This can be done in $O(1)$ for each edge.
Javier Cano
CC BY-SA 3.0
2015-05-20T02:48:25.380Z
2015-05-20T02:48:25.380Z
Javier Cano
<p>A version of Tucker's algorithm was used in B. Awerbuch, A. Israeli, and Y. Shiloach, Finding Euler Circuits in Logarithmic Parallel Time, STOC 1984, to find Euler tours efficiently in parallel, and similar ideas can be used to make the algorithm run sequentially in linear time.</p>

<p>Suppose you have a connected graph $G$ in which all vertices have even degree, and start by pairing off edges at each vertex. This forms a collection of cycles that together cover the graph, and Tucker's algorithm works by joining the cycles together one at a time.</p>

<p>To make this repeated joining process efficient, first run a connected components algorithm (e.g. DFS) to find which edges belong to which cycles. Make a bipartite multigraph $H$, where the vertices on one side of the bipartition correspond one-for-one with the vertices of $G$, the vertices on the other side of the bipartition correspond with the cycles you've constructed, and the edges of $H$ correspond to incidences between cycles and vertices in $G$. Construct a spanning tree $T$ of $H$ (e.g. DFS again), rooted at one of the cycle vertices.</p>

<p>Now, for each cycle $C$ that is not the root of $T$, join $C$ to its grandparent in $T$ (by swapping the edge pairing at the common vertex of the two cycles, represented by the parent of $C$), in constant time per join.</p>

<p>The same technique also works for directed graphs (and that's the version that Awerbuch et al use for their main presentation); in that case, the only difference is that you want equally many incoming and outgoing edges at each vertex, and the edge-pairing at each vertex must pair incoming edges with outgoing edges.</p>

CC BY-SA 3.0
2015-05-22T07:01:09.947Z
2015-05-22T07:01:09.947Z
David Eppstein
<p>What is the time complexity of <a href="https://books.google.com/books?id=Va8AAQAAQBAJ&amp;pg=PA136&amp;lpg=PA136&amp;dq=tucker%27s+algorithm+eulerian+circuit&amp;source=bl&amp;ots=phX2pF2Uzs&amp;sig=kJPB9pYX7sLWfeO8r_p69Ewg2oo&amp;hl=en&amp;sa=X&amp;ei=eq9YVbLVAev6ygOGsoH4Bg&amp;redir_esc=y#v=onepage&amp;q=tucker&#39;s%20algorithm%20eulerian%20circuit&amp;f=false" rel="nofollow">Tucker's algorithm</a> for generating a Eulerian circuit? 
The Tucker's algorithm takes as input a connected graph whose vertices are all of even degree, constructs an arbitrary 2-regular detachment of the graph and then generates a Eulerian circuit.</p>

<p>I couldn't find any reference that says, for example, how the algorithm constructs an arbitrary 2-regular detachment of the graph, what data structures it uses, what the time complexity is, and so on. Any ideas?</p>

<reference-request><graph-theory><graph-algorithms><time-complexity>
Runtime of Tucker's algorithm for generating a Eulerian circuit
Ernst Stavro
# Runtime of Tucker's algorithm for generating a Eulerian circuit

(Asked by: username_0 on 2015-05-19)

What is the time complexity of [Tucker's algorithm](https://books.google.com/books?id=Va8AAQAAQBAJ&pg=PA136&lpg=PA136&dq=tucker%27s+algorithm+eulerian+circuit&source=bl&ots=phX2pF2Uzs&sig=kJPB9pYX7sLWfeO8r_p69Ewg2oo&hl=en&sa=X&ei=eq9YVbLVAev6ygOGsoH4Bg&redir_esc=y#v=onepage&q=tucker's%20algorithm%20eulerian%20circuit&f=false) for generating a Eulerian circuit?
The Tucker's algorithm takes as input a connected graph whose vertices are all of even degree, constructs an arbitrary 2-regular detachment of the graph and then generates a Eulerian circuit.

I couldn't find any reference that says, for example, how the algorithm constructs an arbitrary 2-regular detachment of the graph, what data structures it uses, what the time complexity is, and so on. Any ideas?

**Tags:** reference-request, graph-theory, graph-algorithms, time-complexity

---

## 2 answers

### Answer by username_2 on 2015-05-22. Score: 7 | Accepted answer

A version of Tucker's algorithm was used in B. Awerbuch, A. Israeli, and Y. Shiloach, Finding Euler Circuits in Logarithmic Parallel Time, STOC 1984, to find Euler tours efficiently in parallel, and similar ideas can be used to make the algorithm run sequentially in linear time.

Suppose you have a connected graph $G$ in which all vertices have even degree, and start by pairing off edges at each vertex. This forms a collection of cycles that together cover the graph, and Tucker's algorithm works by joining the cycles together one at a time.

To make this repeated joining process efficient, first run a connected components algorithm (e.g. DFS) to find which edges belong to which cycles. Make a bipartite multigraph $H$, where the vertices on one side of the bipartition correspond one-for-one with the vertices of $G$, the vertices on the other side of the bipartition correspond with the cycles you've constructed, and the edges of $H$ correspond to incidences between cycles and vertices in $G$. Construct a spanning tree $T$ of $H$ (e.g. DFS again), rooted at one of the cycle vertices.

Now, for each cycle $C$ that is not the root of $T$, join $C$ to its grandparent in $T$ (by swapping the edge pairing at the common vertex of the two cycles, represented by the parent of $C$), in constant time per join.

The same technique also works for directed graphs (and that's the version that Awerbuch et al use for their main presentation); in that case, the only difference is that you want equally many incoming and outgoing edges at each vertex, and the edge-pairing at each vertex must pair incoming edges with outgoing edges.


---

### Answer by username_1 on 2015-05-20. Score: 1

It can be done on $O(|E|\log |E|)$, nevertheless implementing it might be cumbersome. I won't get into details of how implement, but a general overview so we can analyze its running time:

For this we will need and adjacency list instead of an adjacency matrix.

Step 1.-, for each vertex split away the vertices, you can split away all the edges for each vertex, it can be done in $O(|E|)$ in total, by traversing each of the adjacency list of each vertex. Then do a DFS to find and store each cycle components in a doubly linked circular list. And we will need an array A of lists, such that list A[i] will have a pointer to each component such that vertex $i$ appears in that component. This can be done while doing DFS.

Step 2 and 3. For each of the lists at each vertex, we will take two adjacent components, and we will ask if both are the same, if they are, remove the first pointer, and continue. If both are different components, join the two lists, for this, in the list we should have a pointer to the position in the doubly linked list of such vertex. Then we can merge two components in $O(1)$. Then remove one of the entries and proceed until we have only one list, and remove it. Repeat for each vertex until only one list remains, such doubly linked circular list will be our eulerian cycle.

The tricky part, and where the $O(\log |E|)$ comes from is on finding if two components are the same. For this we can do relabeling the smallest component, and we will get an amortized time of $O(\log |E|)$, (see Cormen et al's chapter on Kruskal algorithm). Or maybe use a union-find data structure, in such case you can make it amortized $O(|E|\alpha(|E|))$, which is a little better time. It could be possible to get O(|E|) time but a clever use of pointers might be implied and escapes from my intuition currently.

Note that this operation to determine if two components are the same would be in function of $|E|$ instead of $n$, since we are duplicating vertices, but the number of vertices and its duplicates is bounded by $|E|$.

Notice that you are using a graph theory book and for the pure graph theory point of view the complexity is usually irrelevant, and even more irrelevant the implementation details, from that point of view is enough to show that it can be done systematically, and the focus is on how simple you can explain and prove that it is correct, it is very uncommon to find data structures mentioned in such a book, since that is usually out the book's scope.

> **Comments:**
> **username_1**: The 2-regular detachment can be done by adding extra info into the adjacency list of each vertex. Let us assume that you have an edge between $u$ and $v$, and you want to detach it from $u$, then in the list for $u$, the node representing $v$ will need to have a reference to $v$ but also a pointer to the node in the list of $v$ representing $u$. Then to do the detach, create vertex $w$ add the edge in its adjacency list, and change the node representing $u$ in $v$'s list to be representing $w$. And remember that $w$ is a duplicate of $u$. This can be done in $O(1)$ for each edge.  

---

