trekhleb/javascript-algorithms · error · Error
Eulerian path must contain two odd-ranked vertices
Error message
Eulerian path must contain two odd-ranked vertices
What it means
Error "Eulerian path must contain two odd-ranked vertices" thrown in trekhleb/javascript-algorithms.
Source
Thrown at src/algorithms/graph/eulerian-path/eulerianPath.js:41
const isCircuit = !Object.values(oddRankVertices).length;
if (!isCircuit && Object.values(oddRankVertices).length !== 2) {
throw new Error('Eulerian path must contain two odd-ranked vertices');
}View on GitHub (pinned to 85293e3e2b)
Solutions
- Add or remove edges so the graph has 0 odd-degree vertices (Eulerian circuit) or exactly 2 (Eulerian path).
- Check vertex degrees before calling eulerianPath and reject graphs that are not Eulerian.
- Use a general traversal such as DFS or BFS if the graph is not Eulerian.
When it happens
Trigger: eulerianPath is called on a graph that is not an Eulerian circuit and does not have exactly two odd-degree vertices (e.g. 1, 3, or 4 odd-ranked vertices), so no Eulerian path exists.
Common situations: Running Fleury's algorithm on a graph with 1, 3, or more odd-degree vertices; an Eulerian path requires exactly two odd-degree endpoints.
AI-assisted analysis of trekhleb/javascript-algorithms@85293e3e2b (2026-08-24).
Data as JSON: /api/errors/826b15b7c2c84ef5.
Report an issue: GitHub.