SlideShare a Scribd company logo
1 of 48
Download to read offline
Algorithms
Parallel Algorithms
1
2
An overview of lecture
• The Euler tour technique
• Computation of different tree functions
• Tree contraction
• Evaluation of arithmetic expressions
3
Problems in parallel
computations of tree functions
• Computations of tree functions are
important for designing many algorithms for
trees and graphs.
• Some of these computations include
preorder, postorder, inorder numbering of
the nodes of a tree, number of descendants
of each vertex, level of each vertex etc.
4
Problems in parallel
computations of tree functions
• Most sequential algorithms for these
problems use depth-first search for solving
these problems.
• However, depth-first search seems to be
inherently sequential in some sense.
5
Parallel depth-first search
• It is difficult to do depth-first search in parallel.
• We cannot assign depth-first numbering to
the node n unless we have assigned depth-
first numbering to all the nodes in the subtree
A.
6
Parallel depth-first search
• There is a definite order of visiting the nodes
in depth-first search.
• We can introduce additional edges to the tree
to get this order.
• The Euler tour technique converts a tree into
a list by adding additional edges.
7
Parallel depth-first search
• The red (or, magenta ) arrows are followed when
we visit a node for the first (or, second) time.
• If the tree has n nodes, we can construct a list
with 2n - 2 nodes, where each arrow (directed
edge) is a node of the list.
8
Euler tour technique
• For a node v T, p(v) is the parent of v.
• Each red node in the list represents an edge of
the nature < p(v) , v >.
• We can determine the preorder numbering of a
node of the tree by counting the red nodes in the
list.
9
Euler tour technique
• Let T = (V, E) be a given tree and let T’ = (V, E’ )
be a directed graph obtained from T.
• Each edge (u, v) E is replaced by two edges
< u, v > and < v, u >.
• Both the indegree and outdegree of an internal
node of the tree are now same.
• The indegree and outdegree of a leaf is 1 each.
• Hence T’ is an Eulerian graph.
10
Euler tour technique
• An Euler circuit of a graph is an edge-disjoint
circuit which traverses all the nodes.
• A graph permits an Euler circuit if and only if
each vertex has equal indegree and outdegree.
• An Euler circuit can be used for optimal parallel
computation of many tree functions.
• To construct an Euler circuit, we have to specify
the successor edge for each edge.
11
Constructing an Euler tour
• Each edge on an Euler circuit has a unique
successor edge.
• For each vertex v V we fix an ordering of the
vertices adjacent to v.
• If d is the degree of vertex v, the vertices adjacent to
v are:
adj(v) = < u0, u1, …, ud -1 >
• The successor of edge < ui, v > is:
s(< ui, v >) = < v, u(i + 1) mod d >, 0 i (d - 1)
12
Constructing an Euler tour
13
Correctness of Euler tour
• Consider the graph T’ = (V, E’ ) , where E’ is obtained
by replacing each e E by two directed edges of
opposite directions.
Lemma: The successor function s defines only one
cycle and not a set of edge-disjoint cycles in T’.
Proof: We have already shown that the graph is
Eulerian.
• We prove the lemma through induction.
14
Correctness of Euler tour
basis: When the tree has 2 nodes, there is only
one edge and one cycle with two edges.
Suppose, the claim is true for n nodes. We
should show that it is true when there are n +
1 nodes.
15
Correctness of Euler tour
• We can introduce an extra node by introducing a
leaf to an existing tree, like the leaf v.
• Initially, adj(u) = <…, v’, v’’, …> . Hence,
s(< v’, u >) = < u, v’’ >.
16
Correctness of Euler tour
• After the introduction of v, adj(u) = <…, v’, v, v’’, …>
• s(< v’, u >) = < u, v > and
s(< v, u >) = < u, v’’ >
• Hence, there is only one cycle after v is
introduced.
17
Construction of Euler tour in
parallel
18
Construction of Euler tour in
parallel
• We assume that the tree is given as a set of
adjacency lists for the nodes. The adjacency list L[v]
for v is given in an array.
• Consider a node v and a node ui adjacent to v.
• We need:
– The successor < v, u(i + 1) mod d > for < ui, v >. This is done by
making the list circular.
– < ui, v >. This is done by keeping a direct pointer from ui in
L[v] to v in L[ui].
19
Construction of Euler tour in
parallel
• We can construct an Euler tour in O(1) time using
O(n) processors.
• One processor is assigned to each node of the
adjacency list.
• There is no need of concurrent reading, hence the
EREW PRAM model is sufficient.
20
Rooting a tree
• For doing any tree computation, we need to
know the parent p(v) for each node v.
• Hence, we need to root the tree at a vertex r.
• We first construct an Euler tour and for the
vertex r, set s(< ud -1, r >) = 0.
• ud -1 is the last vertex adjacent to r.
• In other words, we break the Euler tour at r.
21
Rooting a tree
22
Rooting a tree
23
Rooting a tree
Input: The Euler tour of a tree and a special
vertex r.
Output: For each vertex v r, the parent p(v) of
v in the tree rooted at r.
24
Rooting a tree
begin
1. Set s(< u, r >) = 0, where u is the last vertex in the
adjacency list of r.
2. Assign a weight 1 to each edge of the list and
compute parallel prefix.
3. For each edge < x, y >, set x = p(y) whenever the
prefix sum of < x, y > is smaller than the prefix sum
of < y, x >.
end
25
Rooting a tree
26
Computation of tree functions
• Given a tree T, for many tree computations:
– We first construct the Euler tour of T
– Then we root the tree at a vertex
• We can compute:
– The postorder number of each vertex
– The preorder number of each vertex
– The inorder number of each vertex
– The level of each vertex
– The number of descendants of each vertex.
27
Tree Contraction
• Some tree computations cannot be solved efficiently
with the Euler tour technique alone.
• An important problem is evaluation of an arithmetic
expression given as a binary tree.
28
Tree Contraction
• Each leaf holds a constant and each internal node
holds an arithmetic operator like +, .
• The goal is to compute the value of the expression
at the root.
• The tree contraction technique is a systematic way
of shrinking a tree into a single vertex.
• We successively apply the operation of merging a
leaf with its parent or merging a degree-2 vertex
with its parent.
29
The RAKE operation
• Let T = (V, E) be a rooted binary tree and for
each vertex v, p(v) is its parent.
• sib(v) is the child of p(v). We consider only binary
trees.
• In the rake operation for a leaf u such that p(u)
r.
– Remove u and p(u) from T, and
– Connect sib(u) to p(p(u)).
30
The RAKE operation
• In our tree contraction algorithm, we apply the rake
operation repeatedly to reduce the size of the binary
tree.
• We need to apply rake to many leaves in parallel in
order to achieve a fast running time.
31
The RAKE operation
• But we cannot apply rake operation to
nodes whose parents are consecutive on
the tree.
• For example, rake operation cannot be
applied to nodes 1 and 8 in parallel.
• We need to apply the rake operation to non-
consecutive leaves as they appear from left
to right.
32
The RAKE operation
• We first label the leaves consecutively from left to right.
• In an Euler path for a rooted tree, the leaves appear from
left to right.
• We can assign a weight 1 to each edge of the kind (v,
p(v)) where v is a leaf.
• We exclude the leftmost and the rightmost leaves. These
two leaves will be the two children of the root when the
tree is contracted to a three-node tree.
• We do a prefix sum on the resulting list and the leaves
are numbered from left to right.
33
The RAKE operation
• We now store all the n leaves in an array A.
• Aodd is the subarray consisting of the odd-
indexed elements of A.
• Aeven is the subarray consisting of the even-
indexed elements of A.
• We can create the arrays Aodd and Aeven in O(1)
time and O(n) work.
34
Tree contraction algorithm
begin
for iterations do
1. Apply the rake operation in parallel to all the
elements of Aodd that are left children
2. Apply the rake operation in parallel to the rest of
the elements in Aodd.
3. Set A := Aeven.
end
log( 1)n
35
Tree contraction algorithm
36
Correctness of tree contraction
• Whenever the rake operation is applied in parallel to
several leaves, the parents of any two such leaves are
not adjacent.
• The number of leaves reduces by half after each iteration
of the loop. Hence the tree is contracted in O(log n) time.
• Euler tour takes O(n) work.
• The total number of operations for all the iterations of the
loop is:
( ( ))
2i
i
n
O O n
37
An example
38
An example
39
Evaluation of arithmetic
expressions
• If we evaluate an expression tree bottom-up, it
will take O(n) time for a long and skinny tree.
• Hence we apply tree contraction.
40
Evaluation of arithmetic
expressions
• We do not completely evaluate each
internal node. We evaluate the internal
nodes partially.
• For each internal node v, we associate a
label (av, bv). av and bv are constants.
• The value of the expression at node is:
(av X + bv), where X is an unknown value for
the expression of the subtree rooted at v.
41
Keeping an invariant
Invariant:
• Let u be an internal node which holds the
operation , .
• Let v and w are the children of u with labels
(av, bv) and (aw, bw).
• Then the value at u is:
val(u) = (avval(v) + bv) (awval(w) + bw)
42
Keeping an invariant
43
Applying the rake operation
• The value at node u is:
val(u) = (avcv + bv) (aw X + bw)
• X is the unknown value at node w.
44
Applying the rake operation
• The contribution of val(u) to the value of node
p(u) is:
au val(u) + bu = au[(avcv + bv) (aw X + bw)] + bu
• We can adjust the labels of node w to (a’w ,
b’w)
• a’w = au(avcv + bv) aw
• b’w = au(avcv + bv) bw + bu
45
Complexity of expression
evaluation
• The correctness of the expression evaluation
depends on correctly maintaining the invariants.
• We start with a label (1, 0) for each leaf and correctly
maintain the invariant at each rake operation.
• We have already proved the correctness of the rake
operation.
• Hence, evaluation of an expression given as a
binary tree takes O(n) work and O(log n) time.
46
An example
47
An example
48
An example

More Related Content

What's hot

Huffman's algorithm in Data Structure
 Huffman's algorithm in Data Structure Huffman's algorithm in Data Structure
Huffman's algorithm in Data StructureVrushali Dhanokar
 
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES	UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES Kathirvel Ayyaswamy
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data StructureMeghaj Mallick
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queueSenthil Kumar
 
Towers Hanoi Algorithm
Towers Hanoi AlgorithmTowers Hanoi Algorithm
Towers Hanoi AlgorithmJorge Jasso
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]Muhammad Hammad Waseem
 
Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphsTilakpoudel2
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithmsRajendran
 
Array linear data_structure_2 (1)
Array linear data_structure_2 (1)Array linear data_structure_2 (1)
Array linear data_structure_2 (1)eShikshak
 
Knapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithmKnapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithmHoneyChintal
 
Anti aliasing,area sampling,koch curve and c curve
Anti aliasing,area sampling,koch curve and c curveAnti aliasing,area sampling,koch curve and c curve
Anti aliasing,area sampling,koch curve and c curvePallab Kumar Nandi
 
Heap Sort || Heapify Method || Build Max Heap Algorithm
Heap Sort || Heapify Method || Build Max Heap AlgorithmHeap Sort || Heapify Method || Build Max Heap Algorithm
Heap Sort || Heapify Method || Build Max Heap AlgorithmLearning Courses Online
 
Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Kumar
 
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...DrkhanchanaR
 

What's hot (20)

Huffman's algorithm in Data Structure
 Huffman's algorithm in Data Structure Huffman's algorithm in Data Structure
Huffman's algorithm in Data Structure
 
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES	UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Towers Hanoi Algorithm
Towers Hanoi AlgorithmTowers Hanoi Algorithm
Towers Hanoi Algorithm
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphs
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Array linear data_structure_2 (1)
Array linear data_structure_2 (1)Array linear data_structure_2 (1)
Array linear data_structure_2 (1)
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
 
Knapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithmKnapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithm
 
Huffman coding
Huffman coding Huffman coding
Huffman coding
 
Anti aliasing,area sampling,koch curve and c curve
Anti aliasing,area sampling,koch curve and c curveAnti aliasing,area sampling,koch curve and c curve
Anti aliasing,area sampling,koch curve and c curve
 
Heap Sort || Heapify Method || Build Max Heap Algorithm
Heap Sort || Heapify Method || Build Max Heap AlgorithmHeap Sort || Heapify Method || Build Max Heap Algorithm
Heap Sort || Heapify Method || Build Max Heap Algorithm
 
Physical Layer
Physical LayerPhysical Layer
Physical Layer
 
Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Back tracking and branch and bound class 20
Back tracking and branch and bound class 20
 
Transport layer
Transport layerTransport layer
Transport layer
 
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
 
Red black trees
Red black treesRed black trees
Red black trees
 

Similar to Problems in parallel computations of tree functions

Similar to Problems in parallel computations of tree functions (20)

Lec27
Lec27Lec27
Lec27
 
Avl tree detailed
Avl tree detailedAvl tree detailed
Avl tree detailed
 
Graph 1
Graph 1Graph 1
Graph 1
 
Graph
GraphGraph
Graph
 
Graph
GraphGraph
Graph
 
FALLSEM2023-24_BECE302L_TH_VL2023240100270_2023-05-04_Reference-Material-I.pptx
FALLSEM2023-24_BECE302L_TH_VL2023240100270_2023-05-04_Reference-Material-I.pptxFALLSEM2023-24_BECE302L_TH_VL2023240100270_2023-05-04_Reference-Material-I.pptx
FALLSEM2023-24_BECE302L_TH_VL2023240100270_2023-05-04_Reference-Material-I.pptx
 
Graphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ programGraphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ program
 
Avl trees
Avl treesAvl trees
Avl trees
 
Data Structures 5
Data Structures 5Data Structures 5
Data Structures 5
 
B.TECH Math project
B.TECH Math projectB.TECH Math project
B.TECH Math project
 
Algorithms of graph
Algorithms of graphAlgorithms of graph
Algorithms of graph
 
Avl tree
Avl treeAvl tree
Avl tree
 
Graph isomorphism
Graph isomorphismGraph isomorphism
Graph isomorphism
 
Graph representation
Graph representationGraph representation
Graph representation
 
UNIT III.pptx
UNIT III.pptxUNIT III.pptx
UNIT III.pptx
 
Unit V - ppt.pptx
Unit V - ppt.pptxUnit V - ppt.pptx
Unit V - ppt.pptx
 
Graphs
GraphsGraphs
Graphs
 
ppt 1.pptx
ppt 1.pptxppt 1.pptx
ppt 1.pptx
 
Graph ASS DBATU.pptx
Graph ASS DBATU.pptxGraph ASS DBATU.pptx
Graph ASS DBATU.pptx
 
Unit ix graph
Unit   ix    graph Unit   ix    graph
Unit ix graph
 

More from Dr Sandeep Kumar Poonia

An improved memetic search in artificial bee colony algorithm
An improved memetic search in artificial bee colony algorithmAn improved memetic search in artificial bee colony algorithm
An improved memetic search in artificial bee colony algorithmDr Sandeep Kumar Poonia
 
Modified position update in spider monkey optimization algorithm
Modified position update in spider monkey optimization algorithmModified position update in spider monkey optimization algorithm
Modified position update in spider monkey optimization algorithmDr Sandeep Kumar Poonia
 
Enhanced local search in artificial bee colony algorithm
Enhanced local search in artificial bee colony algorithmEnhanced local search in artificial bee colony algorithm
Enhanced local search in artificial bee colony algorithmDr Sandeep Kumar Poonia
 
Memetic search in differential evolution algorithm
Memetic search in differential evolution algorithmMemetic search in differential evolution algorithm
Memetic search in differential evolution algorithmDr Sandeep Kumar Poonia
 
Improved onlooker bee phase in artificial bee colony algorithm
Improved onlooker bee phase in artificial bee colony algorithmImproved onlooker bee phase in artificial bee colony algorithm
Improved onlooker bee phase in artificial bee colony algorithmDr Sandeep Kumar Poonia
 
Comparative study of_hybrids_of_artificial_bee_colony_algorithm
Comparative study of_hybrids_of_artificial_bee_colony_algorithmComparative study of_hybrids_of_artificial_bee_colony_algorithm
Comparative study of_hybrids_of_artificial_bee_colony_algorithmDr Sandeep Kumar Poonia
 
A novel hybrid crossover based abc algorithm
A novel hybrid crossover based abc algorithmA novel hybrid crossover based abc algorithm
A novel hybrid crossover based abc algorithmDr Sandeep Kumar Poonia
 
Multiplication of two 3 d sparse matrices using 1d arrays and linked lists
Multiplication of two 3 d sparse matrices using 1d arrays and linked listsMultiplication of two 3 d sparse matrices using 1d arrays and linked lists
Multiplication of two 3 d sparse matrices using 1d arrays and linked listsDr Sandeep Kumar Poonia
 
Sunzip user tool for data reduction using huffman algorithm
Sunzip user tool for data reduction using huffman algorithmSunzip user tool for data reduction using huffman algorithm
Sunzip user tool for data reduction using huffman algorithmDr Sandeep Kumar Poonia
 
New Local Search Strategy in Artificial Bee Colony Algorithm
New Local Search Strategy in Artificial Bee Colony Algorithm New Local Search Strategy in Artificial Bee Colony Algorithm
New Local Search Strategy in Artificial Bee Colony Algorithm Dr Sandeep Kumar Poonia
 
Performance evaluation of different routing protocols in wsn using different ...
Performance evaluation of different routing protocols in wsn using different ...Performance evaluation of different routing protocols in wsn using different ...
Performance evaluation of different routing protocols in wsn using different ...Dr Sandeep Kumar Poonia
 
Performance evaluation of diff routing protocols in wsn using difft network p...
Performance evaluation of diff routing protocols in wsn using difft network p...Performance evaluation of diff routing protocols in wsn using difft network p...
Performance evaluation of diff routing protocols in wsn using difft network p...Dr Sandeep Kumar Poonia
 

More from Dr Sandeep Kumar Poonia (20)

Soft computing
Soft computingSoft computing
Soft computing
 
An improved memetic search in artificial bee colony algorithm
An improved memetic search in artificial bee colony algorithmAn improved memetic search in artificial bee colony algorithm
An improved memetic search in artificial bee colony algorithm
 
Modified position update in spider monkey optimization algorithm
Modified position update in spider monkey optimization algorithmModified position update in spider monkey optimization algorithm
Modified position update in spider monkey optimization algorithm
 
Enhanced local search in artificial bee colony algorithm
Enhanced local search in artificial bee colony algorithmEnhanced local search in artificial bee colony algorithm
Enhanced local search in artificial bee colony algorithm
 
RMABC
RMABCRMABC
RMABC
 
Memetic search in differential evolution algorithm
Memetic search in differential evolution algorithmMemetic search in differential evolution algorithm
Memetic search in differential evolution algorithm
 
Improved onlooker bee phase in artificial bee colony algorithm
Improved onlooker bee phase in artificial bee colony algorithmImproved onlooker bee phase in artificial bee colony algorithm
Improved onlooker bee phase in artificial bee colony algorithm
 
Comparative study of_hybrids_of_artificial_bee_colony_algorithm
Comparative study of_hybrids_of_artificial_bee_colony_algorithmComparative study of_hybrids_of_artificial_bee_colony_algorithm
Comparative study of_hybrids_of_artificial_bee_colony_algorithm
 
A novel hybrid crossover based abc algorithm
A novel hybrid crossover based abc algorithmA novel hybrid crossover based abc algorithm
A novel hybrid crossover based abc algorithm
 
Multiplication of two 3 d sparse matrices using 1d arrays and linked lists
Multiplication of two 3 d sparse matrices using 1d arrays and linked listsMultiplication of two 3 d sparse matrices using 1d arrays and linked lists
Multiplication of two 3 d sparse matrices using 1d arrays and linked lists
 
Sunzip user tool for data reduction using huffman algorithm
Sunzip user tool for data reduction using huffman algorithmSunzip user tool for data reduction using huffman algorithm
Sunzip user tool for data reduction using huffman algorithm
 
New Local Search Strategy in Artificial Bee Colony Algorithm
New Local Search Strategy in Artificial Bee Colony Algorithm New Local Search Strategy in Artificial Bee Colony Algorithm
New Local Search Strategy in Artificial Bee Colony Algorithm
 
A new approach of program slicing
A new approach of program slicingA new approach of program slicing
A new approach of program slicing
 
Performance evaluation of different routing protocols in wsn using different ...
Performance evaluation of different routing protocols in wsn using different ...Performance evaluation of different routing protocols in wsn using different ...
Performance evaluation of different routing protocols in wsn using different ...
 
Enhanced abc algo for tsp
Enhanced abc algo for tspEnhanced abc algo for tsp
Enhanced abc algo for tsp
 
Database aggregation using metadata
Database aggregation using metadataDatabase aggregation using metadata
Database aggregation using metadata
 
Performance evaluation of diff routing protocols in wsn using difft network p...
Performance evaluation of diff routing protocols in wsn using difft network p...Performance evaluation of diff routing protocols in wsn using difft network p...
Performance evaluation of diff routing protocols in wsn using difft network p...
 
Lecture28 tsp
Lecture28 tspLecture28 tsp
Lecture28 tsp
 
Lecture27 linear programming
Lecture27 linear programmingLecture27 linear programming
Lecture27 linear programming
 
Lecture26
Lecture26Lecture26
Lecture26
 

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

Problems in parallel computations of tree functions

  • 2. 2 An overview of lecture • The Euler tour technique • Computation of different tree functions • Tree contraction • Evaluation of arithmetic expressions
  • 3. 3 Problems in parallel computations of tree functions • Computations of tree functions are important for designing many algorithms for trees and graphs. • Some of these computations include preorder, postorder, inorder numbering of the nodes of a tree, number of descendants of each vertex, level of each vertex etc.
  • 4. 4 Problems in parallel computations of tree functions • Most sequential algorithms for these problems use depth-first search for solving these problems. • However, depth-first search seems to be inherently sequential in some sense.
  • 5. 5 Parallel depth-first search • It is difficult to do depth-first search in parallel. • We cannot assign depth-first numbering to the node n unless we have assigned depth- first numbering to all the nodes in the subtree A.
  • 6. 6 Parallel depth-first search • There is a definite order of visiting the nodes in depth-first search. • We can introduce additional edges to the tree to get this order. • The Euler tour technique converts a tree into a list by adding additional edges.
  • 7. 7 Parallel depth-first search • The red (or, magenta ) arrows are followed when we visit a node for the first (or, second) time. • If the tree has n nodes, we can construct a list with 2n - 2 nodes, where each arrow (directed edge) is a node of the list.
  • 8. 8 Euler tour technique • For a node v T, p(v) is the parent of v. • Each red node in the list represents an edge of the nature < p(v) , v >. • We can determine the preorder numbering of a node of the tree by counting the red nodes in the list.
  • 9. 9 Euler tour technique • Let T = (V, E) be a given tree and let T’ = (V, E’ ) be a directed graph obtained from T. • Each edge (u, v) E is replaced by two edges < u, v > and < v, u >. • Both the indegree and outdegree of an internal node of the tree are now same. • The indegree and outdegree of a leaf is 1 each. • Hence T’ is an Eulerian graph.
  • 10. 10 Euler tour technique • An Euler circuit of a graph is an edge-disjoint circuit which traverses all the nodes. • A graph permits an Euler circuit if and only if each vertex has equal indegree and outdegree. • An Euler circuit can be used for optimal parallel computation of many tree functions. • To construct an Euler circuit, we have to specify the successor edge for each edge.
  • 11. 11 Constructing an Euler tour • Each edge on an Euler circuit has a unique successor edge. • For each vertex v V we fix an ordering of the vertices adjacent to v. • If d is the degree of vertex v, the vertices adjacent to v are: adj(v) = < u0, u1, …, ud -1 > • The successor of edge < ui, v > is: s(< ui, v >) = < v, u(i + 1) mod d >, 0 i (d - 1)
  • 13. 13 Correctness of Euler tour • Consider the graph T’ = (V, E’ ) , where E’ is obtained by replacing each e E by two directed edges of opposite directions. Lemma: The successor function s defines only one cycle and not a set of edge-disjoint cycles in T’. Proof: We have already shown that the graph is Eulerian. • We prove the lemma through induction.
  • 14. 14 Correctness of Euler tour basis: When the tree has 2 nodes, there is only one edge and one cycle with two edges. Suppose, the claim is true for n nodes. We should show that it is true when there are n + 1 nodes.
  • 15. 15 Correctness of Euler tour • We can introduce an extra node by introducing a leaf to an existing tree, like the leaf v. • Initially, adj(u) = <…, v’, v’’, …> . Hence, s(< v’, u >) = < u, v’’ >.
  • 16. 16 Correctness of Euler tour • After the introduction of v, adj(u) = <…, v’, v, v’’, …> • s(< v’, u >) = < u, v > and s(< v, u >) = < u, v’’ > • Hence, there is only one cycle after v is introduced.
  • 17. 17 Construction of Euler tour in parallel
  • 18. 18 Construction of Euler tour in parallel • We assume that the tree is given as a set of adjacency lists for the nodes. The adjacency list L[v] for v is given in an array. • Consider a node v and a node ui adjacent to v. • We need: – The successor < v, u(i + 1) mod d > for < ui, v >. This is done by making the list circular. – < ui, v >. This is done by keeping a direct pointer from ui in L[v] to v in L[ui].
  • 19. 19 Construction of Euler tour in parallel • We can construct an Euler tour in O(1) time using O(n) processors. • One processor is assigned to each node of the adjacency list. • There is no need of concurrent reading, hence the EREW PRAM model is sufficient.
  • 20. 20 Rooting a tree • For doing any tree computation, we need to know the parent p(v) for each node v. • Hence, we need to root the tree at a vertex r. • We first construct an Euler tour and for the vertex r, set s(< ud -1, r >) = 0. • ud -1 is the last vertex adjacent to r. • In other words, we break the Euler tour at r.
  • 23. 23 Rooting a tree Input: The Euler tour of a tree and a special vertex r. Output: For each vertex v r, the parent p(v) of v in the tree rooted at r.
  • 24. 24 Rooting a tree begin 1. Set s(< u, r >) = 0, where u is the last vertex in the adjacency list of r. 2. Assign a weight 1 to each edge of the list and compute parallel prefix. 3. For each edge < x, y >, set x = p(y) whenever the prefix sum of < x, y > is smaller than the prefix sum of < y, x >. end
  • 26. 26 Computation of tree functions • Given a tree T, for many tree computations: – We first construct the Euler tour of T – Then we root the tree at a vertex • We can compute: – The postorder number of each vertex – The preorder number of each vertex – The inorder number of each vertex – The level of each vertex – The number of descendants of each vertex.
  • 27. 27 Tree Contraction • Some tree computations cannot be solved efficiently with the Euler tour technique alone. • An important problem is evaluation of an arithmetic expression given as a binary tree.
  • 28. 28 Tree Contraction • Each leaf holds a constant and each internal node holds an arithmetic operator like +, . • The goal is to compute the value of the expression at the root. • The tree contraction technique is a systematic way of shrinking a tree into a single vertex. • We successively apply the operation of merging a leaf with its parent or merging a degree-2 vertex with its parent.
  • 29. 29 The RAKE operation • Let T = (V, E) be a rooted binary tree and for each vertex v, p(v) is its parent. • sib(v) is the child of p(v). We consider only binary trees. • In the rake operation for a leaf u such that p(u) r. – Remove u and p(u) from T, and – Connect sib(u) to p(p(u)).
  • 30. 30 The RAKE operation • In our tree contraction algorithm, we apply the rake operation repeatedly to reduce the size of the binary tree. • We need to apply rake to many leaves in parallel in order to achieve a fast running time.
  • 31. 31 The RAKE operation • But we cannot apply rake operation to nodes whose parents are consecutive on the tree. • For example, rake operation cannot be applied to nodes 1 and 8 in parallel. • We need to apply the rake operation to non- consecutive leaves as they appear from left to right.
  • 32. 32 The RAKE operation • We first label the leaves consecutively from left to right. • In an Euler path for a rooted tree, the leaves appear from left to right. • We can assign a weight 1 to each edge of the kind (v, p(v)) where v is a leaf. • We exclude the leftmost and the rightmost leaves. These two leaves will be the two children of the root when the tree is contracted to a three-node tree. • We do a prefix sum on the resulting list and the leaves are numbered from left to right.
  • 33. 33 The RAKE operation • We now store all the n leaves in an array A. • Aodd is the subarray consisting of the odd- indexed elements of A. • Aeven is the subarray consisting of the even- indexed elements of A. • We can create the arrays Aodd and Aeven in O(1) time and O(n) work.
  • 34. 34 Tree contraction algorithm begin for iterations do 1. Apply the rake operation in parallel to all the elements of Aodd that are left children 2. Apply the rake operation in parallel to the rest of the elements in Aodd. 3. Set A := Aeven. end log( 1)n
  • 36. 36 Correctness of tree contraction • Whenever the rake operation is applied in parallel to several leaves, the parents of any two such leaves are not adjacent. • The number of leaves reduces by half after each iteration of the loop. Hence the tree is contracted in O(log n) time. • Euler tour takes O(n) work. • The total number of operations for all the iterations of the loop is: ( ( )) 2i i n O O n
  • 39. 39 Evaluation of arithmetic expressions • If we evaluate an expression tree bottom-up, it will take O(n) time for a long and skinny tree. • Hence we apply tree contraction.
  • 40. 40 Evaluation of arithmetic expressions • We do not completely evaluate each internal node. We evaluate the internal nodes partially. • For each internal node v, we associate a label (av, bv). av and bv are constants. • The value of the expression at node is: (av X + bv), where X is an unknown value for the expression of the subtree rooted at v.
  • 41. 41 Keeping an invariant Invariant: • Let u be an internal node which holds the operation , . • Let v and w are the children of u with labels (av, bv) and (aw, bw). • Then the value at u is: val(u) = (avval(v) + bv) (awval(w) + bw)
  • 43. 43 Applying the rake operation • The value at node u is: val(u) = (avcv + bv) (aw X + bw) • X is the unknown value at node w.
  • 44. 44 Applying the rake operation • The contribution of val(u) to the value of node p(u) is: au val(u) + bu = au[(avcv + bv) (aw X + bw)] + bu • We can adjust the labels of node w to (a’w , b’w) • a’w = au(avcv + bv) aw • b’w = au(avcv + bv) bw + bu
  • 45. 45 Complexity of expression evaluation • The correctness of the expression evaluation depends on correctly maintaining the invariants. • We start with a label (1, 0) for each leaf and correctly maintain the invariant at each rake operation. • We have already proved the correctness of the rake operation. • Hence, evaluation of an expression given as a binary tree takes O(n) work and O(log n) time.