parallel algorithms for trees
DESCRIPTION
How to operate on tree data structures using multiple parallel threads of execution. Parallel algorithms allows for achieving higher performance on multi-core machines, but getting the correct result from parallel execution can be tricky. This set of slides illustrates a few primary algorithms that operate on tree data structures in parallel.TRANSCRIPT
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Introduction Building Euler Tours Applications of Euler Tours Conclusion
Questions
Questions
???
ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 42