Table of Contents
Fetching ...

Space-Efficient Hierholzer: Eulerian Cycles in $\mathrm{O}(m)$ Time and $\mathrm{O}(n)$ Space

Ziad Ismaili Alaoui, Detlef Plump, Sebastian Wild

TL;DR

This paper introduces Space-Efficient Hierholzer, a variant that computes an Eulerian cycle in $O(n \lg m)$ bits of working memory while maintaining linear time $O(n+m)$. The key idea is to avoid storing the entire tour by maintaining only one incoming edge per vertex and per-vertex iterators, and to use a small set of edge marks (Black, Red, Green, Dashed) to guide reverse traversal and backtracking. The algorithm outputs the cycle incrementally to a write-only stream and is applicable to both directed and undirected Eulerian graphs, with particular efficiency on dense or multi-graph inputs. The results include a formal correctness proof and precise complexity analyses, making the approach practical and easy to implement in memory-constrained settings, and highlighting potential extensions to broader graph models.

Abstract

We describe a simple variant of Hierholzer's algorithm that finds an Eulerian cycle in a (multi)graph with $n$ vertices and $m$ edges using $\mathrm{O}(n \lg m)$ bits of working memory. This substantially improves the working space compared to standard implementations of Hierholzer's algorithm, which use $\mathrm{O}(m \lg n)$ bits of space. Our algorithm runs in linear time, like the classical versions, but avoids an $\mathrm{O}(m)$-size stack of vertices or storing information for each edge. To our knowledge, this is the first linear-time algorithm to achieve this space bound, and the method is very easy to implement. The correctness argument, by contrast, is surprisingly subtle; we give a detailed formal proof. The space savings are particularly relevant for dense graphs or multigraphs with large edge multiplicities.

Space-Efficient Hierholzer: Eulerian Cycles in $\mathrm{O}(m)$ Time and $\mathrm{O}(n)$ Space

TL;DR

This paper introduces Space-Efficient Hierholzer, a variant that computes an Eulerian cycle in bits of working memory while maintaining linear time . The key idea is to avoid storing the entire tour by maintaining only one incoming edge per vertex and per-vertex iterators, and to use a small set of edge marks (Black, Red, Green, Dashed) to guide reverse traversal and backtracking. The algorithm outputs the cycle incrementally to a write-only stream and is applicable to both directed and undirected Eulerian graphs, with particular efficiency on dense or multi-graph inputs. The results include a formal correctness proof and precise complexity analyses, making the approach practical and easy to implement in memory-constrained settings, and highlighting potential extensions to broader graph models.

Abstract

We describe a simple variant of Hierholzer's algorithm that finds an Eulerian cycle in a (multi)graph with vertices and edges using bits of working memory. This substantially improves the working space compared to standard implementations of Hierholzer's algorithm, which use bits of space. Our algorithm runs in linear time, like the classical versions, but avoids an -size stack of vertices or storing information for each edge. To our knowledge, this is the first linear-time algorithm to achieve this space bound, and the method is very easy to implement. The correctness argument, by contrast, is surprisingly subtle; we give a detailed formal proof. The space savings are particularly relevant for dense graphs or multigraphs with large edge multiplicities.

Paper Structure

This paper contains 23 sections, 12 theorems, 1 figure, 1 algorithm.

Key Result

Lemma 1

At every step of the execution of Space-Efficient-Hierholzer, exactly one of the following statements holds:

Figures (1)

  • Figure 1: Sample execution of Space-Efficient-Hierholzer. For clarity, Dashed edges are labelled in the order in which they are written. The current vertex is represented by double borders.

Theorems & Definitions (26)

  • Definition 1: Eulerian, Eulerian cycle
  • Definition 2: Needle vertex
  • Lemma 1
  • proof
  • Corollary 1
  • Lemma 2
  • proof
  • Lemma 3
  • proof
  • Remark 1
  • ...and 16 more