Skip to content
  • Dashboard
  • Review
  • Go: plan & chat
  • Roadmap
  • Patterns & lessons49
  • Sheets
  • Problems1.5k
  • Ascend
  • Toolkit
  • Core CS + SQL
  • System Design
  • Machine Coding
  • Interview hub
  • Mock interview
  • Companies & OA
  • Leaderboard
  • Battles
  • College Cup
  • People

Keep your progress

Sync across devices with a free account.

Sign upSign in
Patterns & lessons
Sign inSign up
Patterns/Graphs/Graph BFS / DFS

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
Practise nextReconstruct Itinerary
IdeaPracticePitfalls

Recognise it

The signal

use every ticket/edge exactly once

  1. 1Brute force

    Backtracking over edge orders.

  2. 2The observation

    Exponential backtracking: degree conditions guarantee the post-order splice works.

  3. 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

Next

Reconstruct Itinerary

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

Resources

  • Graph Theory playlistWilliam Fiset · video
  • Graph TraversalUSACO Guide · course
  • Disjoint Set Unioncp-algorithms · article
  • Dijkstracp-algorithms · article
  • Topological sortingcp-algorithms · article
  • Shortest paths visualizerVisuAlgo · tool
  • Graph cheatsheetTech Interview Handbook · article
TodayReviewPatternsProblems