Graph Theory37 sections · 1633 units
Open in Course

Reconstruct Itinerary - Core idea

Sort and use Hierholzer.

Core idea: Find the lexicographically smallest Euler path.

Approach: 1.1. Sort the adjacency list for each airport alphabetically

2.2. Run Hierholzer's algorithm, always picking the smallest available destination

3.3. Build the path in reverse (standard Hierholzer)

Why reverse? Hierholzer naturally builds paths from end to start. When you get stuck, you're at the end of the path.

Greedy correctness: Always picking the smallest neighbor works because if it leads to a dead end prematurely, you backtrack and the DFS handles it.