Skip to content
CoreSource checked

Euler Tour

Records entry and exit order while traversing a tree or graph.

Quick Facts

Compact metadata for implementation and discovery.

Category
Graph Traversal
Difficulty
Intermediate
Family
Tree Traversal
Tier
Core
Status
Verified
Review
Source Checked
Sources
2
Formulas
1
Relationships
5
Code example
Ready
Visualization
Ready

Overview

Euler tour traversal captures the order in which nodes are entered and left, which supports subtree queries, ancestor checks, and range-based tree processing.

Core Concepts

entry timeexit timedfs ordersubtree interval

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(V + E)

Average

O(V + E)

Worst

O(V + E)

Space

O(V)

When to Use

  • Use when analyzing graph structure needs entry time.
  • Use when the input matches the assumptions behind tree Traversal.

When Not to Use

  • Avoid when the graph is so large that it needs streaming or external-memory handling.
  • Avoid when a simpler algorithm gives the required result with less setup.

What It Does

  • Records entry and exit order while traversing a tree or graph
  • Uses entry time and exit time to guide the work.
  • Produces visited nodes.

Use Cases

  • Analyzing graph structure
  • Finding connectivity patterns
  • Preparing graph-derived orderings

Inputs

  • Graph
  • Start nodes or query nodes
  • Traversal state

Outputs

  • Visited nodes
  • Derived graph relationships

Key Formulas (1)

Ancestor interval test

entry[u] ≤ entry[v] and exit[v] ≤ exit[u]
entry[u] <= entry[v] and exit[v] <= exit[u]

Checks whether u is an ancestor of v in a DFS tree.

Pseudocode

  1. 1.Prepare the inputs and state needed for Euler Tour.
  2. 2.Apply the entry time step while the stopping condition has not been met.
  3. 3.Update intermediate state and discard invalid candidates.
  4. 4.Return visited nodes.

Canonical Example

Input
Euler Tour input with a small representative case
Output
Visited nodes
Explanation
Euler Tour applies entry time to produce visited nodes.

Implementation Notes

  • Keep visitation state and edge classification state separate.
  • Keep the entry time step separate enough to test independently.

Common Pitfalls

  • Mixing directed and undirected edge assumptions can produce incorrect graph relationships.
  • Forgetting to check edge cases can make Euler Tour look correct on only ideal inputs.

Interactive Mechanism Walkthrough

Graph Frontier & Edge Relaxation

Highlight active nodes, discovered edges, and the graph structure produced by each step.

Euler Tour mechanism walkthrough step 1 of 4suvwxt
Step 1 of 4: Prepare the inputs and state needed for Euler Tour.
graph-traversal-mechanism

Notes

Euler Tour should be used with the assumptions and tradeoffs of tree Traversal in mind.

Sources (2)

What each reference supports for this entry.

Introduction to Algorithms (CLRS)

Book

Textbook support for Euler Tour's standard algorithm design, invariants, and complexity analysis.

Open source

The Algorithm Design Manual

Book

Algorithm catalog support for Euler Tour's problem context, known alternatives, and practical selection tradeoffs.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Euler-tour based tree traversals are commonly produced by depth-first traversal order.

Tags

TreeTraversalLCADepth First Search