English

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

Data Structures and Algorithms 2025-10-29 v2 Discrete Mathematics

Abstract

We describe a simple variant of Hierholzer's algorithm that finds an Eulerian cycle in a (multi)graph with nn vertices and mm edges using O(nlgm)\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 O(mlgn)\mathrm{O}(m \lg n) bits of space. Our algorithm runs in linear time, like the classical versions, but avoids an O(m)\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.

Keywords

Cite

@article{arxiv.2508.05251,
  title  = {Space-Efficient Hierholzer: Eulerian Cycles in $\mathrm{O}(m)$ Time and $\mathrm{O}(n)$ Space},
  author = {Ziad Ismaili Alaoui and Detlef Plump and Sebastian Wild},
  journal= {arXiv preprint arXiv:2508.05251},
  year   = {2025}
}
R2 v1 2026-07-01T04:38:50.311Z