You are on page 1of 5

Euler’s tour

Euler tour is defined as a way of traversing tree such that each vertex is added to the tour
when we visit it (either moving down from parent vertex or returning from child vertex). We
start from root and reach back to root after visiting all vertices.
It requires exactly 2*N-1 vertices to store Euler tour.
Tham quan Euler được định nghĩa là một cách đi ngang qua cây sao cho mỗi đỉnh được thêm
vào tham quan khi chúng ta truy cập nó (di chuyển xuống từ đỉnh mẹ hoặc quay trở lại từ đỉnh
con). Chúng tôi bắt đầu từ gốc và quay trở lại gốc sau khi thăm tất cả các đỉnh.
Nó yêu cầu chính xác 2 * N-1 đỉnh để lưu trữ chuyến tham quan Euler.

Approach: We will run DFS(Depth first search) algorithm on Tree as:

(1) Visit root node, i.e 1 


vis[1]=1, Euler[0]=1 
run dfs() for all unvisited adjacent nodes(2) 
(2) Visit node 2 
vis[2]=1, Euler[1]=2 
run dfs() for all unvisited adjacent nodes(3, 4) 
(3) Visit node 3 
vis[3]=1, Euler[2]=3 
All adjacent nodes are already visited, return to parent node 
and add parent to Euler tour Euler[3]=2 
(4) Visit node 4 
vis[4]=1, Euler[4]=4 
All adjacent nodes are already visited, return to parent node 
and add parent to Euler tour, Euler[5]=2 
(5) Visit node 2 
All adjacent nodes are already visited, return to parent node 
and add parent to Euler tour, Euler[6]=1 
(6) Visit node 1 
All adjacent nodes are already visited, and node 1 is root node 
so, we stop our recursion here.
Phương pháp tiếp cận : Chúng tôi sẽ chạy thuật toán DFS (Tìm kiếm độ sâu đầu tiên)
trên Cây như: 

(1) Truy cập nút gốc, tức là 1 


vis [1] = 1, Euler [0] = 1 
chạy dfs () cho tất cả các nút liền kề chưa được truy cập (2) 
(2) Truy cập nút 2 
vis [2] = 1, Euler [1 ] = 2 
chạy dfs () cho tất cả các nút liền kề chưa được truy cập (3, 4) 
(3) Truy cập nút 3 
vis [3] = 1, Euler [2] = 3 
Tất cả các nút liền kề đã được truy cập, quay lại nút cha 
và thêm nút cha đến chuyến tham quan Euler Euler [3] = 2 
(4) Truy cập nút 4 
vis [4] = 1, Euler [4] = 4 
Tất cả các nút liền kề đã được truy cập, hãy quay lại nút mẹ 
và thêm nút mẹ vào chuyến tham quan Euler, Euler [5] = 2 
(5) Truy cập nút 2 
Tất cả các nút liền kề đã được truy cập, hãy quay lại nút cha 
và thêm cha vào tham quan Euler, Euler [6] = 1 
(6) Truy cập nút 1 
Tất cả các nút liền kề đều đã được truy cập và nút 1 là nút gốc 
, vì vậy, chúng tôi dừng đệ quy của chúng tôi tại đây.
Aplication
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):

1. 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.
2. 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.
3. 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.
4. The depth-first search index of a node v: count the number of advance edges up to
and including (u,v).
5. Determine the lowest common ancestor of two nodes.
Tất cả các vấn đề sau có thể được giải quyết trong O (Tiền tố sum ( n )) (thời gian cần thiết để giải
song song bài toán tổng tiền tố cho danh sách n mục):

1. Phân loại cạnh trước và cạnh rút lui: Thực hiện xếp hạng danh sách trên ETR và
lưu kết quả trong mảng A hai chiều . Khi đó ( u , v ) là một cạnh trước iff A ( u , v )
<  A ( v , u ) và ngược lại là một cạnh rút lui.
2. Xác định mức của mỗi nút: Tính tổng tiền tố trên ETR, trong đó mọi cạnh trước
được tính là 1 và mọi cạnh rút lui được tính là −1. Khi đó giá trị ở cạnh trước ( u , v )
là mức của v .
3. Số nút trong cây con bắt nguồn từ v : giả sử cha của v là u, xác định cạnh trước
( u , v ) và cạnh rút ( v , u ) song song, sau đó đếm số cạnh trước giữa ( u , v ) và
( v , u ) sử dụng tổng tiền tố.
4. Chỉ số tìm kiếm theo độ sâu của nút v : đếm số cạnh trước lên đến và bao gồm
( u , v ).
5. Xác định tổ tiên chung thấp nhất của hai nút.

Euler’s cycle
is a path in graph that visits every edge exactly once. Eulerian Circuit is an
Eulerian Path which starts and ends on the same vertex. 
Đường dẫn Eulerian là một đường dẫn trong biểu đồ truy cập mọi cạnh chính
xác một lần. Eulerian Circuit là một Eulerian Path bắt đầu và kết thúc trên cùng
một đỉnh. 
Application
Eulerian trails are used in bioinformatics to reconstruct the DNA sequence from its fragments.
[13]
 They are also used in CMOS circuit design to find an optimal logic gate ordering.[14] There are
some algorithms for processing trees that rely on an Euler tour of the tree (where each edge is
treated as a pair of arcs).[15][16] The de Bruijn sequences can be constructed as Eulerian trails of de
Bruijn graphs.[17]

Các đường mòn Eulerian được sử dụng trong tin sinh học để tái tạo lại trình tự DNA từ các đoạn
của nó. [13] Chúng cũng được sử dụng trong thiết kế mạch CMOS để tìm thứ tự cổng logic tối
ưu . [14] Có một số thuật toán xử lý cây dựa trên chuyến tham quan cây của Euler (trong đó mỗi cạnh
được coi như một cặp cung). [15] [16] Các trình tự de Bruijn có thể được xây dựng dưới dạng đường
mòn Eulerian của đồ thị de Bruijn . [17]

You might also like