SlideShare uma empresa Scribd logo
1 de 85
Baixar para ler offline
Parallel Algorithms for Trees

                                    Ahmad Khayyat
                     Department of Electrical & Computer Engineering
                                  ahmad.khayyat@ece.queensu.ca

                            Parallel Computation: Models and Methods
                               Selim G. Akl             Chapter 6

                                CISC 879 — Algorithms and Applications
                                          Queen’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     Introduction
                   Graphs
                   Euler 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 set
                of 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 number
                of edges adjacent to the vertex.
                The in-degree of a vertex v in a directed graph is the number
                of edges entering v,
                The out-degree of a vertex v in a directed graph is the
                number 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       Introduction
                   Graphs
                   Euler 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 exactly
        once.
        An undirected graph has an Euler tour if each vertex has an even
        degree.


                                                               v4                 v6                 v3

                                                                        v5

                                                               v1                 v7                 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 exactly
        once.
        An undirected graph has an Euler tour if each vertex has an even
        degree.

        (v1 , v7 ), (v7 , v2 ), (v2 , v3 ), (v3 , v6 )         v4                 v6                 v3

                                                                        v5

                                                               v1                 v7                 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 exactly
        once.
        An undirected graph has an Euler tour if each vertex has an even
        degree.

        (v1 , v7 ), (v7 , v2 ), (v2 , v3 ), (v3 , v6 )         v4                 v6                 v3

        (v6 , v7 ), (v7 , v5 ), (v5 , v6 )                              v5

                                                               v1                 v7                 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 exactly
        once.
        An undirected graph has an Euler tour if each vertex has an even
        degree.

        (v1 , v7 ), (v7 , v2 ), (v2 , v3 ), (v3 , v6 )         v4                 v6                 v3

        (v6 , v7 ), (v7 , v5 ), (v5 , v6 )                              v5
        (v6 , v4 ), (v4 , v5 ), (v5 , v1 )
                                                               v1                 v7                 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 exactly
        once.
        A directed graph has an Euler tour if the in-degree of each vertex
        is equal to the out-degree of the vertex.

                                                                       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 exactly
        once.
        A directed graph has an Euler tour if the in-degree of each vertex
        is equal to the out-degree of the vertex.

        (v1 , v2 ), (v2 , v3 ), (v3 , v4 )                             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 exactly
        once.
        A directed graph has an Euler tour if the in-degree of each vertex
        is equal to the out-degree of the vertex.

        (v1 , v2 ), (v2 , v3 ), (v3 , v4 )                             v1                         v2

        (v4 , v2 ), (v2 , v4 )
                                                                       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 exactly
        once.
        A directed graph has an Euler tour if the in-degree of each vertex
        is equal to the out-degree of the vertex.

        (v1 , v2 ), (v2 , v3 ), (v3 , v4 )                             v1                         v2

        (v4 , v2 ), (v2 , v4 )
                                                                       v3                         v4
        (v4 , v5 ), (v5 , v6 ), (v6 , v4 ), (v4 , v6 )

                                                                       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 exactly
        once.
        A directed graph has an Euler tour if the in-degree of each vertex
        is equal to the out-degree of the vertex.

        (v1 , v2 ), (v2 , v3 ), (v3 , v4 )                             v1                         v2

        (v4 , v2 ), (v2 , v4 )
                                                                       v3                         v4
        (v4 , v5 ), (v5 , v6 ), (v6 , v4 ), (v4 , v6 )

        (v6 , v5 ), (v5 , v1 )                                         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.

                     v3        v1             v4                             v3            v1            v4


                v2             v5                                      v2                  v5

                          v7             v6                                       v7                v6


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 Tours
                  Data Structure
                  The Algorithm
                  Analysis

        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.

        head(v1 )       (v1 , v3 )     (v1 , v4 )     (v1 , v5 )

        head(v2 )       (v2 , v7 )
                                                                                    v3            v1             v4
        head(v3 )       (v3 , v1 )

        head(v4 )       (v4 , v1 )
                                                                              v2                  v5
        head(v5 )       (v5 , v1 )     (v5 , v6 )     (v5 , v7 )
                                                                                         v7                 v6
        head(v6 )       (v6 , v5 )

        head(v7 )       (v7 , v2 )     (v7 , v5 )


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 Tours
                  Data Structure
                  The Algorithm
                  Analysis

        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 .
                                                                                                  1                 4
       (v1 , v3 )       (v3 , v1 )       (v1 , v4 )     (v4 , v1 )                      v3                v1                 v4
                                                                                                  2                 3
                                                                                                      5        12

       (v1 , v5 )       (v5 , v6 )       (v6 , v5 )     (v5 , v7 )
                                                                                v2                        v5
                                                                                         9        8                 7

                                                                                   10                 11       6
       (v7 , v2 )       (v2 , v7 )       (v7 , v5 )     (v5 , v1 )                           v7                         v6

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 the
                 two nodes holding (vi , vj ) and (vj , vi ) (or ij and ji) — in ET.

            Successor of (vi , vj )                            Successor of (vj , vi )
                 if next(ji) = jk then                             if next(ij) = im then
                    succ(ij) ← jk                                     succ(ji) ← im
                 else                                              else
                    succ(ij) ← head(vj )                              succ(ji) ← head(vi )
                 end if                                            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 = P13
 Successor of (v1 , v3 )


     Successor of (vi , vj )                                           v3            v1             v4
         if next(ji) = jk then
            succ(ij) ← jk
                                                                 v2                  v5
         else
            succ(ij) ← head(vj )
                                                                            v7                 v6
         end if


                                                     head(v1 )         (v1 , v3 )      (v1 , v4 )        (v1 , v5 )
                                                                            .
                                                                            .
                                                                            .

                                                     head(v3 )         (v3 , v1 )




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 = P13
 Successor of (v1 , v3 )


     Successor of (vi , vj )                                           v3            v1             v4
         if next(ji) = jk then
            succ(ij) ← jk
                                                                 v2                  v5
         else
            succ(ij) ← head(vj )
                                                                            v7                 v6
         end if


                                                     head(v1 )         (v1 , v3 )      (v1 , v4 )        (v1 , v5 )
            next(31) = null
                                                                            .
                                                                            .
                                                                            .

                                                     head(v3 )         (v3 , v1 )

                                                                          31


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 = P13
 Successor of (v1 , v3 )


     Successor of (vi , vj )                                             v3            v1             v4
         if next(ji) = jk then
            succ(ij) ← jk
                                                                   v2                  v5
         else
            succ(ij) ← head(vj )
                                                                              v7                 v6
         end if
                                                                            13
                                                       head(v1 )         (v1 , v3 )      (v1 , v4 )        (v1 , v5 )
         succ(13) ← head(v3 )
                                                                              .
                                                                              .
                                                                              .
                (v1 , v3 )   (v3 , v1 )                head(v3 )         (v3 , v1 )




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 = P13
 Successor of (v3 , v1 )


     Successor of (vj , vi )                                           v3            v1             v4
         if next(ij) = im then
            succ(ji) ← im
                                                                 v2                  v5
         else
            succ(ji) ← head(vi )
                                                                            v7                 v6
         end if


                                                     head(v1 )         (v1 , v3 )      (v1 , v4 )        (v1 , v5 )
                                                                            .
                                                                            .
                                                                            .

                                                     head(v3 )         (v3 , v1 )




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 = P13
 Successor of (v3 , v1 )


     Successor of (vj , vi )                                           v3            v1              v4
         if next(ij) = im then
            succ(ji) ← im
                                                                 v2                  v5
         else
            succ(ji) ← head(vi )
                                                                            v7                  v6
         end if
                                                                          13               14
                                                     head(v1 )         (v1 , v3 )      (v1 , v4 )         (v1 , v5 )
                next(13) = 14
                                                                            .
                                                                            .
                                                                            .

                                                     head(v3 )         (v3 , v1 )




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 = P13
 Successor of (v3 , v1 )


     Successor of (vj , vi )                                                 v3            v1              v4
         if next(ij) = im then
            succ(ji) ← im
                                                                       v2                  v5
         else
            succ(ji) ← head(vi )
                                                                                  v7                  v6
         end if
                                                                                                 14
                                                           head(v1 )         (v1 , v3 )      (v1 , v4 )         (v1 , v5 )
                succ(31) ← 14
                                                                                  .
                                                                                  .
                                                                                  .
       (v1 , v3 )    (v3 , v1 )         (v1 , v4 )         head(v3 )         (v3 , v1 )

                                                                                31


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 Tours
                  Data Structure
                  The Algorithm
                  Analysis

        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 )




                                                                                   vi           vj            vk
            head(vj )       (vj , vi )         (vj , vk )


            next(ji) = jk



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 )


                                                                                   vi           vj            vk
            head(vj )       (vj , vi )         (vj , vk )


            next(ji) = jk
            next(jk) = ji, or head(vj ) = ji


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 Tours
                  Utility Computations
                  Simple Applications of Euler Tours
                  Computing 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 ))

                                                                            v0

                                                                    v1
     Find the root of v8 .                                                  v2

                                                                    v3

                                                                            v4

                                                                    v5

                                                                            v6

                                                                    v7

                                                                            v8

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 ))

                                                                            v0

                                                                    v1           1

     Find the root of v8 .                                                  v2

                                                                    v3           1

                                                                            v4

                                                                    v5           1

                                                                            v6

                                                                    v7           1

                                                                            v8

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 ))

                                                                            v0

                                                                    v1           1

     Find the root of v8 .                                                  v2          2

                                                                    v3           1

                                                                            v4

                                                                    v5           1

                                                                            v6          2

                                                                    v7           1

                                                                            v8

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 ))

                                                                             v0

                                                                     v1           1

     Find the root of v8 .                                                   v2          2

                                                                     v3           1
     Time Complexity
                                                                             v4                      3

       Sequential:          O(n)                                     v5           1
       Parallel:            O(log n)
                                                                             v6          2

                                                                     v7           1

                                                                             v8

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 parallel
                            next(i) ← succ(i)           Input & Output
        Step 2:      finished ← false                    Input: A linked list
        Step 3:      while not finished do               Output: Prefix computation
                     (3.1) finished ← true
                     (3.2) forall i do in parallel
                           (i) if next(i) = nil then
                                 (a) val(next(i)) ← val(i) ◦ val(next(i))
                                 (b) next(i) ← next(next(i))
                           (ii) if next(i) = nil then
                                            common
                                  finished ← − − false
                                             − −−


                x0          x1        x2            x3        x4           x5            x6           x7


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 parallel
                            next(i) ← succ(i)           Notation
        Step 2:      finished ← false                     xa-b = xa ◦ xa+1 ◦ · · · ◦ xb
        Step 3:      while not finished do
                     (3.1) finished ← true
                     (3.2) forall i do in parallel
                           (i) if next(i) = nil then
                                 (a) val(next(i)) ← val(i) ◦ val(next(i))
                                 (b) next(i) ← next(next(i))
                           (ii) if next(i) = nil then
                                            common
                                  finished ← − − false
                                             − −−


                x0          x1          x2            x3         x4           x5            x6           x7
                x0          x0-1        x1-2          x2-3       x3-4         x4-5         x5-6          x6-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 parallel
                            next(i) ← succ(i)
        Step 2:      finished ← false
        Step 3:      while not finished do
                     (3.1) finished ← true
                     (3.2) forall i do in parallel
                           (i) if next(i) = nil then
                                 (a) val(next(i)) ← val(i) ◦ val(next(i))
                                 (b) next(i) ← next(next(i))
                           (ii) if next(i) = nil then
                                            common
                                  finished ← − − false
                                             − −−


                x0          x1          x2            x3         x4           x5            x6           x7
                x0          x0-1        x0-2          x0-3       x1-4         x2-5         x3-6          x4-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 parallel
                            next(i) ← succ(i)           Complexity
        Step 2:      finished ← false                           t(n) = O(log n)
        Step 3:      while not finished do
                     (3.1) finished ← true
                                                              p(n) = n
                     (3.2) forall i do in parallel
                           (i) if next(i) = nil then
                                 (a) val(next(i)) ← val(i) ◦ val(next(i))
                                 (b) next(i) ← next(next(i))
                           (ii) if next(i) = nil then
                                            common
                                  finished ← − − false
                                             − −−


                x0          x1          x2            x3         x4           x5            x6           x7
                x0          x0-1        x0-2          x0-3       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 Suffix Computation for Linked Lists
        Step 1:        forall i do in parallel
                              next(i) ← succ(i)           Complexity
        Step 2:        finished ← false                           t(n) = O(log n)
        Step 3:        while not finished do
                       (3.1) finished ← true
                                                                 p(n) = n
                       (3.2) forall i do in parallel
                             (i) if next(i) = nil then
                                   (a) val(i) ← val(i) ◦ val(next(i))
                                   (b) next(i) ← next(next(i))
                             (ii) if next(i) = nil then
                                              common
                                    finished ← − − 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
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 the
        list (node position).


                Input: Linked list L                       Output: Sequence numbers

     forall i do in parallel
                                                       1      1       1        1        1        1        1        1
         val(i) ← 1
      Parallel-Prefix(L, +)




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 the
        list (node position).


                Input: Linked list L                       Output: Sequence numbers

     forall i do in parallel
                                                       1      1       1        1        1        1        1        1
         val(i) ← 1
                                                       1      2       3        4        5        6        7        8
      Parallel-Prefix(L, +)




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                             1      1       1        1        1        1        1        1
     (3.1) val(i) ← 1

     (3.2) if succ(i) = nil then
              succ(succ(i)) ← i
      Parallel-Prefix(L, +)



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                             1      1       1        1        1        1        1        1
     (3.1) val(i) ← 1

     (3.2) if succ(i) = nil then
              succ(succ(i)) ← i
      Parallel-Prefix(L, +)



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                             1      1       1        1        1        1        1        1
     (3.1) val(i) ← 1                                    8      7       6        5        4        3        2        1
     (3.2) if succ(i) = nil then
              succ(succ(i)) ← i                                     Complexity
      Parallel-Prefix(L, +)                              t(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 Tours
                  Utility Computations
                  Simple Applications of Euler Tours
                  Computing 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 . . .


                                                                1                  4
                                                     v3                 v1                  v4
                                                                2                  3
                                                                    5        12


                                             v2                         v5
                                                       9        8                  7

                                                10                  11       6
                                                           v7                          v6


                An Euler Tour returns to the root of a subtree only after all
                         vertices 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


                                                                1                  4
                                                     v3                 v1                  v4
                                                                2                  3
                                                                    5        12


                                             v2                         v5
                                                       9        8                  7

                                                10                  11       6
                                                           v7                          v6


                An Euler Tour returns to the root of a subtree only after all
                         vertices 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 edge
                                    otherwise (vi , vj ) is a retreat edge.
                                                                                                1                 4
                                                                                      v3                v1                 v4
     parent(root) ← nil                                                                         2                 3

     forall (vi , vj ) ∈ ET do in parallel                                                          5        12


         if pos(vi , vj ) < pos(vj , vi ) then                                v2                        v5
                                                                                       9        8                 7
             parent(vj ) ← vi
                                                                                 10                 11       6
                                                                                           v7                         v6

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.

                                pos(vi , parent(vi )) − 1 − pos(parent(vi ), vi )
                des(vi ) =                                                        +1
                                                        2
                                                                                                  1                 4
       (v1 , v3 )       (v3 , v1 )       (v1 , v4 )     (v4 , v1 )                      v3                v1                 v4
                                                                                                  2                 3
                                                                                                      5        12

       (v1 , v5 )       (v5 , v6 )       (v6 , v5 )     (v5 , v7 )
                                                                                v2                        v5
                                                                                         9        8                 7

                                                                                   10                 11       6
       (v7 , v2 )       (v2 , v7 )       (v7 , v5 )     (v5 , v1 )                           v7                         v6

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 advance
        edges in ET traversed before reaching vj for the first time + 1.

     preorder(root) ← 1
     forall (vi , vj ) ∈ ET do in parallel
         if pos(vi , vj ) < pos(vj , vi ) then                                              1                 4
                                                                                  v3                v1                 v4
              val(ij) ← 1                                                                   2                 3
                                                                                                5        12
         else
              val(ij) ← 0                                                 v2                        v5
                                                                                   9        8                 7

     Parallel-Prefix(ET, +)                                                   10                 11       6
                                                                                       v7                         v6
     forall (vi , vj ) ∈ ET do in parallel
         if pos(vi , vj ) < pos(vj , vi ) then
              preorder(vj ) ← val(ij) + 1

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 advance
        edges in ET traversed before reaching vj for the first time + 1.

     preorder(root) ← 1
                                                                       1, 3          3, 1          1, 4           4, 1
     forall (vi , vj ) ∈ ET do in parallel
                                                                        1             0              1             0
         if pos(vi , vj ) < pos(vj , vi ) then
              val(ij) ← 1
         else                                                          1, 5          5, 6          6, 5           5, 7
                                                                        1             1              0             1
              val(ij) ← 0
     Parallel-Prefix(ET, +)
                                                                       7, 2          2, 7          7, 5           5, 1
     forall (vi , vj ) ∈ ET do in parallel                              1             0              0             0
         if pos(vi , vj ) < pos(vj , vi ) then
              preorder(vj ) ← val(ij) + 1

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 advance
        edges in ET traversed before reaching vj for the first time + 1.

     preorder(root) ← 1
                                                                       1, 3          3, 1          1, 4           4, 1
     forall (vi , vj ) ∈ ET do in parallel
                                                                        1             0              1             0
         if pos(vi , vj ) < pos(vj , vi ) then
                                                                        1             1              2             2
              val(ij) ← 1
         else                                                          1, 5          5, 6          6, 5           5, 7
                                                                        1             1              0             1
              val(ij) ← 0                                               3             4              4             5
     Parallel-Prefix(ET, +)
                                                                       7, 2          2, 7          7, 5           5, 1
     forall (vi , vj ) ∈ ET do in parallel                              1             0              0             0
         if pos(vi , vj ) < pos(vj , vi ) then                          6             6              6             6
              preorder(vj ) ← val(ij) + 1

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 advance
        edges in ET traversed before reaching vj for the first time + 1.

     preorder(root) ← 1
                                                                       1, 3          3, 1          1, 4           4, 1
     forall (vi , vj ) ∈ ET do in parallel
                                                                        1             0              1             0
         if pos(vi , vj ) < pos(vj , vi ) then
                                                                        2                            3
              val(ij) ← 1
         else                                                          1, 5          5, 6          6, 5           5, 7
                                                                        1             1              0             1
              val(ij) ← 0                                               4             5                            6
     Parallel-Prefix(ET, +)
                                                                       7, 2          2, 7          7, 5           5, 1
     forall (vi , vj ) ∈ ET do in parallel                              1             0              0             0
         if pos(vi , vj ) < pos(vj , vi ) then                          7
              preorder(vj ) ← val(ij) + 1

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 edges
        in ET traversed before reaching vi for the last time + 1.

     postorder(root) ← n
     forall (vi , vj ) ∈ ET do in parallel
         if pos(vi , vj ) < pos(vj , vi ) then                                              1                 4
                                                                                  v3                v1                 v4
              val(ij) ← 0                                                                   2                 3
                                                                                                5        12
         else
              val(ij) ← 1                                                 v2                        v5
                                                                                   9        8                 7

     Parallel-Prefix(ET, +)                                                   10                 11       6
                                                                                       v7                         v6
     forall (vi , vj ) ∈ ET do in parallel
         if pos(vi , vj ) > pos(vj , vi ) then
              postorder(vi ) ← val(ij)

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 edges
        in ET traversed before reaching vi for the last time + 1.

     postorder(root) ← n
                                                                       1, 3          3, 1          1, 4           4, 1
     forall (vi , vj ) ∈ ET do in parallel
                                                                        0             1              0             1
         if pos(vi , vj ) < pos(vj , vi ) then
              val(ij) ← 0
                                                                       1, 5          5, 6          6, 5           5, 7
         else
                                                                        0             0              1             0
              val(ij) ← 1
     Parallel-Prefix(ET, +)
                                                                       7, 2          2, 7          7, 5           5, 1
     forall (vi , vj ) ∈ ET do in parallel                              0             1              1             1
         if pos(vi , vj ) > pos(vj , vi ) then
              postorder(vi ) ← val(ij)

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 edges
        in ET traversed before reaching vi for the last time + 1.

     postorder(root) ← n
                                                                       1, 3          3, 1          1, 4           4, 1
     forall (vi , vj ) ∈ ET do in parallel
                                                                        0             1              0             1
         if pos(vi , vj ) < pos(vj , vi ) then
                                                                        0             1              1             2
              val(ij) ← 0
                                                                       1, 5          5, 6          6, 5           5, 7
         else
                                                                        0             0              1             0
              val(ij) ← 1                                               2             2              3             3
     Parallel-Prefix(ET, +)
                                                                       7, 2          2, 7          7, 5           5, 1
     forall (vi , vj ) ∈ ET do in parallel                              0             1              1             1
         if pos(vi , vj ) > pos(vj , vi ) then                          3             4              5             6
              postorder(vi ) ← val(ij)

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 edges
        in ET traversed before reaching vi for the last time + 1.

     postorder(root) ← n
                                                                       1, 3          3, 1          1, 4           4, 1
     forall (vi , vj ) ∈ ET do in parallel
                                                                        0             1              0             1
         if pos(vi , vj ) < pos(vj , vi ) then
                                                                                      1                            2
              val(ij) ← 0
                                                                       1, 5          5, 6          6, 5           5, 7
         else
                                                                        0             0              1             0
              val(ij) ← 1                                                                            3
     Parallel-Prefix(ET, +)
                                                                       7, 2          2, 7          7, 5           5, 1
     forall (vi , vj ) ∈ ET do in parallel                              0             1              1             1
         if pos(vi , vj ) > pos(vj , vi ) then                                        4              5             6
              postorder(vi ) ← val(ij)

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 all
                vertices 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 )
                                                                               2             1             3
     Examples:
                                                                              v3            v1             v4
     v7 is an ancestor of v2 :
                                                                         7
                  6≤7<6+2=8                                                                      4
                                                                        v2                  v5
     v6 is not an ancestor of v2 :
                                                                                   v7                v6
                 5≤7            5+1=6
                                                                                   6                   5



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


     level(root) ← 0
     forall (vi , vj ) ∈ ET do in parallel                             1, 3          3, 1          1, 4           4, 1
         if pos(vi , vj ) < pos(vj , vi ) then                         −1             1            −1              1

              val(ij) ← −1
         else                                                          1, 5          5, 6          6, 5           5, 7
              val(ij) ← 1                                              −1            −1              1            −1

     Parallel-Suffix(ET, +)
     forall (vi , vj ) ∈ ET do in parallel                             7, 2          2, 7          7, 5           5, 1

         if pos(vi , vj ) < pos(vj , vi ) then                         −1             1              1             1

              level(vj ) ← val(ij) + 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


     level(root) ← 0
     forall (vi , vj ) ∈ ET do in parallel                             1, 3          3, 1          1, 4           4, 1
         if pos(vi , vj ) < pos(vj , vi ) then                         −1             1            −1              1
                                                                        0             1             0              1
              val(ij) ← −1
         else                                                          1, 5          5, 6          6, 5           5, 7
              val(ij) ← 1                                              −1            −1              1            −1
                                                                        0             1              2             1
     Parallel-Suffix(ET, +)
     forall (vi , vj ) ∈ ET do in parallel                             7, 2          2, 7          7, 5           5, 1

         if pos(vi , vj ) < pos(vj , vi ) then                         −1             1              1             1
                                                                        2             3              2             1
              level(vj ) ← val(ij) + 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


     level(root) ← 0
     forall (vi , vj ) ∈ ET do in parallel                             1, 3          3, 1          1, 4           4, 1
         if pos(vi , vj ) < pos(vj , vi ) then                         −1             1            −1              1
                                                                        1                           1
              val(ij) ← −1
         else                                                          1, 5          5, 6          6, 5           5, 7
              val(ij) ← 1                                              −1            −1              1            −1
                                                                        1             2                            2
     Parallel-Suffix(ET, +)
     forall (vi , vj ) ∈ ET do in parallel                             7, 2          2, 7          7, 5           5, 1

         if pos(vi , vj ) < pos(vj , vi ) then                         −1             1              1             1
                                                                        3
              level(vj ) ← val(ij) + 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) ← 0
     forall (vi , vj ) ∈ ET do in parallel                             1, 3          3, 1          1, 4           4, 1
         if pos(vi , vj ) < pos(vj , vi ) then                         −1             1            −1              1
                                                                        1                           1
              val(ij) ← −1
         else                                                          1, 5          5, 6          6, 5           5, 7
              val(ij) ← 1                                              −1            −1              1            −1
                                                                        1             2                            2
     Parallel-Suffix(ET, +)
     forall (vi , vj ) ∈ ET do in parallel                             7, 2          2, 7          7, 5           5, 1

         if pos(vi , vj ) < pos(vj , vi ) then                         −1             1              1             1
                                                                        3
              level(vj ) ← val(ij) + 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 Tours
                  Utility Computations
                  Simple Applications of Euler Tours
                  Computing 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 )}


                                                                                                         1
                                                                                                         v1
                                                                                                         10
     Example:
                                                                                     2                   7          8
                                                                                      v2                 v3         v4
                3 = preorder(v5 ), s3 = 6                                                5                   2          1
                                                                           3                     5
                S = {10, 5, 6, 7, 3, 4, 2, 1}                              v5                     v6
                                                                               6                     3

                                                                           4                     6
                                                                           v7                     v8
                                                                               7                     4


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
                                                                                                         1
                                                                                                         v1
                                                                                                         10
     Example:
                                                                                     2                   7          8
                                                                                      v2                 v3         v4
                  3 = preorder(v5 ), s3 = 6                                              5                   2          1
                                                                           3                     5
                 S = {10, 5, 6, 7, 3, 4, 2, 1}                             v5                     v6
                                                                               6                     3
                Sv2 : k = 2, = 2 + 5 − 1 = 6
                                                                           4                     6
                Sv2 = {5, 6, 7, 3, 4}                                      v7                     v8
                                                                               7                     4


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                                1
                                                                                                         v1
                                                                                                         10
     Example:
                                                                                     2                   7          8
                                                                                      v2                 v3         v4
                  3 = preorder(v5 ), s3 = 6                                              5                   2          1
                                                                           3                     5
                 S = {10, 5, 6, 7, 3, 4, 2, 1}                              v5                    v6
                                                                               6                     3
                Sv2 : k = 2, = 2 + 5 − 1 = 6
                                                                           4                     6
                Sv2 = {5, 6, 7, 3, 4}                                       v7                    v8
                                                                               7                     4


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 a
        sequence {b1 , b2 , . . . , bn } where bi = min(a1 , a2 , . . . , ai ).

        Suffix Minima (SM)
        The suffix minima of a sequence {a1 , a2 , . . . , an } are given by a
        sequence {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 a
        sequence {b1 , b2 , . . . , bn } where bi = min(a1 , a2 , . . . , ai ).

        Suffix Minima (SM)
        The suffix minima of a sequence {a1 , a2 , . . . , an } are given by a
        sequence {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 values
                held 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 =
                             SM =
                                                                                                                       1
                                                                                                                       v1
             PM =                                      PM =                                                            10
             SM =                                      SM =                                        2                   7          8
                                                                                                    v2                 v3          v4
                                                                                                       5                   2          1
        PM =                 PM =                 PM =               PM =                3                     5
                                                                                          v5                    v6
        SM =                 SM =                 SM =               SM =                    6                     3


    1           2        3        4           5        6         7        8              4                     6
        v1          v2       v5       v7          v6       v8        v3       v4          v7                    v8
        10          5        6         7          3          4       2        1              7                     4




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 =
                             SM =
                                                                                         PM:                L            {min(lp , ri )}

             PM =                                      PM =                              SM: {min(r1 , li )}                     R
             SM =                                      SM =


        PM = 10,             PM = 6,              PM = 3,            PM = 2,
                                                                                                    L                            R
                                                                                            l1 , l2 , . . . , lp         r1 , r2 , . . . , rp
        SM =        ,5       SM = ,7              SM = ,4            SM = ,1


    1           2        3        4           5        6         7        8
        v1          v2       v5       v7          v6       v8        v3       v4
        10          5        6         7          3          4       2        1




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 =
                             SM =
                                                                                         PM:                L            {min(lp , ri )}

             PM =                                      PM =                              SM: {min(r1 , li )}                     R
             SM =                                      SM =


        PM = 10,5            PM = 6,6             PM = 3,3           PM = 2,1
                                                                                                    L                            R
                                                                                            l1 , l2 , . . . , lp         r1 , r2 , . . . , rp
        SM = 5,5             SM = 6,7             SM = 3,4           SM = 1,1


    1           2        3        4           5        6         7        8
        v1          v2       v5       v7          v6       v8        v3       v4
        10          5        6         7          3          4       2        1




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 =
                             SM =
                                                                                              PM:                L            {min(lp , ri )}

             PM = 10,5,                                   PM = 3,3,                           SM: {min(r1 , li )}                     R
             SM =             ,6,7                        SM =          ,1,1


        PM = 10,5            PM = 6,6                PM = 3,3           PM = 2,1
                                                                                                         L                            R
                                                                                                 l1 , l2 , . . . , lp         r1 , r2 , . . . , rp
        SM = 5,5             SM = 6,7                SM = 3,4           SM = 1,1


    1           2        3           4           5        6         7          8
        v1          v2       v5          v7          v6       v8        v3         v4
        10          5        6            7          3          4       2          1




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 =
                             SM =
                                                                                         PM:                L            {min(lp , ri )}

             PM = 10,5,5,5                             PM = 3,3,2,1                      SM: {min(r1 , li )}                     R
             SM = 5,5,6,7                              SM = 1,1,1,1


        PM = 10,5            PM = 6,6             PM = 3,3           PM = 2,1
                                                                                                    L                            R
                                                                                            l1 , l2 , . . . , lp         r1 , r2 , . . . , rp
        SM = 5,5             SM = 6,7             SM = 3,4           SM = 1,1


    1           2        3        4           5        6         7        8
        v1          v2       v5       v7          v6       v8        v3       v4
        10          5        6         7          3          4       2        1




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,
                             SM =                 ,1,1,1,1
                                                                                         PM:                L            {min(lp , ri )}

             PM = 10,5,5,5                             PM = 3,3,2,1                      SM: {min(r1 , li )}                     R
             SM = 5,5,6,7                              SM = 1,1,1,1


        PM = 10,5            PM = 6,6             PM = 3,3           PM = 2,1
                                                                                                    L                            R
                                                                                            l1 , l2 , . . . , lp         r1 , r2 , . . . , rp
        SM = 5,5             SM = 6,7             SM = 3,4           SM = 1,1


    1           2        3        4           5        6         7        8
        v1          v2       v5       v7          v6       v8        v3       v4
        10          5        6         7          3          4       2        1




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:                L            {min(lp , ri )}

             PM = 10,5,5,5                             PM = 3,3,2,1                      SM: {min(r1 , li )}                     R
             SM = 5,5,6,7                              SM = 1,1,1,1


        PM = 10,5            PM = 6,6             PM = 3,3           PM = 2,1
                                                                                                    L                            R
                                                                                            l1 , l2 , . . . , lp         r1 , r2 , . . . , rp
        SM = 5,5             SM = 6,7             SM = 3,4           SM = 1,1


    1           2        3        4           5        6         7        8
        v1          v2       v5       v7          v6       v8        v3       v4
        10          5        6         7          3          4       2        1




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 Tree
 An 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
                                                                                                                       1
                                                                                                                       v1
             PM = 10,5,5,5                             PM = 3,3,2,1                                                    10
             SM = 5,5,6,7                              SM = 1,1,1,1                                2                   7          8
                                                                                                    v2                 v3          v4
                                                                                                       5                   2          1
        PM = 10,5            PM = 6,6             PM = 3,3           PM = 2,1            3                     5
                                                                                          v5                    v6
        SM = 5,5             SM = 6,7             SM = 3,4           SM = 1,1                6                     3


    1           2        3        4           5        6         7        8              4                     6
        v1          v2       v5       v7          v6       v8        v3       v4          v7                    v8
        10          5        6         7          3          4       2        1              7                     4



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 Tree
 An Example: Sv2


         k = 2,                   =k+5−1=6                                ⇒            Sv2 = {s2 , . . . , s6 }

                             PM = 10,5,5,5,3,3,2,1
                w
                             SM = 1,1,1,1,1,1,1,1
                                                                                                                       1
                                                                                                                       v1
             PM = 10,5,5,5                             PM = 3,3,2,1                                                    10
             SM = 5,5,6,7                              SM = 1,1,1,1                                2                   7          8
                                                                                                    v2                 v3          v4
                                                                                                       5                   2          1
        PM = 10,5            PM = 6,6             PM = 3,3           PM = 2,1            3                     5
                                                                                          v5                    v6
        SM = 5,5             SM = 6,7             SM = 3,4           SM = 1,1                6                     3


    1           2        3        4           5        6         7        8              4                     6
        v1          v2       v5       v7          v6       v8        v3       v4          v7                    v8
        10          5        6         7          3          4       2        1              7                     4



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 Tree
 An Example: Sv2


         k = 2,                   =k+5−1=6                                ⇒            Sv2 = {s2 , . . . , s6 }

                             PM = 10,5,5,5,3,3,2,1
                w
                             SM = 1,1,1,1,1,1,1,1
                                                                                                                       1
                                                                                                                       v1
             PM = 10,5,5,5                             PM = 3,3,2,1                                                    10
     x                                                                            y
             SM = 5,5,6,7                              SM = 1,1,1,1                                2                   7          8
                                                                                                    v2                 v3          v4
                                                                                                       5                   2          1
        PM = 10,5            PM = 6,6             PM = 3,3           PM = 2,1            3                     5
                                                                                          v5                    v6
        SM = 5,5             SM = 6,7             SM = 3,4           SM = 1,1                6                     3


    1           2        3        4           5        6         7        8              4                     6
        v1          v2       v5       v7          v6       v8        v3       v4          v7                    v8
        10          5        6         7          3          4       2        1              7                     4



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 parallel
                O(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);
                                               (x)   (y)
                O(1)       min(Svi ) ← min(SMk , PM )

        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       Conclusion
                  Summary
                  Questions




ECE @ Queen’s • Fall 2008                          Ahmad Khayyat                         Parallel Algorithms for Trees • 38
Introduction                Building Euler Tours                Applications of Euler Tours                   Conclusion

 Summary


 Summary

                   Levels                  Parent                      Des                     IntMin
                  O(log n)                  O(1)                      O(1)                     O(log n)




                    DFT                      ET                        Pos                       Bin
                    O(1)                    O(1)                     O(log n)                   O(1)




                   Rank                    Prefix                     Preorder
                  O(log n)                O(log n)                   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       Conclusion
                  Summary
                  Questions




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

Mais conteúdo relacionado

Mais procurados

Eigen values and eigen vectors engineering
Eigen values and eigen vectors engineeringEigen values and eigen vectors engineering
Eigen values and eigen vectors engineeringshubham211
 
Eigenvectors & Eigenvalues: The Road to Diagonalisation
Eigenvectors & Eigenvalues: The Road to DiagonalisationEigenvectors & Eigenvalues: The Road to Diagonalisation
Eigenvectors & Eigenvalues: The Road to DiagonalisationChristopher Gratton
 
Numerical solution of eigenvalues and applications 2
Numerical solution of eigenvalues and applications 2Numerical solution of eigenvalues and applications 2
Numerical solution of eigenvalues and applications 2SamsonAjibola
 
Applied numerical methods lec13
Applied numerical methods lec13Applied numerical methods lec13
Applied numerical methods lec13Yasser Ahmed
 
Eigenvalues and Eigenvector
Eigenvalues and EigenvectorEigenvalues and Eigenvector
Eigenvalues and EigenvectorMuhammad Hamza
 
Eigen values and eigenvectors
Eigen values and eigenvectorsEigen values and eigenvectors
Eigen values and eigenvectorsAmit Singh
 
Maths-->>Eigenvalues and eigenvectors
Maths-->>Eigenvalues and eigenvectorsMaths-->>Eigenvalues and eigenvectors
Maths-->>Eigenvalues and eigenvectorsJaydev Kishnani
 
Eigenvalue problems .ppt
Eigenvalue problems .pptEigenvalue problems .ppt
Eigenvalue problems .pptSelf-employed
 
Eigenvalues and eigenvectors
Eigenvalues and eigenvectorsEigenvalues and eigenvectors
Eigenvalues and eigenvectorsiraq
 
Application of eigen value eigen vector to design
Application of eigen value eigen vector to designApplication of eigen value eigen vector to design
Application of eigen value eigen vector to designHome
 
Lecture 9 eigenvalues - 5-1 & 5-2
Lecture 9   eigenvalues -  5-1 & 5-2Lecture 9   eigenvalues -  5-1 & 5-2
Lecture 9 eigenvalues - 5-1 & 5-2njit-ronbrown
 
Linear Transformation Vector Matrices and Spaces
Linear Transformation Vector Matrices and SpacesLinear Transformation Vector Matrices and Spaces
Linear Transformation Vector Matrices and SpacesSohaib H. Khan
 
Eighan values and diagonalization
Eighan values and diagonalization Eighan values and diagonalization
Eighan values and diagonalization gandhinagar
 

Mais procurados (20)

1619 quantum computing
1619 quantum computing1619 quantum computing
1619 quantum computing
 
Eigen values and eigen vectors engineering
Eigen values and eigen vectors engineeringEigen values and eigen vectors engineering
Eigen values and eigen vectors engineering
 
eigenvalue
eigenvalueeigenvalue
eigenvalue
 
Eigenvectors & Eigenvalues: The Road to Diagonalisation
Eigenvectors & Eigenvalues: The Road to DiagonalisationEigenvectors & Eigenvalues: The Road to Diagonalisation
Eigenvectors & Eigenvalues: The Road to Diagonalisation
 
Eigenvalues
EigenvaluesEigenvalues
Eigenvalues
 
Power method
Power methodPower method
Power method
 
Numerical solution of eigenvalues and applications 2
Numerical solution of eigenvalues and applications 2Numerical solution of eigenvalues and applications 2
Numerical solution of eigenvalues and applications 2
 
Applied numerical methods lec13
Applied numerical methods lec13Applied numerical methods lec13
Applied numerical methods lec13
 
Eigenvalues and Eigenvector
Eigenvalues and EigenvectorEigenvalues and Eigenvector
Eigenvalues and Eigenvector
 
Eigen values and eigenvectors
Eigen values and eigenvectorsEigen values and eigenvectors
Eigen values and eigenvectors
 
Maths-->>Eigenvalues and eigenvectors
Maths-->>Eigenvalues and eigenvectorsMaths-->>Eigenvalues and eigenvectors
Maths-->>Eigenvalues and eigenvectors
 
Eigenvalue problems .ppt
Eigenvalue problems .pptEigenvalue problems .ppt
Eigenvalue problems .ppt
 
Unit ix graph
Unit   ix    graph Unit   ix    graph
Unit ix graph
 
Eigenvalues and eigenvectors
Eigenvalues and eigenvectorsEigenvalues and eigenvectors
Eigenvalues and eigenvectors
 
Application of eigen value eigen vector to design
Application of eigen value eigen vector to designApplication of eigen value eigen vector to design
Application of eigen value eigen vector to design
 
Graphs Algorithms
Graphs AlgorithmsGraphs Algorithms
Graphs Algorithms
 
Lecture 9 eigenvalues - 5-1 & 5-2
Lecture 9   eigenvalues -  5-1 & 5-2Lecture 9   eigenvalues -  5-1 & 5-2
Lecture 9 eigenvalues - 5-1 & 5-2
 
Eigen value and vectors
Eigen value and vectorsEigen value and vectors
Eigen value and vectors
 
Linear Transformation Vector Matrices and Spaces
Linear Transformation Vector Matrices and SpacesLinear Transformation Vector Matrices and Spaces
Linear Transformation Vector Matrices and Spaces
 
Eighan values and diagonalization
Eighan values and diagonalization Eighan values and diagonalization
Eighan values and diagonalization
 

Destaque

Search algorithms master
Search algorithms masterSearch algorithms master
Search algorithms masterHossam Hassan
 
Parallel sorting Algorithms
Parallel  sorting AlgorithmsParallel  sorting Algorithms
Parallel sorting AlgorithmsGARIMA SHAKYA
 
Parallel sorting algorithm
Parallel sorting algorithmParallel sorting algorithm
Parallel sorting algorithmRicha Kumari
 
Maximum Matching in General Graphs
Maximum Matching in General GraphsMaximum Matching in General Graphs
Maximum Matching in General GraphsAhmad Khayyat
 
National Air And Space Museum Washington DC
National Air And Space Museum Washington DCNational Air And Space Museum Washington DC
National Air And Space Museum Washington DCShivakumar Patil
 
Was There A Darwinian Revolution
Was There A Darwinian RevolutionWas There A Darwinian Revolution
Was There A Darwinian RevolutionJohn Lynch
 
Google at a glance 1998 - 2008
Google at a glance 1998 - 2008Google at a glance 1998 - 2008
Google at a glance 1998 - 2008Andreas Jaffke
 
History of Creationism, Parts II & III
History of Creationism, Parts II & IIIHistory of Creationism, Parts II & III
History of Creationism, Parts II & IIIJohn Lynch
 
The Chemical Revolution
The Chemical RevolutionThe Chemical Revolution
The Chemical RevolutionJohn Lynch
 
History of Google Local from 2004-2011
History of Google Local from 2004-2011 History of Google Local from 2004-2011
History of Google Local from 2004-2011 Mike Blumenthal
 
Introduction to "Origins, Evolution & Creation"
Introduction to "Origins, Evolution & Creation"Introduction to "Origins, Evolution & Creation"
Introduction to "Origins, Evolution & Creation"John Lynch
 
Ancient Ideas of Creation & Evolution
Ancient Ideas of Creation & EvolutionAncient Ideas of Creation & Evolution
Ancient Ideas of Creation & EvolutionJohn Lynch
 
Why Ben Stein Is Wrong About History & Science
Why Ben Stein Is Wrong About History & ScienceWhy Ben Stein Is Wrong About History & Science
Why Ben Stein Is Wrong About History & ScienceJohn Lynch
 

Destaque (20)

Search algorithms master
Search algorithms masterSearch algorithms master
Search algorithms master
 
Parallel sorting Algorithms
Parallel  sorting AlgorithmsParallel  sorting Algorithms
Parallel sorting Algorithms
 
Parallel sorting algorithm
Parallel sorting algorithmParallel sorting algorithm
Parallel sorting algorithm
 
Maximum Matching in General Graphs
Maximum Matching in General GraphsMaximum Matching in General Graphs
Maximum Matching in General Graphs
 
Parallel searching
Parallel searchingParallel searching
Parallel searching
 
National Air And Space Museum Washington DC
National Air And Space Museum Washington DCNational Air And Space Museum Washington DC
National Air And Space Museum Washington DC
 
Was There A Darwinian Revolution
Was There A Darwinian RevolutionWas There A Darwinian Revolution
Was There A Darwinian Revolution
 
Google at a glance 1998 - 2008
Google at a glance 1998 - 2008Google at a glance 1998 - 2008
Google at a glance 1998 - 2008
 
History of Creationism, Parts II & III
History of Creationism, Parts II & IIIHistory of Creationism, Parts II & III
History of Creationism, Parts II & III
 
The Chemical Revolution
The Chemical RevolutionThe Chemical Revolution
The Chemical Revolution
 
History of Google Local from 2004-2011
History of Google Local from 2004-2011 History of Google Local from 2004-2011
History of Google Local from 2004-2011
 
Chap04alg
Chap04algChap04alg
Chap04alg
 
Algorithms - Aaron Bloomfield
Algorithms - Aaron BloomfieldAlgorithms - Aaron Bloomfield
Algorithms - Aaron Bloomfield
 
simple-sorting algorithms
simple-sorting algorithmssimple-sorting algorithms
simple-sorting algorithms
 
Ds 4
Ds 4Ds 4
Ds 4
 
sPen Data Management
sPen Data ManagementsPen Data Management
sPen Data Management
 
Introduction to "Origins, Evolution & Creation"
Introduction to "Origins, Evolution & Creation"Introduction to "Origins, Evolution & Creation"
Introduction to "Origins, Evolution & Creation"
 
Ancient Ideas of Creation & Evolution
Ancient Ideas of Creation & EvolutionAncient Ideas of Creation & Evolution
Ancient Ideas of Creation & Evolution
 
Google
GoogleGoogle
Google
 
Why Ben Stein Is Wrong About History & Science
Why Ben Stein Is Wrong About History & ScienceWhy Ben Stein Is Wrong About History & Science
Why Ben Stein Is Wrong About History & Science
 

Último

The Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George WellsThe Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George WellsEugene Lysak
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17Celine George
 
5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...CaraSkikne1
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxAditiChauhan701637
 
How to Add a many2many Relational Field in Odoo 17
How to Add a many2many Relational Field in Odoo 17How to Add a many2many Relational Field in Odoo 17
How to Add a many2many Relational Field in Odoo 17Celine George
 
UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024UKCGE
 
M-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxM-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxDr. Santhosh Kumar. N
 
Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.EnglishCEIPdeSigeiro
 
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptxSandy Millin
 
What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?TechSoup
 
How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17Celine George
 
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...Nguyen Thanh Tu Collection
 
Benefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationBenefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationMJDuyan
 
Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...raviapr7
 
Practical Research 1: Lesson 8 Writing the Thesis Statement.pptx
Practical Research 1: Lesson 8 Writing the Thesis Statement.pptxPractical Research 1: Lesson 8 Writing the Thesis Statement.pptx
Practical Research 1: Lesson 8 Writing the Thesis Statement.pptxKatherine Villaluna
 
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfMaximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfTechSoup
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17Celine George
 
Ultra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxUltra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxDr. Asif Anas
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfMohonDas
 
CapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapitolTechU
 

Último (20)

The Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George WellsThe Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George Wells
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17
 
5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptx
 
How to Add a many2many Relational Field in Odoo 17
How to Add a many2many Relational Field in Odoo 17How to Add a many2many Relational Field in Odoo 17
How to Add a many2many Relational Field in Odoo 17
 
UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024
 
M-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxM-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptx
 
Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.
 
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
 
What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?
 
How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17
 
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
 
Benefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationBenefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive Education
 
Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...
 
Practical Research 1: Lesson 8 Writing the Thesis Statement.pptx
Practical Research 1: Lesson 8 Writing the Thesis Statement.pptxPractical Research 1: Lesson 8 Writing the Thesis Statement.pptx
Practical Research 1: Lesson 8 Writing the Thesis Statement.pptx
 
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfMaximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17
 
Ultra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxUltra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptx
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdf
 
CapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptx
 

Parallel Algorithms for Trees

  • 1. Parallel Algorithms for Trees Ahmad Khayyat Department of Electrical & Computer Engineering ahmad.khayyat@ece.queensu.ca Parallel Computation: Models and Methods Selim G. Akl Chapter 6 CISC 879 — Algorithms and Applications Queen’s University October 29, 2008 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 1
  • 2. 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
  • 3. Introduction Building Euler Tours Applications of Euler Tours Conclusion Graphs Outline 1 Introduction Graphs Euler Tours 2 Building Euler Tours 3 Applications of Euler Tours 4 Conclusion ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 3
  • 4. 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 set of 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 number of edges adjacent to the vertex. The in-degree of a vertex v in a directed graph is the number of edges entering v, The out-degree of a vertex v in a directed graph is the number of edges leaving v. ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 4
  • 5. Introduction Building Euler Tours Applications of Euler Tours Conclusion Euler Tours Outline 1 Introduction Graphs Euler Tours 2 Building Euler Tours 3 Applications of Euler Tours 4 Conclusion ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 5
  • 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 exactly once. An undirected graph has an Euler tour if each vertex has an even degree. v4 v6 v3 v5 v1 v7 v2 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 6
  • 7. 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 exactly once. An undirected graph has an Euler tour if each vertex has an even degree. (v1 , v7 ), (v7 , v2 ), (v2 , v3 ), (v3 , v6 ) v4 v6 v3 v5 v1 v7 v2 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 6
  • 8. 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 exactly once. An undirected graph has an Euler tour if each vertex has an even degree. (v1 , v7 ), (v7 , v2 ), (v2 , v3 ), (v3 , v6 ) v4 v6 v3 (v6 , v7 ), (v7 , v5 ), (v5 , v6 ) v5 v1 v7 v2 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 6
  • 9. 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 exactly once. An undirected graph has an Euler tour if each vertex has an even degree. (v1 , v7 ), (v7 , v2 ), (v2 , v3 ), (v3 , v6 ) v4 v6 v3 (v6 , v7 ), (v7 , v5 ), (v5 , v6 ) v5 (v6 , v4 ), (v4 , v5 ), (v5 , v1 ) v1 v7 v2 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 6
  • 10. 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 exactly once. A directed graph has an Euler tour if the in-degree of each vertex is equal to the out-degree of the vertex. v1 v2 v3 v4 v5 v6 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 6
  • 11. 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 exactly once. A directed graph has an Euler tour if the in-degree of each vertex is equal to the out-degree of the vertex. (v1 , v2 ), (v2 , v3 ), (v3 , v4 ) v1 v2 v3 v4 v5 v6 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 6
  • 12. 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 exactly once. A directed graph has an Euler tour if the in-degree of each vertex is equal to the out-degree of the vertex. (v1 , v2 ), (v2 , v3 ), (v3 , v4 ) v1 v2 (v4 , v2 ), (v2 , v4 ) v3 v4 v5 v6 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 6
  • 13. 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 exactly once. A directed graph has an Euler tour if the in-degree of each vertex is equal to the out-degree of the vertex. (v1 , v2 ), (v2 , v3 ), (v3 , v4 ) v1 v2 (v4 , v2 ), (v2 , v4 ) v3 v4 (v4 , v5 ), (v5 , v6 ), (v6 , v4 ), (v4 , v6 ) v5 v6 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 6
  • 14. 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 exactly once. A directed graph has an Euler tour if the in-degree of each vertex is equal to the out-degree of the vertex. (v1 , v2 ), (v2 , v3 ), (v3 , v4 ) v1 v2 (v4 , v2 ), (v2 , v4 ) v3 v4 (v4 , v5 ), (v5 , v6 ), (v6 , v4 ), (v4 , v6 ) (v6 , v5 ), (v5 , v1 ) v5 v6 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 6
  • 15. 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. v3 v1 v4 v3 v1 v4 v2 v5 v2 v5 v7 v6 v7 v6 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 7
  • 16. Introduction Building Euler Tours Applications of Euler Tours Conclusion Data Structure Outline 1 Introduction 2 Building Euler Tours Data Structure The Algorithm Analysis 3 Applications of Euler Tours 4 Conclusion ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 8
  • 17. 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. head(v1 ) (v1 , v3 ) (v1 , v4 ) (v1 , v5 ) head(v2 ) (v2 , v7 ) v3 v1 v4 head(v3 ) (v3 , v1 ) head(v4 ) (v4 , v1 ) v2 v5 head(v5 ) (v5 , v1 ) (v5 , v6 ) (v5 , v7 ) v7 v6 head(v6 ) (v6 , v5 ) head(v7 ) (v7 , v2 ) (v7 , v5 ) ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 9
  • 18. Introduction Building Euler Tours Applications of Euler Tours Conclusion The Algorithm Outline 1 Introduction 2 Building Euler Tours Data Structure The Algorithm Analysis 3 Applications of Euler Tours 4 Conclusion ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 10
  • 19. 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 . 1 4 (v1 , v3 ) (v3 , v1 ) (v1 , v4 ) (v4 , v1 ) v3 v1 v4 2 3 5 12 (v1 , v5 ) (v5 , v6 ) (v6 , v5 ) (v5 , v7 ) v2 v5 9 8 7 10 11 6 (v7 , v2 ) (v2 , v7 ) (v7 , v5 ) (v5 , v1 ) v7 v6 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 11
  • 20. 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 the two nodes holding (vi , vj ) and (vj , vi ) (or ij and ji) — in ET. Successor of (vi , vj ) Successor of (vj , vi ) if next(ji) = jk then if next(ij) = im then succ(ij) ← jk succ(ji) ← im else else succ(ij) ← head(vj ) succ(ji) ← head(vi ) end if end if ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 12
  • 21. Introduction Building Euler Tours Applications of Euler Tours Conclusion The Algorithm Example: Pij = P13 Successor of (v1 , v3 ) Successor of (vi , vj ) v3 v1 v4 if next(ji) = jk then succ(ij) ← jk v2 v5 else succ(ij) ← head(vj ) v7 v6 end if head(v1 ) (v1 , v3 ) (v1 , v4 ) (v1 , v5 ) . . . head(v3 ) (v3 , v1 ) ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 13
  • 22. Introduction Building Euler Tours Applications of Euler Tours Conclusion The Algorithm Example: Pij = P13 Successor of (v1 , v3 ) Successor of (vi , vj ) v3 v1 v4 if next(ji) = jk then succ(ij) ← jk v2 v5 else succ(ij) ← head(vj ) v7 v6 end if head(v1 ) (v1 , v3 ) (v1 , v4 ) (v1 , v5 ) next(31) = null . . . head(v3 ) (v3 , v1 ) 31 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 13
  • 23. Introduction Building Euler Tours Applications of Euler Tours Conclusion The Algorithm Example: Pij = P13 Successor of (v1 , v3 ) Successor of (vi , vj ) v3 v1 v4 if next(ji) = jk then succ(ij) ← jk v2 v5 else succ(ij) ← head(vj ) v7 v6 end if 13 head(v1 ) (v1 , v3 ) (v1 , v4 ) (v1 , v5 ) succ(13) ← head(v3 ) . . . (v1 , v3 ) (v3 , v1 ) head(v3 ) (v3 , v1 ) ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 13
  • 24. Introduction Building Euler Tours Applications of Euler Tours Conclusion The Algorithm Example: Pij = P13 Successor of (v3 , v1 ) Successor of (vj , vi ) v3 v1 v4 if next(ij) = im then succ(ji) ← im v2 v5 else succ(ji) ← head(vi ) v7 v6 end if head(v1 ) (v1 , v3 ) (v1 , v4 ) (v1 , v5 ) . . . head(v3 ) (v3 , v1 ) ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 14
  • 25. Introduction Building Euler Tours Applications of Euler Tours Conclusion The Algorithm Example: Pij = P13 Successor of (v3 , v1 ) Successor of (vj , vi ) v3 v1 v4 if next(ij) = im then succ(ji) ← im v2 v5 else succ(ji) ← head(vi ) v7 v6 end if 13 14 head(v1 ) (v1 , v3 ) (v1 , v4 ) (v1 , v5 ) next(13) = 14 . . . head(v3 ) (v3 , v1 ) ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 14
  • 26. Introduction Building Euler Tours Applications of Euler Tours Conclusion The Algorithm Example: Pij = P13 Successor of (v3 , v1 ) Successor of (vj , vi ) v3 v1 v4 if next(ij) = im then succ(ji) ← im v2 v5 else succ(ji) ← head(vi ) v7 v6 end if 14 head(v1 ) (v1 , v3 ) (v1 , v4 ) (v1 , v5 ) succ(31) ← 14 . . . (v1 , v3 ) (v3 , v1 ) (v1 , v4 ) head(v3 ) (v3 , v1 ) 31 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 14
  • 27. Introduction Building Euler Tours Applications of Euler Tours Conclusion Analysis Outline 1 Introduction 2 Building Euler Tours Data Structure The Algorithm Analysis 3 Applications of Euler Tours 4 Conclusion ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 15
  • 28. 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 ) vi vj vk head(vj ) (vj , vi ) (vj , vk ) next(ji) = jk ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 16
  • 29. 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 ) vi vj vk head(vj ) (vj , vi ) (vj , vk ) next(ji) = jk next(jk) = ji, or head(vj ) = ji ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 16
  • 30. 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
  • 31. Introduction Building Euler Tours Applications of Euler Tours Conclusion Utility Computations Outline 1 Introduction 2 Building Euler Tours 3 Applications of Euler Tours Utility Computations Simple Applications of Euler Tours Computing Minima 4 Conclusion ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 18
  • 32. Introduction Building Euler Tours Applications of Euler Tours Conclusion Utility Computations Pointer Jumping parent(vi ) ← parent(parent(vi )) v0 v1 Find the root of v8 . v2 v3 v4 v5 v6 v7 v8 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 19
  • 33. Introduction Building Euler Tours Applications of Euler Tours Conclusion Utility Computations Pointer Jumping parent(vi ) ← parent(parent(vi )) v0 v1 1 Find the root of v8 . v2 v3 1 v4 v5 1 v6 v7 1 v8 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 19
  • 34. Introduction Building Euler Tours Applications of Euler Tours Conclusion Utility Computations Pointer Jumping parent(vi ) ← parent(parent(vi )) v0 v1 1 Find the root of v8 . v2 2 v3 1 v4 v5 1 v6 2 v7 1 v8 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 19
  • 35. Introduction Building Euler Tours Applications of Euler Tours Conclusion Utility Computations Pointer Jumping parent(vi ) ← parent(parent(vi )) v0 v1 1 Find the root of v8 . v2 2 v3 1 Time Complexity v4 3 Sequential: O(n) v5 1 Parallel: O(log n) v6 2 v7 1 v8 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 19
  • 36. Introduction Building Euler Tours Applications of Euler Tours Conclusion Utility Computations Parallel Prefix Computation for Linked Lists Step 1: forall i do in parallel next(i) ← succ(i) Input & Output Step 2: finished ← false Input: A linked list Step 3: while not finished do Output: Prefix computation (3.1) finished ← true (3.2) forall i do in parallel (i) if next(i) = nil then (a) val(next(i)) ← val(i) ◦ val(next(i)) (b) next(i) ← next(next(i)) (ii) if next(i) = nil then common finished ← − − false − −− x0 x1 x2 x3 x4 x5 x6 x7 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 20
  • 37. Introduction Building Euler Tours Applications of Euler Tours Conclusion Utility Computations Parallel Prefix Computation for Linked Lists Step 1: forall i do in parallel next(i) ← succ(i) Notation Step 2: finished ← false xa-b = xa ◦ xa+1 ◦ · · · ◦ xb Step 3: while not finished do (3.1) finished ← true (3.2) forall i do in parallel (i) if next(i) = nil then (a) val(next(i)) ← val(i) ◦ val(next(i)) (b) next(i) ← next(next(i)) (ii) if next(i) = nil then common finished ← − − false − −− x0 x1 x2 x3 x4 x5 x6 x7 x0 x0-1 x1-2 x2-3 x3-4 x4-5 x5-6 x6-7 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 20
  • 38. Introduction Building Euler Tours Applications of Euler Tours Conclusion Utility Computations Parallel Prefix Computation for Linked Lists Step 1: forall i do in parallel next(i) ← succ(i) Step 2: finished ← false Step 3: while not finished do (3.1) finished ← true (3.2) forall i do in parallel (i) if next(i) = nil then (a) val(next(i)) ← val(i) ◦ val(next(i)) (b) next(i) ← next(next(i)) (ii) if next(i) = nil then common finished ← − − false − −− x0 x1 x2 x3 x4 x5 x6 x7 x0 x0-1 x0-2 x0-3 x1-4 x2-5 x3-6 x4-7 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 20
  • 39. Introduction Building Euler Tours Applications of Euler Tours Conclusion Utility Computations Parallel Prefix Computation for Linked Lists Step 1: forall i do in parallel next(i) ← succ(i) Complexity Step 2: finished ← false t(n) = O(log n) Step 3: while not finished do (3.1) finished ← true p(n) = n (3.2) forall i do in parallel (i) if next(i) = nil then (a) val(next(i)) ← val(i) ◦ val(next(i)) (b) next(i) ← next(next(i)) (ii) if next(i) = nil then common finished ← − − false − −− x0 x1 x2 x3 x4 x5 x6 x7 x0 x0-1 x0-2 x0-3 x0-4 x0-5 x0-6 x0-7 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 20
  • 40. Introduction Building Euler Tours Applications of Euler Tours Conclusion Utility Computations Parallel Suffix Computation for Linked Lists Step 1: forall i do in parallel next(i) ← succ(i) Complexity Step 2: finished ← false t(n) = O(log n) Step 3: while not finished do (3.1) finished ← true p(n) = n (3.2) forall i do in parallel (i) if next(i) = nil then (a) val(i) ← val(i) ◦ val(next(i)) (b) next(i) ← next(next(i)) (ii) if next(i) = nil then common finished ← − − 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
  • 41. 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 the list (node position). Input: Linked list L Output: Sequence numbers forall i do in parallel 1 1 1 1 1 1 1 1 val(i) ← 1 Parallel-Prefix(L, +) ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 22
  • 42. 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 the list (node position). Input: Linked list L Output: Sequence numbers forall i do in parallel 1 1 1 1 1 1 1 1 val(i) ← 1 1 2 3 4 5 6 7 8 Parallel-Prefix(L, +) ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 22
  • 43. 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 1 1 1 1 1 1 1 1 (3.1) val(i) ← 1 (3.2) if succ(i) = nil then succ(succ(i)) ← i Parallel-Prefix(L, +) ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 23
  • 44. 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 1 1 1 1 1 1 1 1 (3.1) val(i) ← 1 (3.2) if succ(i) = nil then succ(succ(i)) ← i Parallel-Prefix(L, +) ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 23
  • 45. 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 1 1 1 1 1 1 1 1 (3.1) val(i) ← 1 8 7 6 5 4 3 2 1 (3.2) if succ(i) = nil then succ(succ(i)) ← i Complexity Parallel-Prefix(L, +) t(n) = O(log n), p(n) = O(n) ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 23
  • 46. 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 Tours Utility Computations Simple Applications of Euler Tours Computing Minima 4 Conclusion ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 24
  • 47. Introduction Building Euler Tours Applications of Euler Tours Conclusion Simple Applications of Euler Tours An Euler Tour is a . . . 1 4 v3 v1 v4 2 3 5 12 v2 v5 9 8 7 10 11 6 v7 v6 An Euler Tour returns to the root of a subtree only after all vertices in the subtree have been visited. ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 25
  • 48. Introduction Building Euler Tours Applications of Euler Tours Conclusion Simple Applications of Euler Tours Depth-First Traversal 1 4 v3 v1 v4 2 3 5 12 v2 v5 9 8 7 10 11 6 v7 v6 An Euler Tour returns to the root of a subtree only after all vertices in the subtree have been visited. ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 25
  • 49. 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 edge otherwise (vi , vj ) is a retreat edge. 1 4 v3 v1 v4 parent(root) ← nil 2 3 forall (vi , vj ) ∈ ET do in parallel 5 12 if pos(vi , vj ) < pos(vj , vi ) then v2 v5 9 8 7 parent(vj ) ← vi 10 11 6 v7 v6 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 26
  • 50. 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. pos(vi , parent(vi )) − 1 − pos(parent(vi ), vi ) des(vi ) = +1 2 1 4 (v1 , v3 ) (v3 , v1 ) (v1 , v4 ) (v4 , v1 ) v3 v1 v4 2 3 5 12 (v1 , v5 ) (v5 , v6 ) (v6 , v5 ) (v5 , v7 ) v2 v5 9 8 7 10 11 6 (v7 , v2 ) (v2 , v7 ) (v7 , v5 ) (v5 , v1 ) v7 v6 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 27
  • 51. 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 advance edges in ET traversed before reaching vj for the first time + 1. preorder(root) ← 1 forall (vi , vj ) ∈ ET do in parallel if pos(vi , vj ) < pos(vj , vi ) then 1 4 v3 v1 v4 val(ij) ← 1 2 3 5 12 else val(ij) ← 0 v2 v5 9 8 7 Parallel-Prefix(ET, +) 10 11 6 v7 v6 forall (vi , vj ) ∈ ET do in parallel if pos(vi , vj ) < pos(vj , vi ) then preorder(vj ) ← val(ij) + 1 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 28
  • 52. 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 advance edges in ET traversed before reaching vj for the first time + 1. preorder(root) ← 1 1, 3 3, 1 1, 4 4, 1 forall (vi , vj ) ∈ ET do in parallel 1 0 1 0 if pos(vi , vj ) < pos(vj , vi ) then val(ij) ← 1 else 1, 5 5, 6 6, 5 5, 7 1 1 0 1 val(ij) ← 0 Parallel-Prefix(ET, +) 7, 2 2, 7 7, 5 5, 1 forall (vi , vj ) ∈ ET do in parallel 1 0 0 0 if pos(vi , vj ) < pos(vj , vi ) then preorder(vj ) ← val(ij) + 1 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 28
  • 53. 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 advance edges in ET traversed before reaching vj for the first time + 1. preorder(root) ← 1 1, 3 3, 1 1, 4 4, 1 forall (vi , vj ) ∈ ET do in parallel 1 0 1 0 if pos(vi , vj ) < pos(vj , vi ) then 1 1 2 2 val(ij) ← 1 else 1, 5 5, 6 6, 5 5, 7 1 1 0 1 val(ij) ← 0 3 4 4 5 Parallel-Prefix(ET, +) 7, 2 2, 7 7, 5 5, 1 forall (vi , vj ) ∈ ET do in parallel 1 0 0 0 if pos(vi , vj ) < pos(vj , vi ) then 6 6 6 6 preorder(vj ) ← val(ij) + 1 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 28
  • 54. 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 advance edges in ET traversed before reaching vj for the first time + 1. preorder(root) ← 1 1, 3 3, 1 1, 4 4, 1 forall (vi , vj ) ∈ ET do in parallel 1 0 1 0 if pos(vi , vj ) < pos(vj , vi ) then 2 3 val(ij) ← 1 else 1, 5 5, 6 6, 5 5, 7 1 1 0 1 val(ij) ← 0 4 5 6 Parallel-Prefix(ET, +) 7, 2 2, 7 7, 5 5, 1 forall (vi , vj ) ∈ ET do in parallel 1 0 0 0 if pos(vi , vj ) < pos(vj , vi ) then 7 preorder(vj ) ← val(ij) + 1 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 28
  • 55. 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 edges in ET traversed before reaching vi for the last time + 1. postorder(root) ← n forall (vi , vj ) ∈ ET do in parallel if pos(vi , vj ) < pos(vj , vi ) then 1 4 v3 v1 v4 val(ij) ← 0 2 3 5 12 else val(ij) ← 1 v2 v5 9 8 7 Parallel-Prefix(ET, +) 10 11 6 v7 v6 forall (vi , vj ) ∈ ET do in parallel if pos(vi , vj ) > pos(vj , vi ) then postorder(vi ) ← val(ij) ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 29
  • 56. 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 edges in ET traversed before reaching vi for the last time + 1. postorder(root) ← n 1, 3 3, 1 1, 4 4, 1 forall (vi , vj ) ∈ ET do in parallel 0 1 0 1 if pos(vi , vj ) < pos(vj , vi ) then val(ij) ← 0 1, 5 5, 6 6, 5 5, 7 else 0 0 1 0 val(ij) ← 1 Parallel-Prefix(ET, +) 7, 2 2, 7 7, 5 5, 1 forall (vi , vj ) ∈ ET do in parallel 0 1 1 1 if pos(vi , vj ) > pos(vj , vi ) then postorder(vi ) ← val(ij) ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 29
  • 57. 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 edges in ET traversed before reaching vi for the last time + 1. postorder(root) ← n 1, 3 3, 1 1, 4 4, 1 forall (vi , vj ) ∈ ET do in parallel 0 1 0 1 if pos(vi , vj ) < pos(vj , vi ) then 0 1 1 2 val(ij) ← 0 1, 5 5, 6 6, 5 5, 7 else 0 0 1 0 val(ij) ← 1 2 2 3 3 Parallel-Prefix(ET, +) 7, 2 2, 7 7, 5 5, 1 forall (vi , vj ) ∈ ET do in parallel 0 1 1 1 if pos(vi , vj ) > pos(vj , vi ) then 3 4 5 6 postorder(vi ) ← val(ij) ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 29
  • 58. 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 edges in ET traversed before reaching vi for the last time + 1. postorder(root) ← n 1, 3 3, 1 1, 4 4, 1 forall (vi , vj ) ∈ ET do in parallel 0 1 0 1 if pos(vi , vj ) < pos(vj , vi ) then 1 2 val(ij) ← 0 1, 5 5, 6 6, 5 5, 7 else 0 0 1 0 val(ij) ← 1 3 Parallel-Prefix(ET, +) 7, 2 2, 7 7, 5 5, 1 forall (vi , vj ) ∈ ET do in parallel 0 1 1 1 if pos(vi , vj ) > pos(vj , vi ) then 4 5 6 postorder(vi ) ← val(ij) ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 29
  • 59. 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 all vertices 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 ) 2 1 3 Examples: v3 v1 v4 v7 is an ancestor of v2 : 7 6≤7<6+2=8 4 v2 v5 v6 is not an ancestor of v2 : v7 v6 5≤7 5+1=6 6 5 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 30
  • 60. 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 level(root) ← 0 forall (vi , vj ) ∈ ET do in parallel 1, 3 3, 1 1, 4 4, 1 if pos(vi , vj ) < pos(vj , vi ) then −1 1 −1 1 val(ij) ← −1 else 1, 5 5, 6 6, 5 5, 7 val(ij) ← 1 −1 −1 1 −1 Parallel-Suffix(ET, +) forall (vi , vj ) ∈ ET do in parallel 7, 2 2, 7 7, 5 5, 1 if pos(vi , vj ) < pos(vj , vi ) then −1 1 1 1 level(vj ) ← val(ij) + 1 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 31
  • 61. 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 level(root) ← 0 forall (vi , vj ) ∈ ET do in parallel 1, 3 3, 1 1, 4 4, 1 if pos(vi , vj ) < pos(vj , vi ) then −1 1 −1 1 0 1 0 1 val(ij) ← −1 else 1, 5 5, 6 6, 5 5, 7 val(ij) ← 1 −1 −1 1 −1 0 1 2 1 Parallel-Suffix(ET, +) forall (vi , vj ) ∈ ET do in parallel 7, 2 2, 7 7, 5 5, 1 if pos(vi , vj ) < pos(vj , vi ) then −1 1 1 1 2 3 2 1 level(vj ) ← val(ij) + 1 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 31
  • 62. 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 level(root) ← 0 forall (vi , vj ) ∈ ET do in parallel 1, 3 3, 1 1, 4 4, 1 if pos(vi , vj ) < pos(vj , vi ) then −1 1 −1 1 1 1 val(ij) ← −1 else 1, 5 5, 6 6, 5 5, 7 val(ij) ← 1 −1 −1 1 −1 1 2 2 Parallel-Suffix(ET, +) forall (vi , vj ) ∈ ET do in parallel 7, 2 2, 7 7, 5 5, 1 if pos(vi , vj ) < pos(vj , vi ) then −1 1 1 1 3 level(vj ) ← val(ij) + 1 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 31
  • 63. 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) ← 0 forall (vi , vj ) ∈ ET do in parallel 1, 3 3, 1 1, 4 4, 1 if pos(vi , vj ) < pos(vj , vi ) then −1 1 −1 1 1 1 val(ij) ← −1 else 1, 5 5, 6 6, 5 5, 7 val(ij) ← 1 −1 −1 1 −1 1 2 2 Parallel-Suffix(ET, +) forall (vi , vj ) ∈ ET do in parallel 7, 2 2, 7 7, 5 5, 1 if pos(vi , vj ) < pos(vj , vi ) then −1 1 1 1 3 level(vj ) ← val(ij) + 1 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 31
  • 64. Introduction Building Euler Tours Applications of Euler Tours Conclusion Computing Minima Outline 1 Introduction 2 Building Euler Tours 3 Applications of Euler Tours Utility Computations Simple Applications of Euler Tours Computing Minima 4 Conclusion ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 32
  • 65. Introduction Building Euler Tours Applications of Euler Tours Conclusion Computing Minima The Interval Minima Problem S = {sk : k = preorder(vi ) ⇒ sk = val(vi )} 1 v1 10 Example: 2 7 8 v2 v3 v4 3 = preorder(v5 ), s3 = 6 5 2 1 3 5 S = {10, 5, 6, 7, 3, 4, 2, 1} v5 v6 6 3 4 6 v7 v8 7 4 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 33
  • 66. 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 1 v1 10 Example: 2 7 8 v2 v3 v4 3 = preorder(v5 ), s3 = 6 5 2 1 3 5 S = {10, 5, 6, 7, 3, 4, 2, 1} v5 v6 6 3 Sv2 : k = 2, = 2 + 5 − 1 = 6 4 6 Sv2 = {5, 6, 7, 3, 4} v7 v8 7 4 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 33
  • 67. 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 1 v1 10 Example: 2 7 8 v2 v3 v4 3 = preorder(v5 ), s3 = 6 5 2 1 3 5 S = {10, 5, 6, 7, 3, 4, 2, 1} v5 v6 6 3 Sv2 : k = 2, = 2 + 5 − 1 = 6 4 6 Sv2 = {5, 6, 7, 3, 4} v7 v8 7 4 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 33
  • 68. 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 a sequence {b1 , b2 , . . . , bn } where bi = min(a1 , a2 , . . . , ai ). Suffix Minima (SM) The suffix minima of a sequence {a1 , a2 , . . . , an } are given by a sequence {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
  • 69. 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 a sequence {b1 , b2 , . . . , bn } where bi = min(a1 , a2 , . . . , ai ). Suffix Minima (SM) The suffix minima of a sequence {a1 , a2 , . . . , an } are given by a sequence {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 values held by leaves in the subtree rooted at x. ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 34
  • 70. Introduction Building Euler Tours Applications of Euler Tours Conclusion Computing Minima Constructing the Tree PM = SM = 1 v1 PM = PM = 10 SM = SM = 2 7 8 v2 v3 v4 5 2 1 PM = PM = PM = PM = 3 5 v5 v6 SM = SM = SM = SM = 6 3 1 2 3 4 5 6 7 8 4 6 v1 v2 v5 v7 v6 v8 v3 v4 v7 v8 10 5 6 7 3 4 2 1 7 4 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 35
  • 71. Introduction Building Euler Tours Applications of Euler Tours Conclusion Computing Minima Constructing the Tree PM = SM = PM: L {min(lp , ri )} PM = PM = SM: {min(r1 , li )} R SM = SM = PM = 10, PM = 6, PM = 3, PM = 2, L R l1 , l2 , . . . , lp r1 , r2 , . . . , rp SM = ,5 SM = ,7 SM = ,4 SM = ,1 1 2 3 4 5 6 7 8 v1 v2 v5 v7 v6 v8 v3 v4 10 5 6 7 3 4 2 1 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 35
  • 72. Introduction Building Euler Tours Applications of Euler Tours Conclusion Computing Minima Constructing the Tree PM = SM = PM: L {min(lp , ri )} PM = PM = SM: {min(r1 , li )} R SM = SM = PM = 10,5 PM = 6,6 PM = 3,3 PM = 2,1 L R l1 , l2 , . . . , lp r1 , r2 , . . . , rp SM = 5,5 SM = 6,7 SM = 3,4 SM = 1,1 1 2 3 4 5 6 7 8 v1 v2 v5 v7 v6 v8 v3 v4 10 5 6 7 3 4 2 1 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 35
  • 73. Introduction Building Euler Tours Applications of Euler Tours Conclusion Computing Minima Constructing the Tree PM = SM = PM: L {min(lp , ri )} PM = 10,5, PM = 3,3, SM: {min(r1 , li )} R SM = ,6,7 SM = ,1,1 PM = 10,5 PM = 6,6 PM = 3,3 PM = 2,1 L R l1 , l2 , . . . , lp r1 , r2 , . . . , rp SM = 5,5 SM = 6,7 SM = 3,4 SM = 1,1 1 2 3 4 5 6 7 8 v1 v2 v5 v7 v6 v8 v3 v4 10 5 6 7 3 4 2 1 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 35
  • 74. Introduction Building Euler Tours Applications of Euler Tours Conclusion Computing Minima Constructing the Tree PM = SM = PM: L {min(lp , ri )} PM = 10,5,5,5 PM = 3,3,2,1 SM: {min(r1 , li )} R SM = 5,5,6,7 SM = 1,1,1,1 PM = 10,5 PM = 6,6 PM = 3,3 PM = 2,1 L R l1 , l2 , . . . , lp r1 , r2 , . . . , rp SM = 5,5 SM = 6,7 SM = 3,4 SM = 1,1 1 2 3 4 5 6 7 8 v1 v2 v5 v7 v6 v8 v3 v4 10 5 6 7 3 4 2 1 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 35
  • 75. Introduction Building Euler Tours Applications of Euler Tours Conclusion Computing Minima Constructing the Tree PM = 10,5,5,5, SM = ,1,1,1,1 PM: L {min(lp , ri )} PM = 10,5,5,5 PM = 3,3,2,1 SM: {min(r1 , li )} R SM = 5,5,6,7 SM = 1,1,1,1 PM = 10,5 PM = 6,6 PM = 3,3 PM = 2,1 L R l1 , l2 , . . . , lp r1 , r2 , . . . , rp SM = 5,5 SM = 6,7 SM = 3,4 SM = 1,1 1 2 3 4 5 6 7 8 v1 v2 v5 v7 v6 v8 v3 v4 10 5 6 7 3 4 2 1 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 35
  • 76. 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: L {min(lp , ri )} PM = 10,5,5,5 PM = 3,3,2,1 SM: {min(r1 , li )} R SM = 5,5,6,7 SM = 1,1,1,1 PM = 10,5 PM = 6,6 PM = 3,3 PM = 2,1 L R l1 , l2 , . . . , lp r1 , r2 , . . . , rp SM = 5,5 SM = 6,7 SM = 3,4 SM = 1,1 1 2 3 4 5 6 7 8 v1 v2 v5 v7 v6 v8 v3 v4 10 5 6 7 3 4 2 1 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 35
  • 77. Introduction Building Euler Tours Applications of Euler Tours Conclusion Computing Minima Finding the Minima Using the Tree An 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 1 v1 PM = 10,5,5,5 PM = 3,3,2,1 10 SM = 5,5,6,7 SM = 1,1,1,1 2 7 8 v2 v3 v4 5 2 1 PM = 10,5 PM = 6,6 PM = 3,3 PM = 2,1 3 5 v5 v6 SM = 5,5 SM = 6,7 SM = 3,4 SM = 1,1 6 3 1 2 3 4 5 6 7 8 4 6 v1 v2 v5 v7 v6 v8 v3 v4 v7 v8 10 5 6 7 3 4 2 1 7 4 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 36
  • 78. Introduction Building Euler Tours Applications of Euler Tours Conclusion Computing Minima Finding the Minima Using the Tree An Example: Sv2 k = 2, =k+5−1=6 ⇒ Sv2 = {s2 , . . . , s6 } PM = 10,5,5,5,3,3,2,1 w SM = 1,1,1,1,1,1,1,1 1 v1 PM = 10,5,5,5 PM = 3,3,2,1 10 SM = 5,5,6,7 SM = 1,1,1,1 2 7 8 v2 v3 v4 5 2 1 PM = 10,5 PM = 6,6 PM = 3,3 PM = 2,1 3 5 v5 v6 SM = 5,5 SM = 6,7 SM = 3,4 SM = 1,1 6 3 1 2 3 4 5 6 7 8 4 6 v1 v2 v5 v7 v6 v8 v3 v4 v7 v8 10 5 6 7 3 4 2 1 7 4 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 36
  • 79. Introduction Building Euler Tours Applications of Euler Tours Conclusion Computing Minima Finding the Minima Using the Tree An Example: Sv2 k = 2, =k+5−1=6 ⇒ Sv2 = {s2 , . . . , s6 } PM = 10,5,5,5,3,3,2,1 w SM = 1,1,1,1,1,1,1,1 1 v1 PM = 10,5,5,5 PM = 3,3,2,1 10 x y SM = 5,5,6,7 SM = 1,1,1,1 2 7 8 v2 v3 v4 5 2 1 PM = 10,5 PM = 6,6 PM = 3,3 PM = 2,1 3 5 v5 v6 SM = 5,5 SM = 6,7 SM = 3,4 SM = 1,1 6 3 1 2 3 4 5 6 7 8 4 6 v1 v2 v5 v7 v6 v8 v3 v4 v7 v8 10 5 6 7 3 4 2 1 7 4 ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 36
  • 80. 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 parallel O(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); (x) (y) O(1) min(Svi ) ← min(SMk , PM ) 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
  • 81. Introduction Building Euler Tours Applications of Euler Tours Conclusion Summary Outline 1 Introduction 2 Building Euler Tours 3 Applications of Euler Tours 4 Conclusion Summary Questions ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 38
  • 82. Introduction Building Euler Tours Applications of Euler Tours Conclusion Summary Summary Levels Parent Des IntMin O(log n) O(1) O(1) O(log n) DFT ET Pos Bin O(1) O(1) O(log n) O(1) Rank Prefix Preorder O(log n) O(log n) O(log n) ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 39
  • 83. 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
  • 84. Introduction Building Euler Tours Applications of Euler Tours Conclusion Questions Outline 1 Introduction 2 Building Euler Tours 3 Applications of Euler Tours 4 Conclusion Summary Questions ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 41
  • 85. Introduction Building Euler Tours Applications of Euler Tours Conclusion Questions Questions ??? ECE @ Queen’s • Fall 2008 Ahmad Khayyat Parallel Algorithms for Trees • 42