🤖 AI Summary
This paper addresses the space bottleneck in computing Eulerian circuits in large-scale (multi)graphs. We propose a space-efficient algorithm that reduces working memory from the conventional $O(m log n)$ bits to $O(n log m)$ bits on an $n$-vertex, $m$-edge graph, while retaining $O(m)$ time complexity. Our method introduces a novel non-recursive variant of Hierholzer’s algorithm that simulates recursion via an explicit stack, eliminating per-edge state markers and the implicit depth-first recursion stack. Instead, it relies solely on compact vertex-level data structures and bit-optimized memory management. To the best of our knowledge, this is the first algorithm achieving $O(m)$ time and $O(n)$ words—i.e., $O(n log m)$ bits—space for Eulerian circuit construction. The approach is particularly advantageous for dense graphs and high-multiplicity multigraphs. We provide a formal correctness proof verifying the algorithm’s soundness and termination.
📝 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.