HOME

TheInfoList



OR:

The Euler tour technique (ETT), named after
Leonhard Euler Leonhard Euler ( , ; 15 April 170718 September 1783) was a Swiss mathematician, physicist, astronomer, geographer, logician and engineer who founded the studies of graph theory and topology and made pioneering and influential discoveries in ma ...
, is a method in
graph theory In mathematics, graph theory is the study of ''graphs'', which are mathematical structures used to model pairwise relations between objects. A graph in this context is made up of '' vertices'' (also called ''nodes'' or ''points'') which are conn ...
for representing
trees In botany, a tree is a perennial plant with an elongated stem, or trunk, usually supporting branches and leaves. In some usages, the definition of a tree may be narrower, including only woody plants with secondary growth, plants that are u ...
. The tree is viewed as a
directed graph In mathematics, and more specifically in graph theory, a directed graph (or digraph) is a graph that is made up of a set of vertices connected by directed edges, often called arcs. Definition In formal terms, a directed graph is an ordered pa ...
that contains two directed edges for each edge in the tree. The tree can then be represented as a
Eulerian circuit In graph theory, an Eulerian trail (or Eulerian path) is a trail in a finite graph that visits every edge exactly once (allowing for revisiting vertices). Similarly, an Eulerian circuit or Eulerian cycle is an Eulerian trail that starts and ends ...
of the directed graph, known as the Euler tour representation (ETR) of the tree. The ETT allows for efficient,
parallel computation Parallel computing is a type of computation in which many calculations or processes are carried out simultaneously. Large problems can often be divided into smaller ones, which can then be solved at the same time. There are several different fo ...
of solutions to common problems in
algorithmic graph theory In mathematics, graph theory is the study of ''graphs'', which are mathematical structures used to model pairwise relations between objects. A graph in this context is made up of '' vertices'' (also called ''nodes'' or ''points'') which are conn ...
. 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 in the tree, insert (''u'',''v'') and (''v'',''u'') in the edge list. * Sort the edge list
lexicographically In mathematics, the lexicographic or lexicographical order (also known as lexical order, or dictionary order) is a generalization of the alphabetical order of the dictionaries to sequences of ordered symbols or, more generally, of elements of a ...
. (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: : \mathrm(u,v)=\begin \mathrm(v,u) & \mathrm(v,u)\neq \mathrm \\ \mathrm(v)&\text. \end 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 In computer science, the prefix sum, cumulative sum, inclusive scan, or simply scan of a sequence of numbers is a second sequence of numbers , the sums of prefixes ( running totals) of the input sequence: : : : :... For instance, the prefix sums ...
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 In computer science, a self-balancing binary search tree (BST) is any node-based binary search tree that automatically keeps its height (maximal number of levels below the root) small in the face of arbitrary item insertions and deletions.Donald ...
, 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.Euler tour trees
- in Lecture Notes in Advanced Data Structures. Prof. Erik Demaine; Scribe: Katherine Lai.


References

{{Reflist Graph algorithms Parallel computing