A One Pass Streaming Algorithm for Finding Euler Tours

Given an undirected graph G on n nodes and m edges in the form of a data stream we study the problem of finding an Euler tour in G. Our main result is the first one-pass streaming algorithm computing an Euler tour of G in the form of an edge successor function with only O(nlog(n))\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$\mathcal O(n\log (n))$\end{document} RAM, which is optimal for this setting (e.g. Sun and Woodruff (2015)). Since the output size can be much larger, we use a write-only tape to gradually output the solution. The previously best-known result for finding Euler tours in data streams is implicitly given by the W-stream algorithm of Demetrescu et al. (2010) using O(m/n)\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$\mathcal O(m/n)$\end{document} passes under the same RAM limitation. Our approach is to partition the edges into edge-disjoint cycles and to merge the cycles until a single Euler tour is achieved. In the streaming environment such a merging is far from being obvious as the limited RAM allows the processing of only a constant number of cycles at once. This enforces merging of cycles that partially are no longer present in RAM. We solve this problem with a new edge swapping technique, for which storing two certain edges per node is sufficient to merge tours without having all tour edges in RAM. The mathematical key is to model tours and their merging in an algebraic way, where certain equivalence classes represent subtours. This quite general approach might be of interest also in other routing problems.


Euler Tours in the Graph-Streaming Model
In the Euler tour problem, we are looking for a closed 1 trail in an undirected graph G = (V , E), where n = |V | and m = |E|, such that each edge is visited exactly once. It is a well studied graph-theoretic problem with applications in the field of big data. For example, solving the traveling salesman problem with the wellknown Christofides algorithm requires an Euler tour [1]. Further, for de novo genome assembly, large de Bruijn graphs can be examined with Eulerian paths [2]. For the processing of large graphs, the graph streaming or semi streaming model introduced by Feigenbaum et al. [3] has been studied extensively over the last decade. In this model, a graph with n nodes and m edges is given as a stream of its edges. Randomaccess memory (RAM, also called internal memory) is restricted to O(n polylog(n)) edges at a time, see, e.g., the survey [4] for a detailed introduction. In consequence, the model cannot be applied to problems where the size of the solution exceeds this amount of memory. Since the size of an Euler tour is m, which might even be (n 2 ), we need a relaxation of the model that allows us to store the output separate from the RAM. An obvious solution for this problem is the addition of a write-only output tape with the sole purpose of storing the Euler tour. In this setting it is common to output the Euler tour in the form of an edge-successor function, i.e. a bijective function E → E mapping each edge to the respective subsequent edge of the Euler tour (e.g. [5], [6]).

Previous Work
Graph streaming with the usage of an additional output tape resembles the model used by Grohe et al. [7]. They consider Turing machines with a read/write input tape, multiple read/write tapes of significantly smaller size, called 'internal memory tapes', and an additional write-only output tape. They count the number of times the head of the input tape changes its direction. This is closely related to the streaming model by Feigenbaum et al. since a streaming pass can be remodeled as a run on the input tape with two direction changes of the head. In a more recent work by François et al. [8], a read-only input tape and a write-only output tape are considered for the problems of stream reverting and sorting.
Another related model is the W-streaming model introduced by Demetrescu et al. [9], which is a relaxation of the classical streaming model. It originated as a more restrictive alternative to the StrSort model introduced by Aggarwal et al. [10,11]. At each pass, an output stream is written, which becomes the input stream of the next pass. Finding an Euler tour in trees in W-streaming has been studied in multiple papers (e.g., [6]), but to the best of our knowledge the general Euler tour problem has hardly been considered in a streaming model so far. However, there are some general results for transferring PRAM algorithms to the W-streaming model. Atallah and Vishkin [5] presented a PRAM algorithm for finding Euler tours, using O(log(n)) time and n + m processors. Transferred to the W-streaming model with the methods from [6], this algorithm computes an Euler tour in the form of a bijective successor function within p = O(m polylog(n)/s) passes, where s is the RAM-capacity. Sun and Woodruff [12] showed that a one-pass streaming algorithm for verifying whether a graph is Eulerian needs Ω(n log(n)) RAM. This implies that the minimum RAM-requirement of a one pass streaming algorithm with additional output tape for finding an Euler tour also is Ω(n log(n)).

Our Contribution
We present the streaming algorithm EULER-TOUR for finding an Euler tour in a graph in form of a bijective successor function or stating that the graph is not Eulerian, using only one pass, O(n log(n)) bits of RAM and an additional write-only output tape. This is not only a significant improvement over previous results, but is in the view of the lower bound of Sun and Woodruff [12] the first optimal algorithm in this setting. Atallah and Vishkin [5] find edge disjoint tours (in our case cycles) and connect them by pairwise swapping the successor edges of suitable edges. This idea is easy to implement without memory restrictions but the implementation gets distinctly more complicated with limited memory space: We cannot store all cycles in RAM. Therefore, we have to output edges and their successors before finding resp. processing all cycles. Our idea is to keep specific edges of some cycles in RAM along with additional information so that we are able to merge following cycles regardless of their appearance with already processed tours which likely are no longer present in RAM.
We develop a new mathematical foundation by partitioning the edges into equivalence classes induced by a given bijective successor function and prove structural properties that allow to iteratively change this function on a designated set of edges so that the modified function is still bijective. Translated to graphs this is a tour merging process. This mathematical approach is quite general and might be useful in other routing scenarios in streaming models.

Organization of the Article
In Section 2 we give some basic definitions. Our algorithm consists of several subroutines and technical data structures. Therefore, for the reader's convenience Section 3 is dedicated to an informal and example-based description. Section 4 contains the pseudo code of the algorithm. In Section 5, we show the connection of the concepts of Euler tours and successor functions and then show that the required RAM of the algorithm does not exceed O(n log(n)) and that the output actually depicts an Euler tour (Theorem 1).

Preliminaries
Let N := {1, 2, . . .} denote the set of natural numbers. For n ∈ N let [n] := {1, . . . , n}. In the following, we consider a simple graph G = (V , E) without loops where V denotes the set of nodes and E the set of (undirected) edges. A walk in G is a finite sequence T = (v 1 , . . . , v ) of nodes of G with {v i , v i+1 } ∈ E for all i ∈ {1, . . . , − 1}. If additionally every edge is visited at most once, we call it trail. The We also write e ∈ T instead of e ∈ E(T ). For a directed edge e we denote by e (1) its first and by e (2) its second component. A trail T = (v 1 , . . . , v , v 1 ) of length l, which starts and ends at v 1 , is called a tour. In tours, we usually do not care about starting point and end point, so we slightly abuse the notation and write v i+ or v i− for a node v i , identifying v +1 := v 1 and v +2 := v 2 and so on. If additionally v i = v j holds for all i, j ∈ [ − 1], i = j (and ≥ 3), we call T a cycle. An Euler tour of G is a tour T with E(T ) = E. Since in the streaming model the graph is represented as a set of edges, we often use the edges for the depiction of tours. With , T can be written as T = (e 1 , . . . , e l ). Here, we also use the slightly abusive index notation. Note that for the tour T the edges are distinct.

Idea of the Algorithm
In this section we explain the new algorithmic idea in a more informal way. First we describe how merging of subtours can be accomplished without RAM limitation clarifying why this does not work in the streaming environment. Thereafter we explain our merging technique, its locality and RAM efficiency.

Subtour merging in Unrestricted RAM
Recall that the Euler tour will be presented by a successor function, so for every edge we will compute the corresponding successor edge in the tour. Let G = (V , E) be an Eulerian graph and T , T be edge-disjoint tours in G. The tour induces an orientation of the edges in a canonical way. If T and T have a common node v, it is easy to merge them to a single tour: T has at least one in-going edge (u, v) with a successor edge (v, w), and T has at least one in-going edge (u , v) with a successor edge (v, w ). By changing the successor edge of (u, v) from (v, w) to (v, w ) and the successor edge of (u , v) to (v, w), we get a tour containing all edges of T ∪ T (see Fig. 1).
The same principle can be applied when merging more than two tours at once. When we have a tour T and tours T 1 , . . . , T k , k ∈ N, such that T , T 1 , . . . , T k are pairwise edge-disjoint and for every j ∈ [k] there is a common node v j of T and T j , switching the successor edges of two in-going edges per node v j as described above creates a tour containing the edges of T ∪ T 1 ∪ · · · ∪ T k .
We can use this method as a simple algorithm for finding an Euler tour: a) Find a partition of E into edge disjoint cycles. b) Iteratively pick a cycle C and merge it with all tours encountered so far which have at least one common node with C. Such a merging process certainly converges to a tour covering all nodes, if a subtour obtained by merging some subtours does not decompose into some subtours again. If we use a local swapping technique to merge tours, this can very well happen, if swapping is applied again to some other node of the merged tour (see Fig. 2). In the RAM model this problem does not appear, since we can keep all tours in RAM and avoid such fatal nodes.
But in the streaming model with O(n log n) RAM it is far from being obvious how to implement an efficient tour merging for the following reasons. Therefore, we must keep track of common nodes and the related edges.

Subtour Merging in Limited RAM
We start with an example of four cycles C 1 , . . . , C 4 , all sharing one node v (see Fig. 3). Let's assume that the cycles are in the same order as found by the algorithm. Let (u 1 , v), . . . , (u 4 , v) be the respective in-going edges and (v, w 1 ), . . . , (v, w 4 ) be the respective out-going edges. By swapping the successor edges of (u 1 , v) and  (u 2 , v) as explained before, we construct a tour T containing all edges from C 1 and C 2 . We then merge this tour with C 3 swapping the successor edges of (u 1 , v) and (u 3 , v). Finally, C 4 is merged with T by swapping the successors of (u 1 , v) and (u 4 , v). The successor edges are now as follows: of the cycle C 1 has the out-going edge of the last cycle as its successor edge. The edge (u 1 , v) is the first in-going edge of v and called the first-in edge of v. Let us briefly show how this merging can be implemented in the streaming model with an additional output tape. When C 1 is kept in RAM, we store the edge (u 1 , v), since we don't know its final successor edge yet. We also keep the edge (v, w 1 ) in RAM, because it will be the successor edge of C 2 . We call such an edge the potential successor edge of v.
The crux is that, no matter how many cycles are merged at the node v, we get along with only two additional edges in RAM at a time: the first-in edge, which will never change after it is initialized and the recent potential successor, which will be replaced every time we merge a new cycle at v. In our example, when merging a cycle C i for i > 1, we assign the edge (v, w i−1 ) as successor edge of (u i , v) and replace (v, w i−1 ) by (v, w i ) in RAM as potential successor edge of v. All other edges are written on the output tape with their corresponding successors and don't have to be stored in RAM. Finally, when no more cycles with node v occur, we can write (u 1 , v) together with the recent successor edge (in our case this is (v, w 4 )) on the output tape. Now, let us consider the more complicated case, where we wish to merge a cycle C with multiple tours at several nodes. Consider a cycle C and tours T 1 , . . . , T j . Let v 1 , . . . , v j , be nodes such that v i belongs to T i and C for all i. We distinguish between merging at three types of nodes: 1. For the nodes v 1 , . . . , v j we swap the successor edges. 2. Nodes in C and in T 1 ∪ · · · ∪ T j \{v 1 , . . . , v j }: as only one successor edge swapping per tour is needed, these additional common nodes are not used, hence for every v ∈ T 1 ∪ · · · ∪ T j \{v 1 , . . . , v j } the in-going edge (u, v) of C keeps its successor edge, so nothing happens here. 3. Nodes in C\(T 1 ∪ · · · ∪ T j ). These nodes are visited by the algorithm for the first time. Since we might want to merge C with future cycles at these nodes, we store for every v ∈ C\(T 1 ∪ · · · ∪ T j ) the in-going edge (u, v) of C as first-in edge and the out-going edge (v, w) of C as potential successor edge.
At any point of time we store at most one cycle C and two edges per node (a first-in edge and a potential successor) in RAM, so O(n log n) RAM suffices. Note that the very first cycle found by the algorithm consists only of type 3 nodes, so every edge will become a first-in edge.

High Level Description
For the readers convenience we give a high level description of our algorithm. A detailed description in pseudo code together with an outline of the analysis and the proof of the main theorem will follow in the next sections. We denote the set of first-in edges by F .
1. Iteratively: 1.1 Read edges from the input stream until the edges in RAM contain a cycle C.
a) store the in-going edge (u, v) of C in F (we will process these ≤ n edges in step 2), b) remember the out-going edge (v, w) as potential successor edge of v.
1.3 Every node v that has already been visited, has thereby been assigned to a unique tour T with v ∈ C ∩ T . For each tour that shares a node with C, choose exactly one common node. 1.4 For each node v chosen in step 1.3 'swap the successors'. That means, we write the in-going edge e on the output tape and take the recent potential successor edge of v as successor edge for e. Then, save the out-going edge as new potential successor edge of v. 1.5 For each edge that has not been stored in F (step 1.2) or written on the output tape (step 1.4) so far, write this edge on the output tape and take as successor the following edge in C. 1.6 Assign all tours with common nodes together with all newly visited nodes to a single tour.
2. After the end of the input stream is reached, all edges have either been written on the output tape or stored in F . For every edge (u, v) ∈ F , write it on the output tape and take as its successor the potential successor edge of v.
An example of how the algorithm works can be found in the Appendix.

The Algorithm in Pseudo Code
To enable a clear and structured analysis, in this section we present the pseudo-code for our algorithm. For a better understanding it is split up into several procedures that correspond to the steps from our high level description in Section 3.3. Note that these procedures are not independent algorithms, since they access variables from the main algorithm. The output is an Euler tour on G, given in the form of a successor function δ * . To be more precise, the output is a sequence of triples is the potential successor edge of v and t (v) ∈ [n] represents the tour that v is assigned to at the moment. The algorithm searches the stream for cycles (Step 1.1 in our high level description in Section 3.3) and whenever a cycle is found, we will run the procedure MERGE-CYCLE on this cycle. Next we state the procedure MERGE-CYCLE, which implements the steps 1.2 to 1.6 in Section 3.3.
Let us now explain all the procedures that are used in MERGE-CYCLE. The procedure NEW-NODES implements step 1.2 from Section 3.3. If a node v ∈ C is processed the very first time by the algorithm, this is indicated by t (v) = 0. If this is the case, we store the C-edge in-going to v in the set F and define s(v) as the next node on C. So the edge (v, v i+1 ) becomes the potential successor of v.
The procedure CONSTRUCT-J-M is a realization of step 1.3 in Section 3.3. Recall that the t-values of the nodes represent the tours that we have constructed so far. For every possible t-value j ∈ [n], we pick exactly one node v with t (v) = j if there is one. These nodes are stored in J , their t-values are stored in M. The nodes in J are the nodes we want to use for merging tours. If two nodes have the same t-value, this means they are already part of the same tour (see Lemma 8), so we have to avoid using both of them for merging.
In the procedure MERGE, we use the nodes from J to merge all tours that share a node with the cycle C by edge-swapping (step 1.4 in Section 3.3).
In the procedure WRITE, we take care of all the edges that have not been stored in F and have not been written on the output tape in the procedure MERGE (Step 1.5 in Section 3.3).
In the procedure UPDATE we update the t-values to implement step 1.6. This way we ensure that the t-values of the nodes still represent the tours they belong to. If M = ∅, the cycle C has no intersecting nodes with already constructed tours, so it is declared as a new tour. Otherwise, all nodes from the cycle C and all intersecting tours now belong to one single tour, represented by the t-value a.
Finally, in the procedure WRITE-F (step 2 in Section 3.3), the first-in edges that have been stored in F during the algorithm are written on the output tape with proper successors. Note that for each (u, v) ∈ F it holds s(v) = 0.

Main Results and Proof Idea
For the readers convenience we first sketch the proof idea and new mathematical techniques in the analysis. The goal is to show that the algorithm EULER-TOUR works as claimed, that is, the memory requirement does not exceed the O(n log n) bound and the output successor function δ * determines an Euler tour for the input graph G.
We state the two main results of this paper: Lemma 1 Algorithm EULER-TOUR needs at most O(n log n) bits of RAM.
Theorem 1 If G is Eulerian, δ * determines an Euler tour on G.
The memory estimation is done in Section 5.2 and is a careful analysis of the Algorithm EULER-TOUR and its subroutines. The main arguments are that at any point of time we store at most two edges per node (a first-in edge and a potential successor), the edges of the cycle that is recently processed and a label for every node (its t-value). The correctness proof turns out to be much more complicated. Every bijective successor function δ partitions the edges of G into edge-disjoint tours. In this case 'being in the same tour' forms an equivalence relation on the set of edges, which is denoted by ≡ δ . We prove this fact in Theorem 2. This allows us to use equivalence classes, when analyzing the dynamic change of subtours induced by successor functions in an algebraic framework. This analysis takes place in Section 5.3 and is concluded by Theorem 1, which states that the output successor function δ * indeed induces an Euler Tour on G. We start with a successor function δ C . In Lemma 5 we show that δ C is bijective and that the equivalence classes of the corresponding equivalence relation ≡ δ C are simply the directed cycles found during the algorithm EULER-TOUR (line 4). Next we construct a recursive sequence of bijective successor functions δ * 0 , . . . , δ * N and their corresponding equivalence classes with δ * 0 = δ C and δ * N = δ * , where N denotes the total number of cycles found by the algorithm. The differences from δ * k+1 to δ * k basically correspond to the successor swapping process in the Procedure MERGE-CYCLE running on the (k + 1)-th cycle found by the algorithm. At this point we need the lemmata 7 and 8, the crux of the analysis. Lemma 7 ensures that the successor swapping leads to a union of all involved equivalence classes and finally Lemma 8 tells us that all successor functions from the sequence δ * 0 , . . . , δ * N are bijective, that the procedure UPDATE works correctly and that after an edge (u, v) has been processed by EULER-TOUR, all processed edges incident in u or v belong to the same equivalence class. Using that Eulerian Graphs are connected, the proof of Theorem 1 then follows with a few simple arguments, because by applying Theorem 2 it suffices to show that all edges of G are in the same equivalence class of the relation ≡ δ * .

Subtour Representation by Equivalence Classes
In this subsection we present some basic definitions and results that allow us to transfer the problem of tour merging in a graph to the notion of equivalence relations on E. This will facilitate an elegant and clear analysis of our algorithm.  (1) = e (2) for all e ∈ E. (iii) Let G = (V , E) be a directed graph with successor function δ. We define the relation ≡ δ on E as follows: For e, e ∈ E, e ≡ δ e :⇔ ∃k ∈ N : δ k (e) = e , where δ k denotes the k-wise composition of δ.
So e ≡ δ e means that e can be reached from e by iteratively applying δ.

Lemma 2 Let δ be a bijective successor function on a directed graph G = (V , E). Then ≡ δ is an equivalence relation on E.
Proof Reflexivity: Let e ∈ E. Since E is finite, there exists k ∈ N with the following property: There exists k ∈ N with k < k and δ k (e) = δ k (e). Otherwise, all elements of the sequence (δ (e)) ∈N would be pairwise distinct, in contradiction to the fact that there exist only |E| edges. Let k be minimal with this property. Since δ is injective, it follows that δ k−1 (e) = δ k −1 (e) and the minimality of k enforces that k − 1 / ∈ N. So k = 1, therefore δ k (e) = δ(e) and by the injectivity of δ we have δ k−1 (e) = e.
Symmetry: Let e, e ∈ E with e = e and e ≡ δ e . Then there exists a minimal k ∈ N with δ k (e) = e . As shown above, there also exists a k ∈ N with δ k (e) = e. Then k < k , because otherwise δ k−k (e) = δ k−k (δ k (e)) = δ k (e) = e , in contradiction to the minimality of k. It follows that δ k −k (e ) = δ k −k (δ k (e)) = δ k (e) = e.
Transitivity: Let e, e , e ∈ E with e ≡ δ e and e ≡ δ e . Then there exist k 1 , k 2 ∈ N with δ k 1 (e) = e and δ k 2 (e ) = e . So we have δ k 1 +k 2 (e) = e .
Before we start with a detailed memory-and correctness analysis, we show that at the end of the algorithm, every edge {u, v} ∈ E has been written on the output tape exactly once, either in the form (u, v) or in the form (v, u).

Lemma 4 (i) After each processing of an edge in the algorithm EULER-TOUR
(lines 2 to 5), the graph Proof We start by proving the first part of (i) via induction over the number of already processed edges. If there are no edges processed so far, then E int = ∅, so G int is cycle-free. Now let k ∈ [|E|] ∪ {0}, let G k , G k+1 denote G int after k resp. k + 1 edges have been processed and let G k be cycle-free. Let e denote the (k + 1)-th processed edge. When e is added to G int , it may produce a cycle C. If e does not produce a cycle, then G k+1 = G k ∪ {e} is cycle-free and we are done. If e produces a cycle C, then according to lines 6,7 in MERGE-CYCLE all C-edges are deleted from E int .
Because e ∈ C, we get G k+1 = (G k ∪ {e}) \ C ⊆ G k and we are done by the induction hypothesis. Now assume for a moment that E int = ∅ at the end of EULER-TOUR. We know that G int is cycle-free at this time, so G int contains a node with odd degree in G int . Because we always delete whole cycles, the degree of this node in G has to be odd as well, but then G is not an Eulerian graph. In this case we might output a message that G does not contain an Euler tour.
(ii). During the execution of EULER-TOUR every edge from E is added to E int at some point of time and there is only one way for an edge to be deleted from E int again, namely in line 7 of the procedure MERGE-CYCLE. At that time the edge has either been written on the output tape by the procedure MERGE or WRITE (in which case we are done), or it has been added to F in the procedure NEW-NODES. In that case it is written on the output tape in WRITE-F. Because, according to (i), E int = ∅ at the end of EULER-TOUR,by then every edge must have been written on the output tape in exactly one of these ways.

Memory Requirement
Proof of Lemma 1 We consider the different variables and sets.
Variable c: c is initialized with 0 and changed in the procedure UPDATE if and only if M = ∅ at that time. This only happens if in the procedure CONSTRUCT-J-M for every node v of the considered cycle, we have t (v) = 0, which means that none of the cycle nodes was considered before. This case can occur at most n/3 times during the algorithm, because there are at most n/3 node disjoint cycles in G. So c ≤ n/3 and log n bits suffice to store c.
Variable s(v): With this variable we store the label of a node, so for fixed v ∈ V , log n bits suffice and altogether n log n bits suffice.
Variable t (v): We prove that for any v ∈ V t(v) ≤ n at any time: Assume for a moment that this is not the case. Let T be the first point of time at which t (v) is set to a value > n for some v ∈ V . t (v) is only changed in the procedure UPDATE, line 9 or 11. In both cases t (v) is set to a which is either c (line 4) or min(M) (line 6). We already showed c ≤ n/3 < n. Hence, by our assumption, min(M) > n at that time. But this implies that at the time of construction of M, there already existed a node u ∈ V with t (u) > n (procedure CONSTRUCT-J-M, line 3) in contradiction to the choice of T .
Sets E int , F, J, M: Because a single element of each of these sets can be stored in log n bits, it suffices to show that the cardinalities of these sets do not exceed n. For E int , this is shown in Lemma 4. For J and M, this follows directly from the construction (procedure CONSTRUCT-J-M). In the set F , for every node only the first edge entering this node is stored (procedure NEW-NODES, lines 2 and 4), so clearly |F | ≤ n.

Correctness
In this subsection, we prove by a series of lemmas that the output successor function δ * determines an Euler tour on G, provided that G is Eulerian (Theorem 1). This is done with the help of our structure theorem (Theorem 2), where bijectivity of δ * and the condition that δ * induces only one equivalence class is required. In the following, we show that these assumptions are true for δ * by generating a sequence of bijective successor functions δ * 0 , . . . , δ * N such that δ * N = δ * and δ * i+1 emerges from δ * i by swapping of edge successors.
Lemma 4 (ii) induces an orientation on E, which we call R * : For all {u, v} ∈ E, we define has been written on the output tape (v, u) if (v, u) has been written on the output tape.
Let C 1 , . . . , C N denote the cycles found by the algorithm EULER-TOUR (lines 2-5) in chronological order. We use this ordering only for the sake of analysis. Note that the cycles C 1 , . . . , C N form a partition of E. For k ∈ [N] and a variable x ∈ {s(v), t (v), . . . |v ∈ V }, we denote by x k the value of x after the k-th call of MERGE-CYCLE. With x 0 we denote the initial value of x.
j +2 ) for every j ∈ [ i ] and define with (1) the successor function δ C : So δ C is the canonical successor function induced by the cycles C 1 , . . . , C N .
Lemma 5 (i) The successor function δ C is bijective.
(ii) For any two edges e, e we have e ≡ δ C e ⇔ ∃i ∈ [N] : e, e ∈ C i .
Proof (i). We first show that δ C is surjective: Let e ∈ R * (E). Then e belongs to some cycle (ii). Let e, e ∈ R * (E) with e ≡ δ C e and k ∈ [N] such that e ∈ C k . Since Let k ∈ {0, . . . , N}. We consider the time right after the k-th iteration of MERGE-CYCLE. For k = 0 this means the very beginning of the algorithm. We call edges from k i=1 E(C i ) processed edges, since those edges have already been loaded into E int and then have been deleted from there. All processed edges can be divided into two types: -Type A: The edge has been written on the output tape with a dedicated successor. -Type B: The edge has been added to F . These are the only possible cases for processed edges, because an edge which is deleted from E int is either written on the output tape or added to F (procedure WRITE). This leads to the following definition.

Lemma 6
Let k, ∈ {0, . . . , N} with k < . Then for any v, v ∈ V , e ∈ R * (E), we have Because t k (v) = 0 and the t-value of v is never set to 0 after its initialization, t k (v) = 0. We take a closer look at the (k + 1)-th call of MERGE-CYCLE. If for a node its t-value is changed in this call, it is set to a k +1 (line 9 or 11 in UPDATE), so we may assume that t k +1 (v) = a k +1 = t k +1 (v ). But this implies that t k (v) ∈ M or v ∈ C k +1 . In the latter case, since t k (v) = 0, we also have t k (v) ∈ M (procedure CONSTRUCT-J-M). But then, t k (v ) = t k (v) ∈ M and therefore t k +1 (v ) = a k +1 = t k +1 (v), in contradiction to our assumption.
The next lemma describes the cycle merging in terms of equivalence classes. Let us briefly explain the meaning of the quite technical notation in this lemma. The reader may think of e 1 , . . . , e r as edges of the same cycle C. The edges e 1 , . . . , e r are edges that do not belong to C, but to several tours that share at least one node with C, such that (e i ) (2) = (e i ) (2) for all i ∈ [r]. The condition e i ≡ δ e j reflects the fact that we have to choose exactly one common node per tour for merging, as already explained in Section 3, see Fig. 2. We obtain the new successor function δ by performing the successor swapping as described in step 1.4 in Section 3.3. (P 1) tells us that via this swapping all associated equivalence classes are merged which means that all affected tours become one big tour. (P 2) makes sure that tours that don't share nodes with C are not changed at all.
Now we apply the induction hypothesis to δ r and δ as follows: We take δ r instead of δ, δ remains, r = 1 and e 1 resp. e 1 are replaced by e r+1 resp. e r+1 . Then P1 gives Since e 1 ≡ δ e r+1 , we get with (8 For the proof of (P2), let e ∈ E\[e 1 ] δ . Since e / ∈ [e 1 ] δ , by (12) and (14)   every edge on P , either the edge itself or the corresponding reversed edge has been processed during the algorithm EULER-TOUR. By Lemma 8 (ii), t N (x) = t N (y) for all nodes x, y of P , hence, t N (u) = t N (u ) and by Lemma 8 (i), we get e ≡ δ * N e . Since δ * N = δ * , we are done.

Conclusion
We have presented a one-pass algorithm with O(n log(n)) RAM for finding Euler tours in undirected graphs in the graph streaming model with an additional write-only output tape. This gives two possible directions for future work.
-Are there other well suited graph-theoretical problems, where the size of a solution exceeds O(n polylog(n)) RAM but which can be solved in the graph streaming model with an additional output tape? -Can our technique of linking tours to equivalence classes be useful for other routing problems?