Hierholzer's algorithm (source code)

= Hierholzer's algorithm
{c}

<Hierholzer's algorithm> constructs an <Euler circuit> by growing closed <trails> along unused <edges> and splicing them at shared <vertices>, as in the <Euler circuit criterion>. Each <edge> must have a distinct record. An implementation using <adjacency lists>, a <stack>, and a used flag for each <edge> runs in $O(|V|+|E|)$ time, including the connectivity and <vertex degree> checks. Store both incidences of a <self-loop>, while marking its single <edge> record used only once.