Parallel Algorithms for Trees
-
Upload
ahmad-khayyat -
Category
Education
-
view
2.404 -
download
3
description
Transcript of Parallel Algorithms for Trees
![Page 1: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/1.jpg)
Parallel Algorithms for Trees
Ahmad KhayyatDepartment of Electrical & Computer Engineering
Parallel Computation: Models and MethodsSelim G. Akl Chapter 6
CISC 879 — Algorithms and ApplicationsQueen’s University
October 29, 2008
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 1
![Page 2: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/2.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Outline
1 Introduction
2 Building Euler Tours
3 Applications of Euler Tours
4 Conclusion
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 2
![Page 3: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/3.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Graphs
Outline
1 IntroductionGraphsEuler Tours
2 Building Euler Tours
3 Applications of Euler Tours
4 Conclusion
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 3
![Page 4: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/4.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Graphs
Graphs
A Graph G = (V,E) is a set of vertices V connected by a setof edges E.
If the edges have orientation, the graph is directed.
A path is an ordered list of edges in the form(vi, vj), (vj , vk), (vk, vl).
A cycle is a path that begins and ends at the same vertex.
The degree of a vertex in an undirected graph is the numberof edges adjacent to the vertex.
The in-degree of a vertex v in a directed graph is the numberof edges entering v,The out-degree of a vertex v in a directed graph is thenumber of edges leaving v.
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 4
![Page 5: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/5.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Euler Tours
Outline
1 IntroductionGraphsEuler Tours
2 Building Euler Tours
3 Applications of Euler Tours
4 Conclusion
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 5
![Page 6: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/6.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Euler Tours
Euler Tours
Euler Tour (ET)
A cycle where every edge of the graph appears in the cycle exactlyonce.
An undirected graph has an Euler tour if each vertex has an evendegree.
(v1, v7), (v7, v2), (v2, v3), (v3, v6)
(v6, v7), (v7, v5), (v5, v6)
(v6, v4), (v4, v5), (v5, v1)
v1
v5
v7
v4 v6 v3
v2
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 6
![Page 7: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/7.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Euler Tours
Euler Tours
Euler Tour (ET)
A cycle where every edge of the graph appears in the cycle exactlyonce.
An undirected graph has an Euler tour if each vertex has an evendegree.
(v1, v7), (v7, v2), (v2, v3), (v3, v6)
(v6, v7), (v7, v5), (v5, v6)
(v6, v4), (v4, v5), (v5, v1)
v1
v5
v7
v4 v6 v3
v2
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 6
![Page 8: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/8.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Euler Tours
Euler Tours
Euler Tour (ET)
A cycle where every edge of the graph appears in the cycle exactlyonce.
An undirected graph has an Euler tour if each vertex has an evendegree.
(v1, v7), (v7, v2), (v2, v3), (v3, v6)
(v6, v7), (v7, v5), (v5, v6)
(v6, v4), (v4, v5), (v5, v1)
v1
v5
v7
v4 v6 v3
v2
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 6
![Page 9: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/9.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Euler Tours
Euler Tours
Euler Tour (ET)
A cycle where every edge of the graph appears in the cycle exactlyonce.
An undirected graph has an Euler tour if each vertex has an evendegree.
(v1, v7), (v7, v2), (v2, v3), (v3, v6)
(v6, v7), (v7, v5), (v5, v6)
(v6, v4), (v4, v5), (v5, v1) v1
v5
v7
v4 v6 v3
v2
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 6
![Page 10: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/10.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Euler Tours
Euler Tours
Euler Tour (ET)
A cycle where every edge of the graph appears in the cycle exactlyonce.
A directed graph has an Euler tour if the in-degree of each vertexis equal to the out-degree of the vertex.
(v1, v2), (v2, v3), (v3, v4)
(v4, v2), (v2, v4)
(v4, v5), (v5, v6), (v6, v4), (v4, v6)
(v6, v5), (v5, v1)
v1 v2
v3 v4
v5 v6
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 6
![Page 11: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/11.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Euler Tours
Euler Tours
Euler Tour (ET)
A cycle where every edge of the graph appears in the cycle exactlyonce.
A directed graph has an Euler tour if the in-degree of each vertexis equal to the out-degree of the vertex.
(v1, v2), (v2, v3), (v3, v4)
(v4, v2), (v2, v4)
(v4, v5), (v5, v6), (v6, v4), (v4, v6)
(v6, v5), (v5, v1)
v1 v2
v3 v4
v5 v6
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 6
![Page 12: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/12.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Euler Tours
Euler Tours
Euler Tour (ET)
A cycle where every edge of the graph appears in the cycle exactlyonce.
A directed graph has an Euler tour if the in-degree of each vertexis equal to the out-degree of the vertex.
(v1, v2), (v2, v3), (v3, v4)
(v4, v2), (v2, v4)
(v4, v5), (v5, v6), (v6, v4), (v4, v6)
(v6, v5), (v5, v1)
v1 v2
v3 v4
v5 v6
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 6
![Page 13: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/13.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Euler Tours
Euler Tours
Euler Tour (ET)
A cycle where every edge of the graph appears in the cycle exactlyonce.
A directed graph has an Euler tour if the in-degree of each vertexis equal to the out-degree of the vertex.
(v1, v2), (v2, v3), (v3, v4)
(v4, v2), (v2, v4)
(v4, v5), (v5, v6), (v6, v4), (v4, v6)
(v6, v5), (v5, v1)
v1 v2
v3 v4
v5 v6
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 6
![Page 14: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/14.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Euler Tours
Euler Tours
Euler Tour (ET)
A cycle where every edge of the graph appears in the cycle exactlyonce.
A directed graph has an Euler tour if the in-degree of each vertexis equal to the out-degree of the vertex.
(v1, v2), (v2, v3), (v3, v4)
(v4, v2), (v2, v4)
(v4, v5), (v5, v6), (v6, v4), (v4, v6)
(v6, v5), (v5, v1)
v1 v2
v3 v4
v5 v6
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 6
![Page 15: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/15.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Euler Tours
Trees
Tree
An undirected graph that is connected and contains no cycles.
A tree with n vertices has exactly n− 1 edges.
A directed tree (DT) with n vertices has 2n− 2 edges.
ë Its ET is a sequence of 2n− 2 edges.
v1v3 v4
v5
v6v7
v2
v1v3 v4
v5
v6v7
v2
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 7
![Page 16: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/16.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Data Structure
Outline
1 Introduction
2 Building Euler ToursData StructureThe AlgorithmAnalysis
3 Applications of Euler Tours
4 Conclusion
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 8
![Page 17: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/17.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Data Structure
Directed Trees (DT) as Linked Lists
n linked lists, one for each vertex.
The nodes of a list are edges leaving that vertex.
(v1, v3)head(v1) (v1, v4) (v1, v5)
(v2, v7)head(v2)
(v3, v1)head(v3)
(v4, v1)head(v4)
(v5, v1)head(v5) (v5, v6) (v5, v7)
(v6, v5)head(v6)
(v7, v2)head(v7) (v7, v5)
v1v3 v4
v5
v6v7
v2
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 9
![Page 18: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/18.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
The Algorithm
Outline
1 Introduction
2 Building Euler ToursData StructureThe AlgorithmAnalysis
3 Applications of Euler Tours
4 Conclusion
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 10
![Page 19: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/19.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
The Algorithm
Algorithm Input and Output
Input:n linked lists representing a directed tree (DT).
Output:Compute the Euler tour (ET) for the given DT:
ë Arrange all the edges of the DT in a single linked list.ë Each edge (vi, vj) is followed by an edge (vj , vk).ë The first edge leaves some vertex vl, the last edge enters vl.
(v1, v3) (v3, v1) (v1, v4) (v4, v1)
(v1, v5) (v5, v6) (v6, v5) (v5, v7)
(v7, v2) (v2, v7) (v7, v5) (v5, v1)
v1v3 v4
v5
v6v7
v2
1
2 3
4
5 12
6
78
11
9
10
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 11
![Page 20: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/20.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
The Algorithm
Building the Euler Tour in Parallel
Assuming the shared-memory model, with n− 1 processors.
Each processor Pij , i < j, is in charge of two edges: (vi, vj)and (vj , vi).
Pij determines the position (actually, the successor) of thetwo nodes holding (vi, vj) and (vj , vi) (or ij and ji) — in ET.
Successor of (vi, vj)
if next(ji) = jk thensucc(ij) ← jk
elsesucc(ij) ← head(vj)
end if
Successor of (vj , vi)
if next(ij) = im thensucc(ji) ← im
elsesucc(ji) ← head(vi)
end if
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 12
![Page 21: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/21.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
The Algorithm
Example: Pij = P13Successor of (v1, v3)
Successor of (vi, vj)
if next(ji) = jk thensucc(ij) ← jk
elsesucc(ij) ← head(vj)
end if
(v1, v3) (v3, v1)
v1v3 v4
v5
v6v7
v2
(v1, v3)head(v1) (v1, v4) (v1, v5)...
(v3, v1)head(v3)
31
13
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 13
![Page 22: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/22.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
The Algorithm
Example: Pij = P13Successor of (v1, v3)
Successor of (vi, vj)
if next(ji) = jk thensucc(ij) ← jk
elsesucc(ij) ← head(vj)
end if
next(31) = null
(v1, v3) (v3, v1)
v1v3 v4
v5
v6v7
v2
(v1, v3)head(v1) (v1, v4) (v1, v5)...
(v3, v1)head(v3)
31
13
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 13
![Page 23: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/23.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
The Algorithm
Example: Pij = P13Successor of (v1, v3)
Successor of (vi, vj)
if next(ji) = jk thensucc(ij) ← jk
elsesucc(ij) ← head(vj)
end if
succ(13) ← head(v3)
(v1, v3) (v3, v1)
v1v3 v4
v5
v6v7
v2
(v1, v3)head(v1) (v1, v4) (v1, v5)...
(v3, v1)head(v3)
31
13
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 13
![Page 24: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/24.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
The Algorithm
Example: Pij = P13Successor of (v3, v1)
Successor of (vj , vi)
if next(ij) = im thensucc(ji) ← im
elsesucc(ji) ← head(vi)
end if
(v1, v3) (v3, v1) (v1, v4)
v1v3 v4
v5
v6v7
v2
(v1, v3)head(v1) (v1, v4) (v1, v5)...
(v3, v1)head(v3)
13
31
14
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 14
![Page 25: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/25.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
The Algorithm
Example: Pij = P13Successor of (v3, v1)
Successor of (vj , vi)
if next(ij) = im thensucc(ji) ← im
elsesucc(ji) ← head(vi)
end if
next(13) = 14
(v1, v3) (v3, v1) (v1, v4)
v1v3 v4
v5
v6v7
v2
(v1, v3)head(v1) (v1, v4) (v1, v5)...
(v3, v1)head(v3)
13
31
14
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 14
![Page 26: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/26.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
The Algorithm
Example: Pij = P13Successor of (v3, v1)
Successor of (vj , vi)
if next(ij) = im thensucc(ji) ← im
elsesucc(ji) ← head(vi)
end if
succ(31) ← 14
(v1, v3) (v3, v1) (v1, v4)
v1v3 v4
v5
v6v7
v2
(v1, v3)head(v1) (v1, v4) (v1, v5)...
(v3, v1)head(v3)
13
31
14
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 14
![Page 27: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/27.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Analysis
Outline
1 Introduction
2 Building Euler ToursData StructureThe AlgorithmAnalysis
3 Applications of Euler Tours
4 Conclusion
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 15
![Page 28: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/28.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Analysis
Correctness
Visits all the edges:
ë Every pair of edges is assigned to a processor.
Produces a single cycle, not several small cycles:
(vi, vj) (vj , vk)
(vj , vi) (vk, vj)
(vj , vi)head(vj) (vj , vk)
next(ji) = jk
next(jk) = ji, or head(vj) = ji
vi vj vk
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 16
![Page 29: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/29.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Analysis
Correctness
Visits all the edges:
ë Every pair of edges is assigned to a processor.
Produces a single cycle, not several small cycles:
(vi, vj) (vj , vk)
(vj , vi) (vk, vj)
(vj , vi)head(vj) (vj , vk)
next(ji) = jk
next(jk) = ji, or head(vj) = ji
vi vj vk
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 16
![Page 30: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/30.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Analysis
Complexity
t(n) = O(1)p(n) = n− 1 = O(n)
⇒ c(n) = O(n)
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 17
![Page 31: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/31.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Utility Computations
Outline
1 Introduction
2 Building Euler Tours
3 Applications of Euler ToursUtility ComputationsSimple Applications of Euler ToursComputing Minima
4 Conclusion
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 18
![Page 32: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/32.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Utility Computations
Pointer Jumping parent(vi) ← parent(parent(vi))
Find the root of v8.
Time Complexity
Sequential: O(n)
Parallel: O(log n)
v0
v1
v2
v3
v4
v5
v6
v7
v8
1
1
1
1
1
1
1
1
2
2
1
1
1
1
2
2
3
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 19
![Page 33: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/33.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Utility Computations
Pointer Jumping parent(vi) ← parent(parent(vi))
Find the root of v8.
Time Complexity
Sequential: O(n)
Parallel: O(log n)
v0
v1
v2
v3
v4
v5
v6
v7
v8
1
1
1
1
1
1
1
1
2
2
1
1
1
1
2
2
3
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 19
![Page 34: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/34.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Utility Computations
Pointer Jumping parent(vi) ← parent(parent(vi))
Find the root of v8.
Time Complexity
Sequential: O(n)
Parallel: O(log n)
v0
v1
v2
v3
v4
v5
v6
v7
v8
1
1
1
1
1
1
1
1
2
2
1
1
1
1
2
2
3
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 19
![Page 35: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/35.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Utility Computations
Pointer Jumping parent(vi) ← parent(parent(vi))
Find the root of v8.
Time Complexity
Sequential: O(n)
Parallel: O(log n)
v0
v1
v2
v3
v4
v5
v6
v7
v8
1
1
1
1
1
1
1
1
2
2
1
1
1
1
2
2
3
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 19
![Page 36: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/36.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Utility Computations
Parallel Prefix Computation for Linked Lists
Step 1: forall i do in parallelnext(i) ← succ(i)
Step 2: finished ← falseStep 3: while not finished do
(3.1) finished ← true(3.2) forall i do in parallel
(i) if next(i) 6= nil then(a) val(next(i)) ← val(i) ◦ val(next(i))(b) next(i) ← next(next(i))
(ii) if next(i) 6= nil then
finished common←−−−−− false
x0 x1
x0-1
x2
x1-2
x3
x2-3
x4
x3-4
x5
x4-5
x6
x5-6
x7
x6-7x0 x0-1 x0-2 x0-3 x1-4 x2-5 x3-6 x4-7x0-4 x0-5 x0-6 x0-7
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 20
Input & Output
Input: A linked listOutput: Prefix computation
![Page 37: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/37.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Utility Computations
Parallel Prefix Computation for Linked Lists
Step 1: forall i do in parallelnext(i) ← succ(i)
Step 2: finished ← falseStep 3: while not finished do
(3.1) finished ← true(3.2) forall i do in parallel
(i) if next(i) 6= nil then(a) val(next(i)) ← val(i) ◦ val(next(i))(b) next(i) ← next(next(i))
(ii) if next(i) 6= nil then
finished common←−−−−− false
x0 x1
x0-1
x2
x1-2
x3
x2-3
x4
x3-4
x5
x4-5
x6
x5-6
x7
x6-7x0
x0-1 x0-2 x0-3 x1-4 x2-5 x3-6 x4-7x0-4 x0-5 x0-6 x0-7
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 20
Notation
xa-b = xa ◦ xa+1 ◦ · · · ◦ xb
![Page 38: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/38.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Utility Computations
Parallel Prefix Computation for Linked Lists
Step 1: forall i do in parallelnext(i) ← succ(i)
Step 2: finished ← falseStep 3: while not finished do
(3.1) finished ← true(3.2) forall i do in parallel
(i) if next(i) 6= nil then(a) val(next(i)) ← val(i) ◦ val(next(i))(b) next(i) ← next(next(i))
(ii) if next(i) 6= nil then
finished common←−−−−− false
x0 x1
x0-1
x2
x1-2
x3
x2-3
x4
x3-4
x5
x4-5
x6
x5-6
x7
x6-7
x0 x0-1 x0-2 x0-3 x1-4 x2-5 x3-6 x4-7
x0-4 x0-5 x0-6 x0-7
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 20
![Page 39: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/39.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Utility Computations
Parallel Prefix Computation for Linked Lists
Step 1: forall i do in parallelnext(i) ← succ(i)
Step 2: finished ← falseStep 3: while not finished do
(3.1) finished ← true(3.2) forall i do in parallel
(i) if next(i) 6= nil then(a) val(next(i)) ← val(i) ◦ val(next(i))(b) next(i) ← next(next(i))
(ii) if next(i) 6= nil then
finished common←−−−−− false
x0 x1
x0-1
x2
x1-2
x3
x2-3
x4
x3-4
x5
x4-5
x6
x5-6
x7
x6-7
x0 x0-1 x0-2 x0-3
x1-4 x2-5 x3-6 x4-7
x0-4 x0-5 x0-6 x0-7
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 20
Complexity
t(n) = O(log n)p(n) = n
![Page 40: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/40.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Utility Computations
Parallel Suffix Computation for Linked Lists
Step 1: forall i do in parallelnext(i) ← succ(i)
Step 2: finished ← falseStep 3: while not finished do
(3.1) finished ← true(3.2) forall i do in parallel
(i) if next(i) 6= nil then(a) val(i) ← val(i) ◦ val(next(i))(b) next(i) ← next(next(i))
(ii) if next(i) 6= nil then
finished common←−−−−− false
x0 x1 x2 x3 x4 x5 x6 x7
x0-7 x1-7 x2-7 x3-7 x4-7 x5-7 x6-7 x7
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 21
Complexity
t(n) = O(log n)p(n) = n
![Page 41: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/41.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Utility Computations
List Sequencing
List Sequencing
Computing the distance of each node from the beginning of thelist (node position).
Input: Linked list L Output: Sequence numbers
forall i do in parallel
val(i) ← 1
Parallel-Prefix(L, +)
1 1 1 1 1 1 1 1
1 2 3 4 5 6 7 8
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 22
![Page 42: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/42.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Utility Computations
List Sequencing
List Sequencing
Computing the distance of each node from the beginning of thelist (node position).
Input: Linked list L Output: Sequence numbers
forall i do in parallel
val(i) ← 1
Parallel-Prefix(L, +)
1 1 1 1 1 1 1 1
1 2 3 4 5 6 7 8
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 22
![Page 43: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/43.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Utility Computations
List Ranking
List Ranking
Computing the distance of each node from the end of the list.
Input: Linked list L Output: Node ranks
forall i do in parallel
(3.1) val(i) ← 1
(3.2) if succ(i) 6= nil then
succ(succ(i)) ← i
Parallel-Prefix(L, +)
1 1 1 1 1 1 1 1
8 7 6 5 4 3 2 1
Complexityt(n) = O(log n), p(n) = O(n)
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 23
![Page 44: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/44.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Utility Computations
List Ranking
List Ranking
Computing the distance of each node from the end of the list.
Input: Linked list L Output: Node ranks
forall i do in parallel
(3.1) val(i) ← 1
(3.2) if succ(i) 6= nil then
succ(succ(i)) ← i
Parallel-Prefix(L, +)
1 1 1 1 1 1 1 1
8 7 6 5 4 3 2 1
Complexityt(n) = O(log n), p(n) = O(n)
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 23
![Page 45: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/45.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Utility Computations
List Ranking
List Ranking
Computing the distance of each node from the end of the list.
Input: Linked list L Output: Node ranks
forall i do in parallel
(3.1) val(i) ← 1
(3.2) if succ(i) 6= nil then
succ(succ(i)) ← i
Parallel-Prefix(L, +)
1 1 1 1 1 1 1 1
8 7 6 5 4 3 2 1
Complexityt(n) = O(log n), p(n) = O(n)
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 23
![Page 46: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/46.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Simple Applications of Euler Tours
Outline
1 Introduction
2 Building Euler Tours
3 Applications of Euler ToursUtility ComputationsSimple Applications of Euler ToursComputing Minima
4 Conclusion
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 24
![Page 47: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/47.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Simple Applications of Euler Tours
An Euler Tour is a . . .
v1v3 v4
v5
v6v7
v2
1
2 3
4
5 12
6
78
11
9
10
An Euler Tour returns to the root of a subtree only after allvertices in the subtree have been visited.
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 25
![Page 48: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/48.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Simple Applications of Euler Tours
Depth-First Traversal
v1v3 v4
v5
v6v7
v2
1
2 3
4
5 12
6
78
11
9
10
An Euler Tour returns to the root of a subtree only after allvertices in the subtree have been visited.
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 25
![Page 49: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/49.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Simple Applications of Euler Tours
Finding Parents
Recall:
ë pos(i) is node i’s sequence number.ë In an Euler Tour, a node looks like (vi, vj).ë If (vi, vj) is a node, then (vj , vi) is also a node.
pos(vi, vj) < pos(vj , vi) ⇒ (vi, vj) is an advance edgeotherwise (vi, vj) is a retreat edge.
parent(root) ← nilforall (vi, vj) ∈ ET do in parallel
if pos(vi, vj) < pos(vj , vi) thenparent(vj) ← vi
v1v3 v4
v5
v6v7
v2
1
2 3
4
5 12
6
78
11
9
10
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 26
![Page 50: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/50.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Simple Applications of Euler Tours
Counting Descendants des(vi)
The subtree of vi edges appear between the advance edge(parent(vi), vi) and the retreat edge (vi, parent(vi)) in ET.
Half of these edges are advance edges and half are retreat.
des(vi) is the number of advance edges in the subtree + 1.
des(vi) =pos(vi, parent(vi))− 1− pos(parent(vi), vi)
2+ 1
(v1, v3) (v3, v1) (v1, v4) (v4, v1)
(v1, v5) (v5, v6) (v6, v5) (v5, v7)
(v7, v2) (v2, v7) (v7, v5) (v5, v1)
v1v3 v4
v5
v6v7
v2
1
2 3
4
5 12
6
78
11
9
10
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 27
![Page 51: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/51.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Simple Applications of Euler Tours
Numbering Vertices Preorder (top-down)
The preorder number of a vertex vj is the number of advanceedges in ET traversed before reaching vj for the first time + 1.
preorder(root) ← 1forall (vi, vj) ∈ ET do in parallel
if pos(vi, vj) < pos(vj , vi) then
val(ij) ← 1
else
val(ij) ← 0
Parallel-Prefix(ET, +)
forall (vi, vj) ∈ ET do in parallelif pos(vi, vj) < pos(vj , vi) then
preorder(vj) ← val(ij) + 1
v1v3 v4
v5
v6v7
v2
1
2 3
4
5 12
6
78
11
9
10
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 28
![Page 52: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/52.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Simple Applications of Euler Tours
Numbering Vertices Preorder (top-down)
The preorder number of a vertex vj is the number of advanceedges in ET traversed before reaching vj for the first time + 1.
preorder(root) ← 1forall (vi, vj) ∈ ET do in parallel
if pos(vi, vj) < pos(vj , vi) then
val(ij) ← 1
else
val(ij) ← 0
Parallel-Prefix(ET, +)
forall (vi, vj) ∈ ET do in parallelif pos(vi, vj) < pos(vj , vi) then
preorder(vj) ← val(ij) + 1
1, 3
1
1
3, 1
0
1
1, 4
1
1
4, 1
0
2
1, 5
1
1
5, 6
1
1
6, 5
0
4
5, 7
1
1
7, 2
1
1
2, 7
0
6
7, 5
0
6
5, 1
0
6
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 28
![Page 53: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/53.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Simple Applications of Euler Tours
Numbering Vertices Preorder (top-down)
The preorder number of a vertex vj is the number of advanceedges in ET traversed before reaching vj for the first time + 1.
preorder(root) ← 1forall (vi, vj) ∈ ET do in parallel
if pos(vi, vj) < pos(vj , vi) then
val(ij) ← 1
else
val(ij) ← 0
Parallel-Prefix(ET, +)
forall (vi, vj) ∈ ET do in parallelif pos(vi, vj) < pos(vj , vi) then
preorder(vj) ← val(ij) + 1
1, 3
11
3, 1
01
1, 4
12
4, 1
02
1, 5
13
5, 6
14
6, 5
04
5, 7
15
7, 2
16
2, 7
06
7, 5
06
5, 1
06
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 28
![Page 54: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/54.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Simple Applications of Euler Tours
Numbering Vertices Preorder (top-down)
The preorder number of a vertex vj is the number of advanceedges in ET traversed before reaching vj for the first time + 1.
preorder(root) ← 1forall (vi, vj) ∈ ET do in parallel
if pos(vi, vj) < pos(vj , vi) then
val(ij) ← 1
else
val(ij) ← 0
Parallel-Prefix(ET, +)
forall (vi, vj) ∈ ET do in parallelif pos(vi, vj) < pos(vj , vi) then
preorder(vj) ← val(ij) + 1
1, 3
12
3, 1
0
1
1, 4
13
4, 1
0
2
1, 5
14
5, 6
15
6, 5
0
4
5, 7
16
7, 2
17
2, 7
0
6
7, 5
0
6
5, 1
0
6
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 28
![Page 55: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/55.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Simple Applications of Euler Tours
Numbering Vertices Postorder (bottom-up)
The postorder number of a vertex vi is the number of retreat edgesin ET traversed before reaching vi for the last time + 1.
postorder(root) ← nforall (vi, vj) ∈ ET do in parallel
if pos(vi, vj) < pos(vj , vi) then
val(ij) ← 0
else
val(ij) ← 1
Parallel-Prefix(ET, +)
forall (vi, vj) ∈ ET do in parallelif pos(vi, vj) > pos(vj , vi) then
postorder(vi) ← val(ij)
v1v3 v4
v5
v6v7
v2
1
2 3
4
5 12
6
78
11
9
10
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 29
![Page 56: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/56.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Simple Applications of Euler Tours
Numbering Vertices Postorder (bottom-up)
The postorder number of a vertex vi is the number of retreat edgesin ET traversed before reaching vi for the last time + 1.
postorder(root) ← nforall (vi, vj) ∈ ET do in parallel
if pos(vi, vj) < pos(vj , vi) then
val(ij) ← 0
else
val(ij) ← 1
Parallel-Prefix(ET, +)
forall (vi, vj) ∈ ET do in parallelif pos(vi, vj) > pos(vj , vi) then
postorder(vi) ← val(ij)
1, 3
0
0
3, 1
1
1
1, 4
0
1
4, 1
1
2
1, 5
0
2
5, 6
0
2
6, 5
1
3
5, 7
0
3
7, 2
0
3
2, 7
1
4
7, 5
1
5
5, 1
1
6
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 29
![Page 57: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/57.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Simple Applications of Euler Tours
Numbering Vertices Postorder (bottom-up)
The postorder number of a vertex vi is the number of retreat edgesin ET traversed before reaching vi for the last time + 1.
postorder(root) ← nforall (vi, vj) ∈ ET do in parallel
if pos(vi, vj) < pos(vj , vi) then
val(ij) ← 0
else
val(ij) ← 1
Parallel-Prefix(ET, +)
forall (vi, vj) ∈ ET do in parallelif pos(vi, vj) > pos(vj , vi) then
postorder(vi) ← val(ij)
1, 3
00
3, 1
11
1, 4
01
4, 1
12
1, 5
02
5, 6
02
6, 5
13
5, 7
03
7, 2
03
2, 7
14
7, 5
15
5, 1
16
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 29
![Page 58: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/58.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Simple Applications of Euler Tours
Numbering Vertices Postorder (bottom-up)
The postorder number of a vertex vi is the number of retreat edgesin ET traversed before reaching vi for the last time + 1.
postorder(root) ← nforall (vi, vj) ∈ ET do in parallel
if pos(vi, vj) < pos(vj , vi) then
val(ij) ← 0
else
val(ij) ← 1
Parallel-Prefix(ET, +)
forall (vi, vj) ∈ ET do in parallelif pos(vi, vj) > pos(vj , vi) then
postorder(vi) ← val(ij)
1, 3
0
0
3, 1
11
1, 4
0
1
4, 1
12
1, 5
0
2
5, 6
0
2
6, 5
13
5, 7
0
3
7, 2
0
3
2, 7
14
7, 5
15
5, 1
16
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 29
![Page 59: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/59.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Simple Applications of Euler Tours
Tree Binary Relations
“An Euler Tour returns to the root of a subtree only after allvertices in the subtree have been visited.”
vi is an ancestor of vj (vj is a descendant of vi) iff:
preorder(vi) ≤ preorder(vj) < preorder(vi) + des(vi)
Examples:
v7 is an ancestor of v2:
6 ≤ 7 < 6 + 2 = 8
v6 is not an ancestor of v2:
5 ≤ 7 ≮ 5 + 1 = 6
v1
1
v3
2
v4
3
v5
v6
5
v7
6
v2
74
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 30
![Page 60: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/60.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Simple Applications of Euler Tours
Levels of Vertices
level(vj) = retreat edges − advance edges, following first vj in ET
= advance edges − retreat edges, up to first vj in ET
level(root) ← 0forall (vi, vj) ∈ ET do in parallel
if pos(vi, vj) < pos(vj , vi) then
val(ij) ← −1
else
val(ij) ← 1
Parallel-Suffix(ET, +)
forall (vi, vj) ∈ ET do in parallelif pos(vi, vj) < pos(vj , vi) then
level(vj) ← val(ij) + 1
1, 3
−1
1
3, 1
1
1
1, 4
−1
1
4, 1
1
1
1, 5
−1
1
5, 6
−1
1
6, 5
1
2
5, 7
−1
1
7, 2
−1
1
2, 7
1
3
7, 5
1
2
5, 1
1
1
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 31
![Page 61: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/61.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Simple Applications of Euler Tours
Levels of Vertices
level(vj) = retreat edges − advance edges, following first vj in ET
= advance edges − retreat edges, up to first vj in ET
level(root) ← 0forall (vi, vj) ∈ ET do in parallel
if pos(vi, vj) < pos(vj , vi) then
val(ij) ← −1
else
val(ij) ← 1
Parallel-Suffix(ET, +)
forall (vi, vj) ∈ ET do in parallelif pos(vi, vj) < pos(vj , vi) then
level(vj) ← val(ij) + 1
1, 3
−10
3, 1
11
1, 4
−10
4, 1
11
1, 5
−10
5, 6
−11
6, 5
12
5, 7
−11
7, 2
−12
2, 7
13
7, 5
12
5, 1
11
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 31
![Page 62: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/62.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Simple Applications of Euler Tours
Levels of Vertices
level(vj) = retreat edges − advance edges, following first vj in ET
= advance edges − retreat edges, up to first vj in ET
level(root) ← 0forall (vi, vj) ∈ ET do in parallel
if pos(vi, vj) < pos(vj , vi) then
val(ij) ← −1
else
val(ij) ← 1
Parallel-Suffix(ET, +)
forall (vi, vj) ∈ ET do in parallelif pos(vi, vj) < pos(vj , vi) then
level(vj) ← val(ij) + 1
1, 3
−11
3, 1
1
1
1, 4
−11
4, 1
1
1
1, 5
−11
5, 6
−12
6, 5
1
2
5, 7
−12
7, 2
−13
2, 7
1
3
7, 5
1
2
5, 1
1
1
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 31
![Page 63: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/63.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Simple Applications of Euler Tours
Levels of Vertices
level(vj) = retreat edges − advance edges, following first vj in ET= advance edges − retreat edges, up to first vj in ET
level(root) ← 0forall (vi, vj) ∈ ET do in parallel
if pos(vi, vj) < pos(vj , vi) then
val(ij) ← −1
else
val(ij) ← 1
Parallel-Suffix(ET, +)
forall (vi, vj) ∈ ET do in parallelif pos(vi, vj) < pos(vj , vi) then
level(vj) ← val(ij) + 1
1, 3
−11
3, 1
1
1
1, 4
−11
4, 1
1
1
1, 5
−11
5, 6
−12
6, 5
1
2
5, 7
−12
7, 2
−13
2, 7
1
3
7, 5
1
2
5, 1
1
1
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 31
![Page 64: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/64.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Computing Minima
Outline
1 Introduction
2 Building Euler Tours
3 Applications of Euler ToursUtility ComputationsSimple Applications of Euler ToursComputing Minima
4 Conclusion
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 32
![Page 65: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/65.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Computing Minima
The Interval Minima Problem
S = {sk : k = preorder(vi)⇒ sk = val(vi)}
Svi = {sk, sk+1, . . . , s`}, ` = k + des(vi)− 1
find min(Svi) ∀ vi
Example:
3 = preorder(v5), s3 = 6S = {10, 5, 6, 7, 3, 4, 2, 1}
Sv2 : k = 2, ` = 2 + 5− 1 = 6Sv2 = {5, 6, 7, 3, 4}
v110
1
v32
7v25
2
v56
3
v41
8
v63
5
v77
4v84
6
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 33
![Page 66: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/66.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Computing Minima
The Interval Minima Problem
S = {sk : k = preorder(vi)⇒ sk = val(vi)}
Svi = {sk, sk+1, . . . , s`}, ` = k + des(vi)− 1
find min(Svi) ∀ vi
Example:
3 = preorder(v5), s3 = 6S = {10, 5, 6, 7, 3, 4, 2, 1}
Sv2 : k = 2, ` = 2 + 5− 1 = 6Sv2 = {5, 6, 7, 3, 4}
v110
1
v32
7v25
2
v56
3
v41
8
v63
5
v77
4v84
6
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 33
![Page 67: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/67.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Computing Minima
The Interval Minima Problem
S = {sk : k = preorder(vi)⇒ sk = val(vi)}
Svi = {sk, sk+1, . . . , s`}, ` = k + des(vi)− 1
find min(Svi) ∀ vi
Example:
3 = preorder(v5), s3 = 6S = {10, 5, 6, 7, 3, 4, 2, 1}
Sv2 : k = 2, ` = 2 + 5− 1 = 6Sv2 = {5, 6, 7, 3, 4}
v110
1
v32
7v25
2
v56
3
v41
8
v63
5
v77
4v84
6
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 33
![Page 68: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/68.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Computing Minima
The Interval Minima Tree
Prefix Minima (PM)
The prefix minima of a sequence {a1, a2, . . . , an} are given by asequence {b1, b2, . . . , bn} where bi = min(a1, a2, . . . , ai).
Suffix Minima (SM)
The suffix minima of a sequence {a1, a2, . . . , an} are given by asequence {d1, d2, . . . , dn} where di = min(ai, ai+1, . . . , an}.
PM 2 1 1 1 1 1
Seq. 2 1 3 4 5 6
SM 1 1 3 4 5 6
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 34
![Page 69: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/69.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Computing Minima
The Interval Minima Tree
Prefix Minima (PM)
The prefix minima of a sequence {a1, a2, . . . , an} are given by asequence {b1, b2, . . . , bn} where bi = min(a1, a2, . . . , ai).
Suffix Minima (SM)
The suffix minima of a sequence {a1, a2, . . . , an} are given by asequence {d1, d2, . . . , dn} where di = min(ai, ai+1, . . . , an}.
A complete binary tree such that:
Leaves are s1, s2, . . . , sn.
Each internal node x contains two sequences:the prefix minima (PM) and suffix minima (SM) of the valuesheld by leaves in the subtree rooted at x.
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 34
![Page 70: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/70.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Computing Minima
Constructing the Tree
PM =
10 ,5 ,5 ,5 ,3 ,3 ,2 ,1
SM =
1 ,1 ,1 ,1 ,1 ,1 ,1 ,1
PM =
10 ,5 ,5 ,5
SM =
5 ,5 ,6 ,7
PM =
3 ,3 ,2 ,1
SM =
1 ,1 ,1 ,1
PM =
10 ,5
SM =
5 ,5
v110
1 v25
2
PM =
6 ,6
SM =
6 ,7
v56
3 v77
4
PM =
3 ,3
SM =
3 ,4
v63
5 v84
6
PM =
2 ,1
SM =
1 ,1
v32
7 v41
8
v110
1
v32
7v25
2
v56
3
v41
8
v63
5
v77
4v84
6
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 35
![Page 71: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/71.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Computing Minima
Constructing the Tree
PM =
10 ,5 ,5 ,5 ,3 ,3 ,2 ,1
SM =
1 ,1 ,1 ,1 ,1 ,1 ,1 ,1
PM =
10 ,5 ,5 ,5
SM =
5 ,5 ,6 ,7
PM =
3 ,3 ,2 ,1
SM =
1 ,1 ,1 ,1
PM = 10 ,
5
SM =
5
,5
v110
1 v25
2
PM = 6 ,
6
SM =
6
,7
v56
3 v77
4
PM = 3 ,
3
SM =
3
,4
v63
5 v84
6
PM = 2 ,
1
SM =
1
,1
v32
7 v41
8
l1, l2, . . . , lp
Lr1, r2, . . . , rp
R
{min(lp, ri)}LPM:
{min(r1, li)} RSM:
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 35
![Page 72: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/72.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Computing Minima
Constructing the Tree
PM =
10 ,5 ,5 ,5 ,3 ,3 ,2 ,1
SM =
1 ,1 ,1 ,1 ,1 ,1 ,1 ,1
PM =
10 ,5 ,5 ,5
SM =
5 ,5 ,6 ,7
PM =
3 ,3 ,2 ,1
SM =
1 ,1 ,1 ,1
PM = 10 ,5
SM = 5 ,5
v110
1 v25
2
PM = 6 ,6
SM = 6 ,7
v56
3 v77
4
PM = 3 ,3
SM = 3 ,4
v63
5 v84
6
PM = 2 ,1
SM = 1 ,1
v32
7 v41
8
l1, l2, . . . , lp
Lr1, r2, . . . , rp
R
{min(lp, ri)}LPM:
{min(r1, li)} RSM:
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 35
![Page 73: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/73.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Computing Minima
Constructing the Tree
PM =
10 ,5 ,5 ,5 ,3 ,3 ,2 ,1
SM =
1 ,1 ,1 ,1 ,1 ,1 ,1 ,1
PM = 10 ,5 ,
5 ,5
SM =
5 ,5
,6 ,7
PM = 3 ,3 ,
2 ,1
SM =
1 ,1
,1 ,1
PM = 10 ,5
SM = 5 ,5
v110
1 v25
2
PM = 6 ,6
SM = 6 ,7
v56
3 v77
4
PM = 3 ,3
SM = 3 ,4
v63
5 v84
6
PM = 2 ,1
SM = 1 ,1
v32
7 v41
8
l1, l2, . . . , lp
Lr1, r2, . . . , rp
R
{min(lp, ri)}LPM:
{min(r1, li)} RSM:
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 35
![Page 74: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/74.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Computing Minima
Constructing the Tree
PM =
10 ,5 ,5 ,5 ,3 ,3 ,2 ,1
SM =
1 ,1 ,1 ,1 ,1 ,1 ,1 ,1
PM = 10 ,5 ,5 ,5
SM = 5 ,5 ,6 ,7
PM = 3 ,3 ,2 ,1
SM = 1 ,1 ,1 ,1
PM = 10 ,5
SM = 5 ,5
v110
1 v25
2
PM = 6 ,6
SM = 6 ,7
v56
3 v77
4
PM = 3 ,3
SM = 3 ,4
v63
5 v84
6
PM = 2 ,1
SM = 1 ,1
v32
7 v41
8
l1, l2, . . . , lp
Lr1, r2, . . . , rp
R
{min(lp, ri)}LPM:
{min(r1, li)} RSM:
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 35
![Page 75: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/75.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Computing Minima
Constructing the Tree
PM = 10 ,5 ,5 ,5 ,
3 ,3 ,2 ,1
SM =
1 ,1 ,1 ,1
,1 ,1 ,1 ,1
PM = 10 ,5 ,5 ,5
SM = 5 ,5 ,6 ,7
PM = 3 ,3 ,2 ,1
SM = 1 ,1 ,1 ,1
PM = 10 ,5
SM = 5 ,5
v110
1 v25
2
PM = 6 ,6
SM = 6 ,7
v56
3 v77
4
PM = 3 ,3
SM = 3 ,4
v63
5 v84
6
PM = 2 ,1
SM = 1 ,1
v32
7 v41
8
l1, l2, . . . , lp
Lr1, r2, . . . , rp
R
{min(lp, ri)}LPM:
{min(r1, li)} RSM:
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 35
![Page 76: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/76.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Computing Minima
Constructing the Tree
PM = 10 ,5 ,5 ,5 ,3 ,3 ,2 ,1
SM = 1 ,1 ,1 ,1 ,1 ,1 ,1 ,1
PM = 10 ,5 ,5 ,5
SM = 5 ,5 ,6 ,7
PM = 3 ,3 ,2 ,1
SM = 1 ,1 ,1 ,1
PM = 10 ,5
SM = 5 ,5
v110
1 v25
2
PM = 6 ,6
SM = 6 ,7
v56
3 v77
4
PM = 3 ,3
SM = 3 ,4
v63
5 v84
6
PM = 2 ,1
SM = 1 ,1
v32
7 v41
8
l1, l2, . . . , lp
Lr1, r2, . . . , rp
R
{min(lp, ri)}LPM:
{min(r1, li)} RSM:
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 35
![Page 77: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/77.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Computing Minima
Finding the Minima Using the TreeAn Example: Sv2
k = 2, ` = k + 5− 1 = 6 ⇒ Sv2 = {s2, . . . , s6}
PM = 10 ,5 ,5 ,5 ,3 ,3 ,2 ,1
SM = 1 ,1 ,1 ,1 ,1 ,1 ,1 ,1
PM = 10 ,5 ,5 ,5
SM = 5 ,5 ,6 ,7
PM = 3 ,3 ,2 ,1
SM = 1 ,1 ,1 ,1
PM = 10 ,5
SM = 5 ,5
v110
1 v25
2
PM = 6 ,6
SM = 6 ,7
v56
3 v77
4
PM = 3 ,3
SM = 3 ,4
v63
5 v84
6
PM = 2 ,1
SM = 1 ,1
v32
7 v41
8
v110
1
v32
7v25
2
v56
3
v41
8
v63
5
v77
4v84
6
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 36
![Page 78: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/78.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Computing Minima
Finding the Minima Using the TreeAn Example: Sv2
k = 2, ` = k + 5− 1 = 6 ⇒ Sv2 = {s2, . . . , s6}
PM = 10 ,5 ,5 ,5 ,3 ,3 ,2 ,1
SM = 1 ,1 ,1 ,1 ,1 ,1 ,1 ,1w
PM = 10 ,5 ,5 ,5
SM = 5 ,5 ,6 ,7
PM = 3 ,3 ,2 ,1
SM = 1 ,1 ,1 ,1
PM = 10 ,5
SM = 5 ,5
v110
1 v25
2
PM = 6 ,6
SM = 6 ,7
v56
3 v77
4
PM = 3 ,3
SM = 3 ,4
v63
5 v84
6
PM = 2 ,1
SM = 1 ,1
v32
7 v41
8
v110
1
v32
7v25
2
v56
3
v41
8
v63
5
v77
4v84
6
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 36
![Page 79: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/79.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Computing Minima
Finding the Minima Using the TreeAn Example: Sv2
k = 2, ` = k + 5− 1 = 6 ⇒ Sv2 = {s2, . . . , s6}
PM = 10 ,5 ,5 ,5 ,3 ,3 ,2 ,1
SM = 1 ,1 ,1 ,1 ,1 ,1 ,1 ,1w
PM = 10 ,5 ,5 ,5
SM = 5 ,5 ,6 ,7x
PM = 3 ,3 ,2 ,1
SM = 1 ,1 ,1 ,1y
PM = 10 ,5
SM = 5 ,5
v110
1 v25
2
PM = 6 ,6
SM = 6 ,7
v56
3 v77
4
PM = 3 ,3
SM = 3 ,4
v63
5 v84
6
PM = 2 ,1
SM = 1 ,1
v32
7 v41
8
v110
1
v32
7v25
2
v56
3
v41
8
v63
5
v77
4v84
6
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 36
![Page 80: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/80.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Computing Minima
The Interval Minima Algorithm
Input: A tree T Output: min(Svi) for all vi ∈ T
O(1) ET ← Parallel-Euler-Tour(T )O(log n) Parallel-Preorder(ET)O(log n) Parallel-Descendants(ET)O(log n) T ′ ← Interval-Minima-Tree(T )
forall vi ∈ T do in parallelO(1) k ← preorder(vi), `← k + des(vi)− 1
O(log n) w ← Lowest-Common-Ancestor(sk, s`) in T ′
O(1) x ← Left-Child(w), y ← Right-Child(w);
O(1) min(Svi)← min(SM(x)k , PM
(y)` )
Complexity:
t(n) = O(log n) p(n) = O(n) ⇒ c(n) = n log(n)
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 37
![Page 81: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/81.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Summary
Outline
1 Introduction
2 Building Euler Tours
3 Applications of Euler Tours
4 ConclusionSummaryQuestions
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 38
![Page 82: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/82.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Summary
Summary
ET
O(1)
DFT
O(1)
Prefix
O(log n)
Pos
O(log n)
Rank
O(log n)
Preorder
O(log n)
Parent
O(1)
Des
O(1)
Levels
O(log n)
Bin
O(1)
IntMin
O(log n)
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 39
![Page 83: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/83.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Summary
Thank You
Thank You!
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 40
![Page 84: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/84.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Questions
Outline
1 Introduction
2 Building Euler Tours
3 Applications of Euler Tours
4 ConclusionSummaryQuestions
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 41
![Page 85: Parallel Algorithms for Trees](https://reader033.fdocuments.in/reader033/viewer/2022052601/559138a81a28abfb488b470b/html5/thumbnails/85.jpg)
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Questions
Questions
???
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 42