Pattern
Eulerian Path / Circuit (Hierholzer)
A walk using every EDGE exactly once exists iff degree conditions hold; Hierholzer's algorithm builds it in O(E) by splicing cycles.
Learn firstGraph BFS / DFS
0%
mastery
0/6 solved
0/6 solved
Recognise it
The signal
use every ticket/edge exactly once
1Brute force
Backtracking over edge orders.
2The observation
Exponential backtracking: degree conditions guarantee the post-order splice works.
3Why it works
Undirected: 0 or 2 odd-degree vertices; directed: out-in = 1 at start, in-out = 1 at end, balanced elsewhere (plus connectivity).
Reach for it when
- +reconstruct a sequence from overlapping pairs
- +De Bruijn sequences
Not when
- ×must visit every VERTEX once (Hamiltonian; dp-bitmask)
Practice
0/6 solved
- Advertisement Play Order from PairsFlipkartOAMedium
- Reconstruct ItineraryUber, GoogleHard
- Valid Arrangement of PairsHard
- De Bruijn SequenceCSESHard
- Mail DeliveryCSESHard
- Teleporters PathCSESHard
Pitfalls
Misconceptions
- !confusing Euler (edges) with Hamiltonian (vertices) paths
Go deeper1 combinations · resources
Combinations
Eulerian Path / Circuit (Hierholzer)+Graph BFS / DFS
use all tickets once, construct sequences from overlapping pairs
- Eulerian Path / Circuit (Hierholzer):
- Hierholzer post-order splice and degree checks
- Graph BFS / DFS:
- DFS over edges
Reconstruct ItineraryValid Arrangement of PairsDe Bruijn Sequence