ArticleslgStudy

computer science

Euler tour technique

Euler tour technique is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Euler tour technique rather than just read about it. In short: The Euler tour technique (ETT), named after Leonhard Euler, is a method in graph theory for representing trees. The tree is viewed as a directed graph that contains two directed edges for each edge in the tree.

Euler tour technique — main illustration
Euler tour technique — illustration

Key takeaways

  • Euler tour technique belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Euler tour technique to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Euler tour technique from memory before moving on to harder problems.

Reference excerpt

The Euler tour technique (ETT), named after Leonhard Euler, is a method in graph theory for representing trees. The tree is viewed as a directed graph that contains two directed edges for each edge in the tree. The tree can then be represented as a Eulerian circuit of the directed graph, known as the Euler tour representation (ETR) of the tree. The ETT allows for efficient, parallel computation of solutions to common problems in algorithmic graph theory. It was introduced by Tarjan and Vishkin in 1984.

Construction Given an undirected tree presented as a set of edges, the Euler tour representation (ETR) can be constructed in parallel as follows:

We construct a symmetric list of directed edges: For each undirected edge {u,v} in the tree, insert (u,v) and (v,u) in the edge list. Sort the edge list lexicographically. (Here we assume that the nodes of the tree are ordered, and that the root is the first element in this order.) Construct adjacency lists for each node (called next) and a map from nodes to the first entries of the adjacency lists (called first): For each edge (u,v) in the list, do in parallel: If the previous edge (x,y) has x ≠ u, i.e. starts from a different node, set first(u) = (u,v) Else if x = u, i.e. starts from the same node, set next(x,y) = (u,v) Construct an edge list (called succ) in Euler tour order by setting pointers succ(u,v) for all edges (u,v) in parallel according to the following rule:

succ(u,v)={next(v,u)next(v,u)≠nilfirst(v)otherwise. The resulting list succ will be circular. The overall construction takes work W(n) = O(sort(n)) (the time it takes to sort n items in parallel) if the tree has n nodes, as in trees the number of edges is one less than the number of nodes.

Roots, advance and retreat edges If the tree has a root, we can split the circular list succ at that root. In that case, we can speak of advance and retreat edges: given a pair of nodes u,v, the first occurrence of either (u,v) or (v,u) in the ETR is called the advance edge, and the second occurrence is called the retreat edge. This appeals to the intuition that the first time such an edge is traversed the distance to the root is increased, while the second time the distance decreases. Rerooting the tree can be done in constant time O(1) by splitting the circular list succ at the new root.

Applications All of the following problems can be solved in O(Prefix sum(n)) (the time it takes to solve the prefix sum problem in parallel for a list of n items):

Classifying advance and retreat edges: Do list ranking on the ETR and save the result in a two-dimensional array A. Then (u,v) is an advance edge iff A(u,v) < A(v,u), and a retreat edge otherwise. Determine the level of each node: Do a prefix sum on the ETR, where every advance edge counts as 1, and every retreat edge counts as −1. Then the value at the advance edge (u,v) is the level of v. Number of nodes in a subtree rooted at v: assume the parent of v is u, determine advance edge (u,v), and the retreat edge (v,u) in parallel, and then count the number of advance edges between (u,v) and (v,u) using prefix sum. The depth-first search index of a node v: count the number of advance edges up to and including (u,v). Determine the lowest common ancestor of two nodes.

Euler tour trees Henzinger and King suggest to represent a given tree by keeping its Euler tour in a balanced binary search tree, keyed by the index in the tour. So for example, the unbalanced tree in the example above, having 7 nodes, will be represented by a balanced binary tree with 14 nodes, one for each time each node appears on the tour. We can represent a forest (an acyclic graph) using a collection of ET trees - one ET tree for one forest tree. This representation allows us to quickly answer the question "what is the root of node v?" by just moving to the first node of the ET tree (since nodes in the ET tree are keyed by their location in the Euler tour, and the root is the first and last node in the tour). When the represented forest is updated (e.g. by connecting two trees to a single tree or by splitting a tree to two trees), the corresponding Euler-tour structure can be updated in time O(log(n)). Link/cut trees have similar performance guarantees. While LC trees are good for maintaining aggregates on paths of a tree (making it a good choice data structure in network flow algorithms), ET trees are better at keeping aggregate information on subtrees.

References

Illustrations

Euler tour technique: Euler tour of a tree, with edges labeled to show the order in which they are traversed by the tour
Euler tour of a tree, with edges labeled to show the order in which they are traversed by the tour

Worked examples

Example 1 — a first encounter with Euler tour technique

Start with the simplest possible case. Write down what Euler tour technique claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Euler tour technique before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Euler tour technique ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Euler tour technique

In research
Euler tour technique appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Euler tour technique in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Euler tour technique is common in secondary-school and first-year university syllabi. It links to neighbouring topics Graph algorithms, Parallel computing, so understanding it makes those chapters shorter.
In everyday life
Look for Euler tour technique outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Euler tour technique” →

How to study Euler tour technique in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Euler tour technique means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Euler tour technique out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Euler tour technique in simple terms?

The Euler tour technique (ETT), named after Leonhard Euler, is a method in graph theory for representing trees. The tree is viewed as a directed graph that contains two directed edges for each edge in the tree.

Why does Euler tour technique matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Euler tour technique?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Euler tour technique.

Tags

  • Graph algorithms
  • Parallel computing

Keep exploring