Open Collections

UBC Theses and Dissertations

UBC Theses Logo

UBC Theses and Dissertations

Parallel techniques for construction of trees and related problems Przytycka, Teresa Maria 1990

Your browser doesn't seem to have a PDF viewer, please download the PDF to view this item.

Item Metadata

Download

Media
831-UBC_1990_A1 P79.pdf [ 9.32MB ]
Metadata
JSON: 831-1.0302108.json
JSON-LD: 831-1.0302108-ld.json
RDF/XML (Pretty): 831-1.0302108-rdf.xml
RDF/JSON: 831-1.0302108-rdf.json
Turtle: 831-1.0302108-turtle.txt
N-Triples: 831-1.0302108-rdf-ntriples.txt
Original Record: 831-1.0302108-source.json
Full Text
831-1.0302108-fulltext.txt
Citation
831-1.0302108.ris

Full Text

Parallel techniques for construction of trees and related problems By Teresa Maria Przytycka Magister, Warsaw University A THESIS SUBMITTED IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE DEGREE OF DOCTOR OF PHILOSOPHY in THE FACULTY OF GRADUATE STUDIES Department of Computer Science We accept this thesis as conforming to the required standard THE UNIVERSITY OF BRITISH COLUMBIA August, 1990 © Teresa Przytycka, 1990 In presenting this thesis in partial fulfilment of the requirements for an advanced degree at the University of British Columbia, I agree that the Library shall make it freely available for reference and study. I further agree that permission for extensive copying of this thesis for scholarly purposes may be granted by the head of my department or by his or her representatives. It is understood that copying or publication of this thesis for financial gain shall not be allowed without my written permission. Department of CompcU-e^ 2cc'&r? c £ The University of British Columbia Vancouver, Canada DE-6 (2/88) Abstrac t The concept of a tree has been used in various areas of mathematics for over a century. In particular, trees appear to be one of the most fundamental notions in computer science. Sequential algorithms for trees are generally well studied. Unfortunately many of these sequential algorithms use methods which seem to be inherently sequential. One of the contributions of this thesis is the introduction of several parallel techniques for the construction of various types of trees and the presentation of new parallel tree construction algorithms using these methods. Along with the parallel tree construction techniques presented here, we develop techniques which have broader applications. We use the Parallel Random Access Machine as our model of computation. We consider two basic methods of constructing trecs:tree expansion and tree synthesis. In the tree expansion method, we start with a single vertex and construct a tree by adding nodes of degree one and/or by subdividing edges. We use the parallel tree expansion technique to construct the tree representation for graphs in the family of graphs known as cographs. In the tree synthesis method, we start with a forest of single node subtrees and construct a tree by adding edges or (for rooted trees) by creating parent nodes for some roots of the trees in the forest. We present a family of parallel and sequential algorithms to construct various approximations to the Huffman tree. All these algorithms apply the tree synthesis method by constructing a tree in a level-by-level fashion. To support one of the algorithms in the family we develop a technique which we call the cascading sampling technique. One might suspect that the parallel tree synthesis method can be applied only to trees of polylogarithmic height, but this is not the case.We present a technique which we call the valley filling technique and develop its accelerated version called the accelerated valley filling technique. We present an application of this technique to an optimal parallel algorithm for construction of minimax trees. ii Table of Contents Abstract i i List of Figures v i Acknowledgements v i i i CHAPTER 1: INTRODUCTION 1 1.1. The Computation Model 2 1.2. Parallel Construction of Trees 5 1.3. A systematic approach to algorithmic problems 8 1.4. Basic definitions and notation 9 CHAPTER 2: BASIC TECHNIQUES FOR DESIGN OF P A R A L L E L ALGORITHMS 12 2.1. Brent's scheduling principle 12 2.2. Prefix sum computation 13 2.3. List ranking , 15 2.4. Euler tour technique 17 2.5. Tree Contraction 18 2.5.1. A tree contraction algorithm 20 2.5.2. Bottom-up Algebraic Tree Computations 25 2.5.2. Top-down Algebraic Tree Computations 31 2.6. Cascading sampling 32 2.7. Parallel divide and conquer and the A l l Dominating Neighbors problem 40 iii 2.7.1. T h e A D N p r o b l e m and the v i s ib i l i ty tree 42 2.7.2. A n optimal algorithm for the A D N problem 44 2.7.3. Appl icat ions 47 2.7.3.1. T h e A l l Strict ly D o m i n a t i n g Ne ighbors ( A S D N ) problem 49 2.7.3.2. C o m p u t i n g horizontal neighbors for vertices o f a monotone polygon 50 2.8. S u m m a r y 53 C H A P T E R 3: P A R A L L E L T R E E E X P A N S I O N - C O N S T R U C T I O N O F T R E E R E P R E S E N T A T I O N F O R C O G R A P H S 55 3.1. Definit ions and basic properties 57 3.2. Bunches and lines in a cotree 60 3.3. A top level description of the cotree construction algorithm 68 3.4. Implementation of the reduce operation 73 3.5. A d j a c e n c y matrix construction f r o m the cotree representation o f a c o g r a p h 75 3.6. R e d u c t i o n o f the processor requirements 77 3.7. A n application o f the cotree construction algorithm - construction a tree representation for a parity graph 78 3.8. S u m m a r y 80 C H A P T E R 4 : P A R A L L E L L E V E L - B Y - L E V E L T R E E S Y N T H E S I S : C O N S T R U C T I O N O F B I N A R Y T R E E S W I T H A L M O S T O P T I M A L W E I G H T E D P A T H L E N G T H 82 4.1. Bas ic Construction Scheme ( B C © ) 86 4.2. Approximate sorting and merging o f approximately sorted sequences 99 4.3. Genera l Construction Scheme ( 9 ^ / 6 ) 101 iv 4.4. P a r a l l e l interpretations o f $"5/6 102 4 .4 .1 . 0 ( l o g n) t ime n ^ ° f o g ^ ^ R J ^ processors p a r a l l e l interpretation of gcs with error bounded by 0.172 103 4.4.2 A 0 ( k l o g n log*n) time n processor parallel interpretation o f gcs with error bounded by l/n^ 104 4 . 1 . 3 . 0 ( k 2 l o g n) time n 2 processor paral le l interpretation o f gcs with error bounded by 4 - 110 4.5. Sequential interpretations o f the 9^<^ 121 4.6. S u m m a r y 124 C H A P T E R 5 : V A L L E Y F I L L I N G T E C H N I Q U E A N D C O N S T R U C T I O N O F M I N I M A X T R E E S 127 5.1. V a l l e y F i l l i n g Technique 130 5.2. L e v e l tree and its construction 132 5.2.1. Construction o f level tree 135 5.2.2. C o m p u t i n g the load function 137 5.3. A n optimal algorithm for alphabetic minimax tree problem 139 5.4. Other versions of the minimax tree problem 142 5.4.1. t-ary a lphabet ic m i n i m a x trees 142 5.4.2. Non-alphabetic t-ary minimax trees 148 5.4.3. M i n i m a x trees with real weights 153 5.5. S u m m a r y 153 C H A P T E R 6 : C O N C L U D I N G R E M A R K S 156 R E F E R E N C E S 164 I n d e x 169 v L i s t o f f i g u r e s Figure 2.1. A prefix sum computation 14 Figure 2.2. Prune and Bypass operations 21 Figure 2.3. Interpretation of Trees as Binary Trees 22 Figure 2.4. A tree contraction sequence 24 Figure 2.5. New labelling of edges after Prune and Bypass operations 28 Figure 2.6. Distribution by sampling 39 Figure 2.7. Visibility sequences 43 Figure 2.8. Hidden sequences (bold) 44 Figure 2.9. Hidden sequences (bold lines) 52 Figure 3.1. A cograph and its cotree 60 Figure 3.2. Notation concerning subtrees 60 Figure 3.3. A 0-bunch and a 1-bunch 62 Figure 3.4. Replacing a bunch by its representative 63 Figure 3.5. Relations ZQ(V,U,W) and Zj^u.w) 64 Figure 3.6. Restricting of the possible positions of nodes v,u,w satisfying Z0(v,u,w) 65 Figure 3.7. A nonbranching node 66 Figure 3.8. A 0-line and a 1-line 66 Figure 3.9. Replacing a line by its representative 67 Figure 3.10. A tree containing 3 brunching nodes, 2 bunches and 1 line 68 Figure 3.11. Substitution of fragments for corresponding representatives 70 Figure 3.12. The worst case configuration for case (2) 72 Figure 3.13. Converting a cotree to a binary tree 76 Figure 4.1. The hierarchical data structure used by the n2-processor algorithm 115 vi Figure 4.2. The summary of results of Chapter 4 125 Figure 5.1. A valley filling step 132 Figure 5.2. Level intervals 133 Figure 5.3. Embedded minimax tree 134 Figure 5.4. A level tree 135 Figure 5.5. Introducing the ordering of children 137 Figure 5.6. Binarization of a level tree 138 Figure 5.7. Construction of a balanced forest 139 Figure 5.8. A regular t-ary alphabetic minimax tree and a t-ary alphabetic minimax tree 142 Figure 5.9. Path compaction (t = 5) 145 Figure 5.10: Leaflets compaction (t = 4) 147 Figure 5.11. A stair 150 Figure 5.12. Treads cutting 150 Figure 5.13. Stair climbing 151 Figure 5.14. Cliff climbing 152 Figure 6.1. Generalizations of the parallel dynamic expression evaluation problem 159 vii Acknowledgements First of all, I would like to thank my supervisor, David Kirkpatrick, for his guidance, the support, and the encouragement that he has given me through my years at the University of Biritish Columbia. I had the very good fortune to have studied under his supervision. I am also indebted to Derek Corneil for his guidance and hospitality during may half year visit to the University of Toronto. I would like to extend my gratitude to the members of my committee Feng Gao, Maria Klawe, and Nick Pippenger for their suggestions on ways in which I could improve my presentation. I would like also to thank Jozef, my husband and coauthor of several papers, for his love, encouragement, and introducing me to knot theory, topology, and hyperbolic geometry. Finally I would like to thank all UBC graduate students, faculty, and staff who made my graduate study a rewarding experience. Special thanks to Nou Dadoun and Lisa Higham for many stimulating discussions and reading of various drafts of papers (and translating several of them into English); to Yueli, Jadranka, and Hilde for putting up with me as an office mate. This research has been founded in part by the University of British Columbia Graduate Fellowship, the I.W. Killam Predoctoral Fellowship and the B.C. Advanced Systems Institute Graduate Student Scholarship. I would like to dedicate this thesis to my children Tomek and Pawetek who were born during my graduate studies. viii Chapter 1: Introduction page 1 CHAPTER 1: INTRODUCTION The concept of a tree has been used in various areas of mathematics for over one century. Among the first people known to use this notion were Kirchhoff [Kil847] and Cayley ([Call857],[Call859]). Since then trees have appeared over and over again in different branches of mathematics, physics, and computer science. In computer science, especially, trees appear to be one of the most fundamental notions. It is hard to enumerate all aspects in which trees are used in computer science. Let us mention here their application as data structures (in particular hierarchical data structures), as a systematic way of exploring graphs, and as a representation of other objects (for example expressions, certain families of graphs). Parallel algorithms have brought a new application of trees, namely as a structure supporting scheduling techniques. For this reason parallel algorithms use trees even more critically than corresponding sequential algorithms. Sequential algorithms for trees have been generally well studied. Unfortunately many of these sequential algorithms use methods which seem to be inherently sequential. One of the contributions of this thesis is the introduction and investigation of several parallel techniques for the construction of various types of trees and the presentation of new parallel tree construction algorithms using these methods. Along with parallel tree construction techniques we develop techniques which have broader applications. The remainder of this chapter is devoted to a brief introduction to parallel computation related to trees. In Section 1.1, we introduce our parallel computation model. In Section 1.2, we briefly discuss parallel techniques for trees and relate our work to other work in the Chapter 1: Introduction page 2 field. The section also provides an overview of Chapters 3-5. In Section 1.3, we introduce the notion of an algorithmic schema, which provides a tool for a uniform presentation of computational techniques. In Section 1.4, we introduce basic definitions and notation concerning trees. In Chapter 2, we present general parallel techniques which support our tree construction techniques. We then describe in more detail our contribution to tree contraction (Section 2.5) and the cascading sampling technique (Section 2.6). In Section 2.7, we briefly discuss the parallel divide-and-conquer technique and its application to an algorithm for the All Dominating Neighbors problem which is used in Chapter 5. l.l.The Computation Model We use the Parallel Random Access Machine (PRAM) as our model of computation ([ForWyl87],[Gol76]). This is a synchronous parallel model of computation in which all processors have access to a common memory in addition to their local memory. We assume that a processor can access any cell of the shared memory in unit time. The processors are indexed by natural numbers and each processor knows its index. We consider the following PRAM models classified according to the manner of resolving read/write conflicts: - Exclusive Read Exclusive Write (EREW) PRAM - no concurrent reads or writes are allowed, - Concurrent Read Exclusive Write (CREW) PRAM- concurrent reads are allowed but no concurrent writes, - Concurrent Read Concurrent Write (CRCW) PRAM- concurrent reads and writes are allowed. According to the method of resolving write conflicts we consider several further submodels of the CRCW PRAM model. In the COMMON CRCW PRAM model, C h a p t e r 1: I n t r o d u c t i o n page 3 processors are allowed to write simultaneously under the condition that they write exacdy the same value. In the ARBITRARY CRCW PRAM model, among processors which try to write simultaneously, an arbitrary processor will succeed, and in the PRIORITY CRCW PRAM model, the processor with the highest index will succeed. The above models are not equivalent. The most powerful among them is the PRIORITY CRCW PRAM and the weakest is the EREW PRAM. However any algorithm which runs on the PRIORITY CRCW PRAM can be implemented on the EREW PRAM using the same number of processors with the time complexity multiplied by a logarithmic factor (see for example [Vis83]). A discussion of relations between PRAM models can be found, for example, in the survey of Karp and Ramachandran [KarRam86] and [FicRagWid88], [Bop89]. The PRAM model of computation is an idealized model of computation. Existing parallel machines usually consist of a number of small processors connected in a fixed network. However the methods used with a network model are usually closely related to the topology of the network. The PRAM model neglects the hardware constraints existing in real parallel machines. Thus it allows us to concentrate on the logical structure of the problem which makes it very convenient for the theoretical study of parallel computation. On the other hand, the PRAM model can be efficiently simulated by more realistic models of computation ([UpfWig87], [AltHagMehPre87], [HerBil88], [HoPre89], [KarUpf88], [Ran87], [Her89]). Let n be the size of a problem. We evaluate the performance of a parallel algorithm which solves the problem using two parameters: t(n) and p(«), where t(n) (resp., p(n)) is equal to the maximum, over all instances of size n, of the number of time units (resp., the number of processors) used by the algorithm. Since we can always save a constant factor in the number of processors at the cost of the same constant factor in the running time we Chapter 1: Introduction page 4 omit the "big oh" when specifying the number of processors. The total work of a parallel algorithm is defined as the product p(n )t(n ). We are especially interested in designing algorithms whose running time is polylogarithmic (i.e. is 0( log k « ) for some constant k) using a polynomial number of processors. The class of problems which can be solved by such algorithms is denoted by NC. This class was first defined by Pippenger [Pip79] and is broadly accepted as the class of problems which can be solved "fast" using a "reasonable" number of processors. An important property of the class NC is that it is invariant under the choice of model of computation over a broad range of models including the PRAM models described above, uniform circuit models [Bor77],[Ruz81], Alternating Turing Machines [ChaKozSto81][Ruz80], and Vector Machines [PraSto79] (see also the survey of Karp and Ramachandran [KarRam86]). While designing efficient parallel algorithms we are searching for algorithms which minimize total work. Our secondary goal is to minimize the time factor. We usually compare the performance of a parallel algorithm with the time complexity of the best known sequential algorithm to solve the given problem. A parallel algorithm is said to achieve optimal speedup over a sequential algorithm which solves the same problem if the total work of the parallel algorithm is of the same order as the time complexity of the sequential algorithm. The notion of optimal speedup clearly depends on the model. Typically, we look for optimal speedup on the weakest possible PRAM model. For many algorithms presented in the thesis the use of concurrent reads improves the time complexity while the use of concurrent writes is not essential. Therefore, unless otherwise specified, we use the CREW PRAM model as our default. If the use of concurrent writes is known to improve the time complexity of the algorithm we note this explicitly. We use the adjective "optimal" in connection with some of our algorithms. Whenever we refer to an algorithm as an optimal parallel algorithm the total work performed by the algorithm is of the same order as the sequential lower bound for the problem, and the Chapter 1: Introduction page 5 sequential algorithm obtained by simulating the parallel algorithm by one processor satisfies the constraints for which the lower bound was established. 1.2. Parallel Construction of Trees While many sequential tree construction algorithms are well studied (we have optimal sequential algorithms for a large number of tree construction problems) designing parallel tree construction algorithms is not an easy task. Many sequential tree construction algorithms se_em to be inherently sequential. For example, currently no deterministic efficient parallel algorithm to construct the Depth First Search (DFS) tree for an arbitrary graph is known. In fact it has been shown ([Rei85]) that given a graph with fixed adjacency lists the problem of computing of the lexicographic DFS order is P-complete (i.e. given any polynomial-time sequential algorithm A with input of length n we can construct, in 0(log n) space, an instance of the lexicographic DFS problem which has a positive solution exactly when A accepts its input). Also the best algorithm known for constructing the Breadth First Search (BFS) tree for a directed graph takes 0(log2n) time using M(n) processors, where M(n) denotes the number of processors needed to multiply two n x n matrices in 0(log n) time. The best upper bound on M(n) is currently M(n)=0(n2-376) [CopWin87], Thus this algorithm does not achieve optimal speedup. We consider two basic methods of constructing trees, namely tree expansion and tree synthesis. In the tree expansion method we start with a single vertex and construct the tree by adding nodes of degree one and/or by subdividing edges. Typical examples of sequential algorithms constructing trees using this approach are algorithms for finding the BFS and the DFS spanning trees of a graph, Prim's algorithm for finding the Minimum Spanning Tree (MST) [Jar30], [Pri55], [Dij59], and most recursive and top-down tree construction algorithms. In a parallel setting this technique consists of introducing an C h a p t e r 1: I n t r o d u c t i o n page 6 independent set of nodes forming new leaves or subdividing edges at each parallel step. Thus it is closely related to the tree contraction method ([MilRei85], [Rei85], [GibRyt87], [ColVis86c], [AbrDadKirPrz87], [GazMilTen87], [AbrDadKirPrz88], [GibRyt89]) discussed in Section 2.5. We introduce the parallel tree expansion method in Chapter 3. We use this technique to construct the tree representation for graphs in the family of graphs known as cographs. In the same chapter we outline a parallel construction of a tree representation for graphs in the family of graphs known as parity graphs. Some of the results of Chapter 3 are reported in [KirPrz87] and [PrzCor89]. Cographs, like various other families of graphs have a recursive description which allows us to represent theni with the help of a tree. Among other families of graphs which permit a tree representation are parity graphs [BurUhr84], outerplanar graphs [Gol80], Halin graphs [Sys84], chordal graphs [ G 0 I 8 O ] , partial k-trees [ G 0 I 8 O ] (in particular, series-parallel graphs), and graphs generated by-eontext free grammars [Sli82]. Because of the number of parallel techniques related to trees, families of graphs which have tree representations often admit efficient parallel algorithms to solve problems which are difficult for general graphs (see for example [BerLawWon85], [He86b], [Ede87], [DahKar87], [NaoNaoSc87], [AbrDadKirPrz89], [RytSzy89]). In the tree synthesis method we start with a forest of single node subtrees and construct the tree by adding edges or (for rooted trees) by creating parent nodes for some roots of the trees in the forest. Kruskal's algorithm for constructing a minimum cost spanning tree and algorithms to construct other families of weighted trees which minimize certain cost functions serve as examples of the tree synthesis method. A number of such families of trees (for example Huffman trees, Binary Search Trees) can be constructed using the parallel dynamic programming technique of Miller, Ramachandran, and Kaltofen ([MilRamKal86]). A major limitation of this technique is its high processor cost. In certain circumstances one can significantly reduce the number of processors used by the parallel Chapter 1: Introduction page 7 dynamic programming algorithm [AtaKosLarMilTen89]. It also appears that a slight relaxation of the optimality criterion can lead to more efficient parallel algorithms. We define the error of a tree to be the difference between the cost of the tree and the cost of an optimal tree for the given input. In the relaxed version of a problem, instead of looking for an optimal solution we are searching for an almost optimal tree, i.e. for a tree whose error is small. Following this idea, we present in Chapter 4 a family of parallel and sequential algorithms to construct various approximations to the Huffman tree. In particular,we present an algorithm which achieves almost optimal speedup (0(logn \og*n) 1time using n processors) over the Huffman algorithm and produces a tree with a very small error. This result has been achieved by applying a cascading sampling technique - a new technique related to that used in Cole's merging sort algorithm [ C 0 I 8 6 ] . The best currently known parallel algorithm for (exact) construction of the Huffman tree is due to Atallah et. al. [AtaKosLarMilTen89]. It runs in 0( log 2 «) using n2/log n CREW processors. Some of the results presented in this chapter were reported in [KirkPrz90]. All algorithms presented in Chapter 4 apply the tree synthesis method by constructing a tree in a level-by-level fashion. At each parallel step we construct parents for elements which are (up to some approximation) on the same level of the constructed tree. The relaxation of the problem allows us to concentrate on trees of logarithmic height and consequently leads to a fast algorithm. One might suspect that the parallel tree synthesis method can be applied only to trees of polylogarithmic height, but this is not the case. In Chapter 5 we present a technique which we call the valley filling technique. Our technique can be considered as an accelerated version of the technique proposed independently by Atallah et. al. [AtaKosLarMilTen89]. We present an application of this technique to an optimal parallel 1log*n={min i: logWn <!} where log(0« donotes i times composotion of the log function Chapter 1: Introduction page 8 algorithm for construction of minimax trees. This, as a special case, leads also to an optimal parallel algorithm for construction of trees from a given sequence of leaves' heights, improving one of the results of Atallah et. al. [AtaKosLarMilTen89]. 1 . 3 . A s y s t e m a t i c a p p r o a c h t o a l g o r i t h m i c p r o b l e m s In this_section we present a formal framework for the presentation of computation techniques and families of algorithms. Sections 2.2, 2.3, 2.5 of Chapter 2 provide examples (of increasing difficulty) of the application of this method. The reader may choose to read this section together with one of those sections. While describing an algorithmic technique we try to abstract a common method used in a family of algorithms. In our approach we would like to see the description of the method and an algorithm which solves a problem using the given method to be in a similar relation as an abstract algebra and its model. To achieve this goal we describe computational methods with the help of algorithmic schemes. An algorithmic scheme is a partially uninterpreted algorithm. This notion was probably first introduced in 1960 by McCarthy ([McC60]) and subsequently developed and popularized by Paterson and Hewitt ([PatHew70]). We define an algorithmic scheme as a sequence & = <J9,p1,...,pn, Ax, F> where Pi,...pn are names of procedures or functions, Ax is a set of axioms defining properties of Pi,...,pn, IP is a program which in addition to the terms of a programming language contains names pi,...,pn, and J9 is the domain of the input. One can think of IP as an algorithm whose meaning depends on the definitions of Pi,...,pn- A sequence pj,...,pn is called an interpretation of the algorithmic scheme Cl if pj,...,pn is a sequence of procedures and functions satisfying axioms Ax. An interpretation of an algorithmic scheme IP uniquely determines an algorithm, namely the algorithm obtained from F by substituting names Pi,...,pn for procedures pj,...,pn. Thus we usually identify an Chapter 1: Introduction page 9 interpretation with the algorithm it defines. For a simple application of this description method see, for example, Section 2.2. We can also view an algorithmic scheme as universal description of a family of algorithms. We take a great advantage of this approach in Chapter 4 where the use of an algorithmic scheme not only simplifies the description but also allows us to state and prove properties common to all algorithms in the family. We use algorithmic schemes in descriptions of many but not all techniques depending on how much can be gained by using this sort of formalism. We often replace an axiomatic presentation of properties of procedures and functions by a less formal but more intuitive description. 1.4. Basic definit ions and notat ion Our graph theoretical terminology is standard (cf. [AhoHopU1174], [Tar83], [Knu68]). A tree is a connected graph without cycles. A tree together with a distinguished node, called the root, is called a rooted tree. This thesis mainly concerns rooted trees so we omit the adjective "rooted" whenever no confusion arises. Let U be the set of nodes of a rooted tree T. Nodes of degree one (for a rooted tree nodes of degree one different than the root) are called leaves. A node which is not a leaf is called an internal node. For a node UG U we use /-r-(u) to denote the length of the unique path from the root to u. /T(u) is refered to as the depth of node u in tree T. The value m^|T(u) is called the height of T. The ith level of a tree is the set of all nodes of depth i. By convention we think of a tree as having the root at the top and the leaves at the bottom. For any two nodes u,ve U if u belongs to the path from the root to node v then u is an ancestor of v and v is a descendant of u. If in addition u and v are connected by an Chapter 1: Introduction page 10 edge then u is the parent of v (we denote it by parentis)) and v is a child of u. Nodes with a common parent node are called siblings. A rooted tree is called a t-ary tree if every internal node has at most t children. A rooted tree whose every internal node has exactly t children is called a full t-ary tree. A full binary tree all of whose leaves belong to at most two adjacent levels is called an almost balanced binary tree. An ordered tree is a tree together with an ordering of each internal node's children. We think of this ordering as the left-to-right ordering. In particular, for an internal node of an ordered binary tree we distinguish its left child and right child. If v is an internal node of an ordered binary tree then right(w) denotes its right child and left(v) denotes its left child. An ordering is often implicit in a representation of a tree. Typically our tree construction algorithms construct ordered trees. A subtree rooted at an internal node u of a tree T is the tree induced on the set of nodes which are descendants of u (including u). We also consider trees whose leaves are labelled with elements from some set. A family of ordered trees such that the right to left order of the leaf labels is fixed is called a family of alphabetic trees. If the leaves of a tree are labelled by elements from R+ then we are dealing with (leaf) weighted trees. Let V be a set of leaves. A (leaf) weighted tree is a tree together with a function w: V—> R + (where V is the set of leaves of T) called the weight function. The value w(v) is called the weight of the element v. Frequently the weight function can be extended to all nodes by defining the weight of an internal node to be some function of the weights of its children. Chapter 1: Introduction page 11 T w o weigh ted trees, T and T ' , are i somorph i c i f there exists a weigh t preserv ing i s o m o p r h i s m f r o m T to T ' . T w o weigh ted alphabetic trees, T and T 1 , are i somorph ic i f there exists a weight and order preserving i somorph i sm f rom T to T ' . L e t <T be a finite f a m i l y o f weigh ted (possibly alphabetic) trees. A funct ion c : cT—> R+ such that i f T , T e 3* are i somorphic then c (T) = c(T') and i f T " is a subtree o f T then c (T") < c (T) is c a l l ed a cost function. A tree T * e <T such that c (T*) = m i n c (T) i s ca l led an optimal tree with respect to the cost Junction c. Chapter 2: Basic techniques for design of parallel algorithms page 12 CHAPTER 2: BASIC TECHNIQUES FOR DESIGN OF PARALLEL ALGORITHMS In this chapter we present general parallel techniques which support our tree construction techniques, and we describe in more detail our contribution to the tree contraction technique (Section 2.5) and the cascading sampling technique (Section 2.6). In Section 2.7, we discuss the parallel divide-and-conquer technique and present a divide-and-conquer algorithm for the All Dominating Neighbor problem which will be used in Chapter 5. 2.1 . Brent 's scheduling pr inc ip le Brent's scheduling principle [Bre74] is a method which is often used to reduce the number of processors used by a parallel algorithm. Consider an algorithm which performs t(n) parallel steps sj,...,st(n). Assume that in step Sj the algorithm performs x± parallel * n ) operations. The number of processors used by the algorithm is m = max xj. Let x = ^ X j . i=l We can simulate step Sj of the algorithm with p<m processors in at most T^-l time. Thus the total time needed to simulate the entire algorithm using p processors is bounded by — + t(«). This technique, known as Brent's scheduling principle, allows us to reduce the number of processors if a large number of processors are idle during a substantial part of the computation. An example of such a computation is the prefix sum algorithm presented in the next section. It should be noted that to apply Brent's scheduling principle one must Chapter 2: Basic techniques for design of parallel algorithms page 13 know how to associate each processor to its job. This problem is called the processor allocation problem and may be nontrivial in general. 2.2. Pref ix sum computat ion Associated with an array X=[x lv..,xn] of n real numbers is an array S=[slv..,sJ of j prefix sums, where Sj = (j=l,...,«). The prefix sum problem is, given an input array i=l X compute the array S of its prefix sums. A parallel prefix sum algorithm was probably first proposed by Ofman ([Ofm63]), however more attention has been given to a later paper of Ladner and Fischer ([LadFis80]). The algorithm can be described as follows: Build an almost balanced binary tree (embedded in the plane) whose consecutive leaves correspond to the consecutive elements of the input array and such that every internal node knows the address of the preceding node from the same level (which we call its left neighbor if such a vertex exists). Then for every internal node v compute the sum of the elements corresponding to the leaves of the subtree rooted at v. This can be done in 0(log n) time with n processors by a bottom-up computation (see Figure 2.1 a). Now process the vertices in top-down fashion. For every internal node v the value of its right child is set to be equal to the value of v and the value of its left child is increased by the value of the left neighbor of v (if it exists). At the end of this computation the i-th leaf has the value of the i-th prefix sum associated with it. An 0(log n)-time «-processor EREW PRAM implementation is obvious. To reduce the number of processors to n/log n we apply Brent's principle, assigning each of n I log n processors to a block of log n successive leaves. In this way the obvious simulation of the 0(«)-processor implementation incurs an additional additive overhead of only 0(log n) time. Chapter 2: Basic techniques for design of parallel algorithms page 14 a) 20 20 11- -#•20 A A -• l l - ^ 18-• 20 A A ^ A 2 1 3 5 4 3 1 1 b) 2 3 6 11 15 18 19 2C Figure 2.1. A prefix sum computation The method used to solve the prefix sum computation problem can be described by the following algorithmic scheme (we assume for simplicity that n = 2 m): where: JS) is a domain, 0 : JS) x JS) -> JS, Ax : x,y,ze JS) => x©(y0z)= (xffiy)©z F: Input: array X=fx1 x nl of elements from JS). Output :S= [si,...,sn] Scheme: For all i do sp := XJ; For k:=l to m do for each i=l,...,2m"k do s ^ s ^ a - i S s 1 ^ ; For k:=m to 1 do for each i=l,...,2mk do skl2i:=ski; S ^ i - l ^ i - i e s * - ! ^ ; For all i do S j : = s;° ; It is easy to see that for any interpretation of © which satisfies the axiom in Ax the above scheme yields an algorithm which computes S j = xi © X2 © . . . © X j . Furthermore if © can be computed in O(T) time with F processors then the corresponding interpretation of tP A can be implemented in 0(T log n) time with IP n processors. To reduce the number of processors to Pn/log n we apply Brent's principle, assigning each of Chapter 2: Basic techniques for design of parallel algorithms page 15 P n / log n processors to a block of log n successive leaves and simulate the O(Pn) processor implementation with Pn / log n processors just as we simulated the n processor implementation of the prefix sum algorithm with nAog n processors. Note that if X is a boolean array and © is interpreted as the "or" function then the above scheme leads to an algorithm which computes the "or" function of the boolean values given in the array in 0(log n) time using n/log n EREW processors. Cook, Dwork, and Reischuk [CooDwoRes86] showed that the "or" function requires time Q.(log n) on a CREW P R A M no matter how many processors or memory cells are used. Therefore the above algorithm achieves the best possible bound. Berkman, Breslauer, Galil, Schieber, and Vishkin [BeBrGalSchVis89] showed that the time factor can be reduced to 0(loglog n) (preserving the total work up to a constant factor) if a CRCW model is used. 2.3. L is t rank ing The list ranking problem is to compute, for each element of a list of elements, its distance from the end of the list. The list ranking problem can be solved using a method closely related to the prefix sum method. The list ranking problem is equivalent to a suffix sum computation, provided that the input sequence is presented in the form of a list and all elements have an assigned value equal to one. Wyllie [Wyl81] proposed a simple list ranking algorithm which can be viewed as an interpretation of the following algorithmic scheme (we assume for simplicity that n = 2m): ZK = < J 9 , © , A x , F > where: J9 is a domain; © : JS)x <£>-> J9, Ax : x,y,ze <© => x © ( y © z ) = ( x © y ) © z Chapter 2: Basic techniques for design of parallel algorithms page 16 F : Input: X = [xi,...,xn] ; SUCC= [succ1,...,succn] where X is an array containing elements of the list and sucq is equal to the index in X of the element following Xj in the list; Output: D=[di,...dn] where dj= 0 X j j=i...« Scheme: For log n iterations repeat in parallel for i =1 ..n do X(i):=X(i) ©X(SUCC(i)); SUCC(i): =SUCC(SUCC(i)). in parallel for i =1 ..n do D(i):=X(i); To obtain a parallel algorithm for the list ranking problem we simply set Xj=l for i=l,..n and interpret © as addition. In general if © can be computed in O(T) time with F processors then the above algorithmic scheme leads to an 0(T log «)-time and Fn -processor algorithm. The technique used in this scheme is also called the pointer jumping technique. Much effort has been made to find a list ranking algorithm which solves the problem in 0(log n) time using only ft/log n processors. Like the prefix sum computation this is the best one can do on a CREW PRAM model. The algorithm given by Wyllie [Wyl81] has been gradually improved through a series of deterministic and randomized results ([Vis84], [KruRudSni85], [MilRef85], [AbrDadKirPrz87b] ). A deterministic algorithm achieving these complexity bounds (on a EREW PRAM) has been given by Cole and Vishkin in [ColVis86]. Because of the large constant in the time factor this algorithm is mainly of theoretical interest. Subsequently, a simpler optimal algorithm (which involves reasonable constants) has been proposed in Anderson and Miller [AndMil88]. Any of these algorithms can be abstracted to obtain an algorithmic scheme leading to an 0(T log n)-time Prc/log tt-processor algorithm. Chapter 2: Basic techniques for design of parallel algorithms page 17 2.4. Euler tour technique The Euler tour technique [TarVis84] provides a general method for reducing computation of certain functions on trees (for example preorder number, number of ancestors) to list ranking. The basic idea is to replace each tree edge by a pair of directed edges with opposite directions, and consider an Euler path which starts and ends at the root. This Euler path, together with some labeling forms the input to a list ranking problem. Assume, for simplicity, that the input tree is a binary tree. To describe the technique we present an algorithm to compute the left-to-right numbering of tree leaves: Example 2.1. Computing the left-to-right numbering of leaves of an input tree Input: a rooted binary tree T; Output: left-to-right numbering of leaves STEP 1. Build a unique list L corresponding to the input tree : Each node v of T is split into three nodes V T , V L and V R . For each of the resulting nodes we define a next field as follows. If v is a leaf then vr.next = V L and VL-next = V R . If w is the right child of v then VL.next = wj and WR.next = V R . If w is the left child of v then v-r.next = wj and WR.next = What results is a l i s t that starts atrootx and ends at r o o t R and traverses each edge of T once in each direction. This is the unique list L corresponding to the input tree. STEP 2. Reduce the computation of the tree function to some interpretation of 33 ift, which  takes the list L as its input. Label the elements of L as follows: x T j = 1, x L j = x R j = 0 if Xj corresponds to a leaf and x T j = x L j = x R j = 0 otherwise and interpret © as addition. It is easy to confirm that after running this interpretation of 33 (R, on the list L , the value at each x T j corresponding to a leaf is equal to the left-to-right number of this leaf. Chapter 2: Basic techniques for design of parallel algorithms page 18 2.5. Tree Contraction The tree contraction problem occurs most naturally in the context of dynamic expression evaluation for an expression presented in the form of a parse tree. The size of an expression is defined by the number of leaves of the parse tree. Brent [Bre74] showed that expressions of size n could be rewritten in straight-line code of depth 0(log n). His approach is a top-down approach and its natural dynamic implementation seems to require 0(log 2«) time. Miller and Reif [MilRei85] describe a deterministic algorithm for dynamic expression evaluation which runs in 0(log n) time with 0(n) processors. A similar result has been independendy reported by Rytter [Ryt85]. A single step of the algorithm of Miller and Reif converts the current binary parse tree to a simpler one by removing, in parallel, all leaves (RAKE operation) and compressing maximal chains of nodes with only one child (COMPRESS operation). During the RAKE operation we compute the values of the expressions at internal nodes all of whose children are leaves. We also modify the functions associated with internal nodes whose number of children has been reduced as the result of the RAKE operation, to obtain functions with the number of arguments equal to the number of children. During the COMPRESS operation we perform a symbolic computation consisting of the composition of the one argument functions associated with the nodes on the compressed paths. Miller and Reif show that after 0(log n) such steps the given tree will be reduced to its root (and thus the expression defined by the tree is computed). Miller and Reif apply their method to construct parallel algorithms for problems which can be reduced to computation on trees. They give a randomized algorithm for testing isomorphism of trees, a deterministic algorithm for constructing a tree of 3-connected components of a planar graph, as well as other algorithms. Among the important contributions of Miller and Reif [MilRei85] is their abstraction of the problem of tree contraction. This leads to a separation of the problem from its familiar applications Chapter 2: Basic techniques for design of parallel algorithms page 19 (notably, dynamic expression evaluation) and places it, along with list ranking, among the fundamental problems of parallel computation. A natural side effect has been the identification of new and unforeseen applications [DadKir87], [He86], [GibRyt86]. Another approach to dynamic expression evaluation is presented by Gibbons and Rytter [GibRyt86]. Their algorithm runs in 0(log n) time using 0(«/log n) processors. They assume, however, that the input (the string representing the expression to be computed) is given in an array and is hence preordered. They prove that the algorithm can be applied to compute an algebraic expression in any algebra with finite carrier. Cole and Vishkin [ColVis86c] propose an alternative method for computation on trees. They solve the tree contraction problem by parallel reduction to the list ranking problem. In this respect their approach is similar to the approach described in this thesis. Our reduction, an abstraction of the technique used for the parallel preprocessing of region trees for fast (sequential) subdivision search [DadKir87], is simpler and more explicit than that of Cole and Vishkin; in particular, it completely avoids the centroid decomposition techniques that lie at the heart of their reduction. Similar algorithms have been proposed independendy by Gibbons and Rytter [GibRyt88] and Kosaraju and Delcher [KosDel88]. All the algorithms considered above share a basic similarity: in each parallel step a parse tree is shrunk by independent vertex removal. For this reason the technique used for dynamic expression evaluation is called the tree contraction technique. One can see a tree contraction technique as a scheduling technique. Namely, for each processor we decide to which node it is assigned at a given time unit. The processor assigned to a tree node at a given time is available for performing a computation which consists either of computing a subexpression or performing a symbolic computation. Additionally the nodes which have been assigned a given time unit are removed from the tree at this time unit. Chapter 2: Basic techniques for design of parallel algorithms page 20 The tree contraction method appears to be a very powerful technique. Thus several researchers have tried to formalize a class of problems which can be solved using this technique. He [He86b] defines the binary tree algebraic computation (BTAC) problem and applies Miller and Reif s technique to obtain a parallel algorithm for this problem. Roughly speaking, the B T A C problem is to compute the value of an algebraic expression given in the form of a parse tree under the assumption that the algebra in which the computation is performed has a finite carrier. A more abstract approach has been taken by Abrahamson, Dadoun, Kirkpatrick and Przytycka [AbrDadKirPrz87] and Miller and Teng [MilTen87]. Our description again follows [AbrDadKirPrz87] but an influence of [MilTen87] should be noted. 2 . 5 . 1 . A t r e e c o n t r a c t i o n a l g o r i t h m . We w i l l assume that trees are presented as an (unordered) array of vertices each of which has associated with it a parent pointer and a doubly-linked list of children. (Of course, it is possible to efficiently convert to or emulate such a representation starting with other more primitive representations.) (Successive) vertices on any list of children are said to be (immediate) siblings. Let T be any binary tree with vertex set V(T). A sequence of trees T\, T2,... is said to be a tree contraction sequence of length A: for T if, (i) T\=T \ (ii) V ( 7 i ) c v d i J ; (iii) I V( T k ) I < 3 ; and (iv) i f v e V( Ti.i) -V(Ti) then either (a) v is a leaf of T\.\ , or (b) v has exactly one child, x, in 7Vi, x e V(T{), and the parent of v in T\_\ is the parent of x in Tv Chapter 2: Basic techniques for design of parallel algorithms page 21 Figure 2.2. Prune and Bypass operations It is clear from the definition that successive trees in a tree contraction sequence are formed by "independent" executions of the following two fundamental operations (see Figure 2.2): Prune(v) — leaf v is removed from the current tree; and Bypass(v) — non-root node v with exactly one child x is removed from the current tree, and the parent w of v becomes the new parent of x (with x replacing v as a child of w). By "independent" we mean that if v is pruned or bypassed then its parent is not bypassed. In this way tree modifications are ensured to be local and executable in parallel. Chapter 2: Basic techniques for design of parallel algorithms page 22 Figure 2.3. Interpretation of Trees as Binary Trees We say that a contraction sequence is a-compact if it has length at most odog n. The tree contraction problem is to construct, for an arbitrary tree T, an a-compact tree contraction sequence for T where a is some universal constant. For our applications it is not necessary to construct the sequence explicitly; it suffices to associate with each node v the index i of the highest indexed tree containing v in the sequence, together with pointers to the parent and child (if any) of v in T{. Since the tree contraction problem for a nonbinary tree T can be naturally reduced to a tree contraction problem for a binary tree T' obtained from T by a binarization step (see Figure 2.3) we Chapter 2: Basic techniques for design of parallel algorithms page 23 concentrate on binary trees only. We should also note that the operations RAKE and COMPRESS used in the tree contraction algorithm of Miller and Reif [MilRei85] can be implemented with the help of the Prune and Bypass operations. The pair of operations Prune(v) followed by Bypass(parent(v)) (where v is any leaf) form a conceptual unit in our algorithm. The algorithm proceeds in phases, each of which consists of a batch of these basic contractions performed in parallel. The independence of the underlying operations is guaranteed by a simple global schedule for leaf removal. Let the leaves be numbered in left to right order. A leaf is removed in phase t if the rightmost 1 in its leaf index is in position t. Our binary tree contraction algorithm has the following simple description: procedure contract (7) (* Assign leaf indices from 0 to rt - 1 *) for each leaf v in parallel index(v) <— left_to_right leaf index of v (* Contraction iterations. *) repeat Tlog nl times for each leaf v in parallel w <— parent (v) if index(v) is odd and w * root then if v is a left child then prune (v) bypass(w) if v is a right child then prune (v) bypass (w) else index(v) <— index (v)/2 Note that the innermost if statements, though they have opposite conditions, are intended to be executed in sequence, with appropriate synchronization in between. Thus, Chapter 2: Basic techniques for design of parallel algorithms page 24 each iteration of the repeat loop has four slots in which prune or bypass operations may be executed. Accordingly, we associate four elements of the tree contraction sequence with each iteration of the repeat loop, describing the tree after each of the four slots. It is also helpful to view the behavior of the algorithm at two other levels. It is immediate from the description that each prune operation is immediately followed by a bypass. Hence in each successive pair of slots a number of composite prune-bypass operations are executed in parallel. Each pair of these composite slots (making up an entire iteration of the repeat loop) serves to eliminate all of the leaves with odd parity in the current tree together with their parents. An example of a tree contraction sequence produced by procedure contract is given on Figure 2.4. Figure 2.4. A tree contraction sequence L e m m a 2.2. Procedure contract constructs a 2-compact tree contraction sequence. P r o o f : It suffices to demonstrate that the prunes and bypasses are performed independently. Since prunes and bypasses are never executed simultaneously, it need only be demonstrated that no vertex v and its parent w are ever bypassed simultaneously. Suppose this is not the case. Without loss of generality, v is the right child of w. Since they are bypassed simultaneously, they must both have leaves as left children. But since o 6/2 Chapter 2: Basic techniques for design of parallel algorithms page 25 these leaves are adjacent in the left to right order and since the index array maintains each leafs left-to-right rank in the current contraction iteration (except, possibly, for the left child of the root), v and w must have indices of opposite parity, a contradiction. • Theorem 2.3. Procedure contract provides an 0(log n)-time and 0(n / log n)-processor EREW PRAM deterministic reduction of tree contraction to list ranking. Proof: We can compute the left-to-right numbering of the leaves of the tree in 0(log n) time with n/log n processors using the Euler tour technique (Example 2.1). Thus it suffices to prove that the iterated contraction step of procedure contract can be implemented in 0(log n) time using 0(rc/log n) processors. An 0(log n) time, 0(n) processor implementation is immediate; if one processor is devoted to each leaf then each phase can be carried out in 0(1) time. To reduce the number of processors to rc/log n we apply Brent's principle as in the prefix sum computation scheme (Section 2.2) • It follows from Theorem 2.3 that the results for list ranking carry over directly to tree contraction. We summarize the most important consequence in the following: Corollary 2.4. The tree contraction problem can be solved deterministically in 0(log n) time using 0(« / log n) processors on a EREW PRAM. 2.5.2. Bottom-up Algebraic Tree Computations A tree contraction algorithm gives a method for solving a large class of parallel tree computation problems. This class includes, for example, dynamic expression evaluation ([MilRei85], [GibRyt86]). He [He86a] and Gibbons and Rytter [GibRyt86] noted that any algebraic expression with operands from an algebra with carrier of fixed finite size can be computed in the cost of tree contraction. This result provides efficient parallel algorithms for several optimization problems, for example minimum covering set, maximum Chapter 2: Basic techniques for design of parallel algorithms page 26 independent set and maximum matching, when the underlying graph is a tree [He86] or has a tree representation [AbrDadKirPrz88], [RytSzy89]. In fact, we can relax the assumption that the carrier of the algebra is of fixed finite size and put some restrictions on the operations only. We can generalize He's binary tree algebraic computation problem in the following way: Let JS) be a set and JFe [f \f: JS) x JS) -> JS)} a set of two-variable functions over JS). The objective of bottom-up algebraic tree computations is to take any ordered regular binary tree T whose leaves are labelled by elements of JS) and whose internal nodes are labelled by elements of CF and to evaluate the algebraic expression associated with T (where functions at internal nodes denote operators and elements labelling leaves are operands). It is natural (and helpful) to generalize the above notion to include a set of functions 9e {g I g : JS)—> JS)}, including the identity function, which serve as edge labels and influence the computation in the obvious way. The triple (JS), defines a bottom-up algebraic tree computation (B-ATC) problem. An indexed set CF of functions is called (T, P) - universal if there exists a universal algorithm to compute the value of any function from ^ in any point of its domain in time T using IP processors. We can formalize a class of problems which can be solved using the tree contraction method the help of the following algorithmic scheme : J 3 _ C i t r G =<<©,9,cr> where: JS) - a domain 9<= {gig: JS) -> JS) }; y c {f|f: JS) xJS) -> JB }; Chapter 2: Basic techniques for design of parallel algorithms page 27 Ax: (decomposability axioms) (i) 9 and CF are (T, P) - universal for some T and IP; (ii) for all gi, gj, e 9» /m G & and ae JS) the functions gs and g t given by gs(x) = gi(/ m( gj(x), a )) and gt(x) = gi(fm( a, gj(x))) both belong to 9 and their indices s and t can be computed from i, j, m and a by an algorithm which runs in T time using P processors IP: Input: A binary tree T with internal nodes labelled with functions ^  from and edges labelled with functions from 9 and leaves labelled with elements from JS) . Output: The value of the expression defined by the parse tree T. Scheme: Run the procedure contract(T) labelling the new tree edges as follows: Let e be an edge whose one endpoint is a leaf labelled a and the other endpoint is internal node v. Let gj be the label of the edge leading from v to its nonleaf son and & be the label of the edge leading from v to its parent. The edge introduced by an application of Prune to the a leaf labelled a and Bypass to its parent v is given the label gs(x) = gi(fm( gj(x),a )) or gt(x) = gi(fm( a, gj(x) )) depending on whether a is the left or the right child of v. The idea of the algorithm is perhaps most easily understood by referring to the transformations of Figure 2.5. A B-ATC problem which satisfies the decomposability axioms (i) and (ii) defined above is called decomposable. Theorem 2.5. For any interpretation of the "03 Cl <TC scheme and for any input tree the associated algebraic expression can be evaluated in time 0(T log ri) using P «/log n processors. Proof: This follows immediately from the tree contraction algorithm and the decomposability axioms. Chapter 2: Basic techniques for design of parallel algorithms page 28 Figure 2.5. New labelling of edges after Prune and Bypass operations Remark 2.6: We should note that we can easily modify the computation scheme in such a way that we will also compute all the functions in internal nodes. In order to do so each bypassed node maintains a pointer to the lower level endpoint of the bypassing edge (i.e. the node whose computation has to be finished in order to finish the computation of the given node). For example, in Figure 2.5 the bypassed node labelled/m retains a pointer to the leaf labelled a and the root of the subtree Y. After finishing the computation of the function in the root we add a new phase to the algorithm. In this phase we allow all the internal nodes to finish computing the values of the function assigned to these nodes. Note Chapter 2: Basic techniques for design of parallel algorithms page 29 that for every internal node v removed at some iteration of the procedure contract one of its children remains in the tree. Furthermore to finish the computation at v it suffices to know the value of this child. In the last tree of the tree contraction sequence the values at all nodes are computed. Thus we can complete the computation at the remaining vertices by processing them in the reverse of their order of elimination in the contraction sequence. We refer to the TF5 Cl <TG computation scheme modified as in Remark 2.6 as the full B _ d . c T G computation scheme. Note that any algebra with a finite carrier has an associated instance of tT3_Cl <T"G (with T and IP being constants). It is also easy to see that general {+, -, *, /} arithmetic computations can be described as an instance of the H5_Ci cTT3. In the example given below we present an interpretation of the U3_Cl «Ttj which we use in our optimal algorithm to construct minimax trees (Chapter 5). Example 2.7: Let T be a tree of n leaves such that every internal node u is labelled with an integer number Xu. Consider the following bottom-up assignment of values to the tree nodes: To compute this labelling one can use the following interpretation of the B_Cl <T £5 scheme: Define the following indexed families of functions (M denotes the set of natural numbers): 1 if u is a leaf value(u) -rvalueOi!) +value(u2) ~| I _ | if u has children uj and Chapter 2: Basic techniques for design of parallel algorithms page 30 3-={f m:N x N->N lm>0; f m(x,y) = l ~ ^ l } • Associate with each edge of T the identity function gQi and with each internal node u the function f^. We show that <N,9,3r> is an interpretation of the H3_Cl <Tt!. It is obvious that the value of any function from the family 9 or ^  can be computed in a constant time from its argument(s). Thus to prove that <N,9,3 r> defines an instance of the U3_Cj eft! it suffices to prove that for any i,j,k,l,m the following holds: (i) gij(fm(gk,i(x),a)) = gq;P(x) for some q and p and q,p can be computed in 0(1) time from i,j,k,l,m; and (ii) gij(f m(a,gj f )i(x))) = g q > p(x) for some q and p and q,p can be computed in O(l) time from i,j,k,l,m; We need the following fact: Fact: For any real number z and integer n (n>0) Proof: If LzJ = z then the equality is obvious. So assume LzJ < z. Note that |_zj = nk+m for some k,m >0 and m<n. So z = LzJ + e = nk+m + e for some 0 < e <1 and [z] -nk+m+1. Thus n n n 1 On the other hand 1 - 1 = | n k + m + e ] = | n 1 n 1 1 , m+el k+ = k+1. n Since f m is symmetric it suffices to prove only (i). But by the fact above we have: gi,j( fm(gk,l( x). a)) = §k+la+mla,lmj( x )-m + I rx+(k+la+mli)~| - 1 mlj 1 Chapter 2: Basic techniques for design of parallel algorithms page 31 Thus to compute value(u) for every node u we assign the element 1 to each leaf and apply the above interpretation of the full U3_Cl ETG scheme. As a consequence the problem of Example 2.7 can be evaluated in time 0(log n) using «/log n processors. 2.5.2. Top-down Algebraic Tree Computations The tf3_Ci <Ttj provides a useful abstraction of many bottom-up tree-based computations. In a number of applications it is necessary to consider top-down (or perhaps a combination of bottom-up and top-down) computations based on trees. For this purpose we introduce <T_Cl <Ttj - the Top-Down Algebraic Tree Computation scheme. Formally: £r_eisrt! =<<© ,y> where: JS) - a domain ? c {f i f ; JS) -> JS) }; Ax: (i) y is (T ,P ) - universal for some P and T ; (ii) y is closed under composition and for each h\, hj e ^ the index of hi 0 fy can be computed from i and j by an 0(T)-time P-processor universal algorithm. P: Input: A binary tree T with edges labelled with functions from & and the root labelled with an element, a, from JS) . Output: For each internal node or leaf,v, evaluate the function fv(a) defined as follows: f v(a)=g(fp a r e n,( v)(a)) where g is the function associated with the edge (\,parent{\)). Scheme: Run the tree contraction algorithm. Each edge e introduced by a bypass operation can, as part of the tree contraction process, be labelled by the composition of the functions associated with the nodes and edges on the path (in T) joining the endpoints of e. The vertices of T are considered in the reverse Chapter 2: Basic techniques for design of parallel algorithms page 32 order of their elimination in the tree contraction sequence. It is straightforward to confirm that the values of vertices in tree Ti can be computed in time T knowing the values of vertices in tree Tu. Theorem 2.8: For any interpretation of <T_0. <TC and for any input tree the value associated with each vertex can be computed in Tlog(rc) time with Pn/log n processors. Proof: This follows immediately from the tree contraction algorithm and axioms (i)-(ii). 2.6. Cascading sampling This section is devoted to a technique which was developed to support parallel algorithms based on a sequence of merging steps. The idea of using a "sampling" technique for a problem related to merging was first explored by Cole [ C 0 I 8 6 ] in connection with his optimal parallel merge sort algorithm. Cole's idea has been generalized further by Atallah, Cole, and Goodrich [AtaColGoo87] to a method called the cascading divide-and-conquer technique. Our technique differs from Cole's technique but shares certain important similarities. Both techniques allow a speedup of a computation which is naturally divided into log n levels. (For example, in a divide -and-conquer algorithm the levels corresponds to the depths of recursive calls). Usually one applies a sampling technique to allow pipelining ( [ C 0 I 8 6 ] , [Kos89]). In our approach, the sampling elements are computed during a preprocessing step. They do not allow starting a computation on a higher level prior to finishing the computation on lower levels, but they make it possible to apply a more efficient algorithm on each of the levels. Let f be a function which given a sorted sequence produces a sorted sequence of no longer length and let # denote the merge of two sorted sequences. Consider the following problem: given m sorted sequences d l v . . ,dm (m < log n) of total length at most n Chapter 2: Basic techniques for design of parallel algorithms page 33 compute the following sequences f(d m ) , f(d m . 1 #f(d m )) , f(dm_2#f(dm. 1#f(dm))), ... . The method of computing such a sequence of sequences would depend on the properties of the function f. Our technique can be helpful when the nature of the function f is such that sequences f(d m ) , f(dm_i#f(dm)), f(dm_2# f(dm_i#f(dm))),... are most naturally computed one after another using m consecutive steps. Several examples of such functions are given below. Example 2.9 : b) f(x l 5 . . . . ,x r) = xj+O, x 2+x 1,....,x r+x r_ 1 ; c) Let g: M x N x N -> (true, false). Define f as follows: f(x2,....,xr) = Xi.,....,Xj where I=ii,....,i s is a subsequnce of the sequence l, . . . ,r T o illustrate the cascading sampling technique in a possibly simple way we ignore function f and show a method of computing sequences d m , dm_i#dm, dm_2#dm_ 1#dm, ... one after another in m consecutive steps. One can solve the above problem by applying Valiant's merging algorithm ([Val75], [BorHop85]) 0(log n) times interleaved with computation of the values of the corresponding functions. This leads to an 0(log n loglog «) - t ime tt-processor solution to the problem. In our approach, to speedup the algorithm, we precede the sequence of mergings by a preprocessing step. We say that sequence dj belongs to level i . The goal of the preprocessing is to divide the merging problems into subproblems which can be solved independently such that at least one of the sequences occurring in a subproblem is "short". a) such that j belongs to I if and only if g(j-l,j,j+l) is true. Chapter 2: Basic techniques for design of parallel algorithms page 34 Since the time used by Valiant's algorithm is 0(loglog r), where r is the length of the shorter list, this may speedup the computation significantly. The preprocessing step consists of log*« sampling steps. Informally, in the s t h sampling step, for every level i < n, every (2 s) t h element from this level is merged into the level i+1. Then, among the elements which arrive at level i+1 every second element is merged into level i+2 and so on until level i + [~log(s)rcl is reached1 or no elements are left. Formally, let V sj be the sorted sequence of elements on level i after the s t h sampling step. Initially V S J=VJ°=VJ. Let dist(V,y) denote the distance of the element y from the beginning of the sequence V. For every sequence V k _ 1 j define a family of sorted sequences Ssi,i>Ssi,2>— m m e following way: S s j t = {xl Bye V s _ 1 j s.t. x=y and <i/.sT(Vs_1j,y)=2s+t-1m for some integer m}; Informally, S s j t is the sequence of elements which are originated at level i in the sampling step s and which arrive on level i+t. Then VSj is defined as Vs-1j#( #S s i j t) a+t=j t<| log(s)n I Elements produced in the sampling process are called sampling elements. A l l other elements are called real. To simplify the description we assume that we add sampling elements at the beginning and at the end of every list. For each sampling element x in level i there is a unique element y in level i-1 such that x = y (we say that x = sample(y)) . The element y is called the source element for element x. A source element may also be a sampling element. For any sampling element, x, define source(x) to be equal to the source element of x. Sampling elements which have been generated in the same sampling step form sequences using the pointer source. The element (real or generated in an earlier 1 logWn denotes i times composition of the log function Chapter 2: Basic techniques for design of parallel algorithms page 35 sampling step) which is pointed at by the pointer source of the last element of such a sequence is said to be the origin of the given sequence. Let u i , u 2 , be a pair of sampling elements from the same level i such that there are no other sampling elements between them. The subsequence of elements which lies between uj and u 2 is called a basic sequence. If u^ and u 2 bound a basic sequence then the sequence of elements from the level i-1 which lies between the source of u^ and the source of u 2 is called the gap associated with this basic sequence. The number of elements in a gap is called the size of the gap. Remark 2.10: To merge two sequences on successive levels i-1 and i it suffices to merge each basic sequence from level i with its corresponding gap on level i-1 (after application of the function fj.j to all its elements). Thus if after the preprocessing step the size of a gap is bounded by g(n) then the whole algorithm can be implemented in loglog g(n) time with n processors. Two important properties of the sampling process are given by the following lemmas. L e m m a 2.11. After log*n sampling steps, each gap size is no more than 2 l o 8 * n + 2 . Proof: In the proof of the lemma we use the following simple facts: Fact 1: a) LxJ < L—J m+m; b) M < L—J m+m +1. m m Consider an interval [a,b] on level j . Let us restrict our attention only to those elements whose samples may belong to this interval. Thus we consider only elements v from levels i=l,2,...,j-l such that if ve V j . t then ve [a,b]. We call these elements interval elements. Let ns[ be the number of interval elements on level i after s sampling steps (for simplicity we assume the convention that for i less than 1, ns[ is equal to zero). The proof of the lemma is based on the following fact: Fact 2: ns{ < 2 s n s i + 1 + 3riog(s)nl+2s+1. Proof of Fact 2: We prove Fact 2 by induction on s. For s=l we have: Chapter 2: Basic techniques for design of parallel algorithms n \ < r^ oi.ii+....+r^ -^ oi_riog n 1] a n d i^+l * "°i+l+ L^0iJ+""+Lgi^f °i-Tlog so n \ - 2 \ + 1 < ( « P r 2 T^O.]) + ( T ^ O . J . ^ O . ^ J ) + ...+ r-J-^0._ r i o g ^ < (2+l)riog «1+ r ^ j ^ j « 0 i - r i o g all (by Fact lb) <3riog /xi+i. Assume now that ns-^ < 2 s " 1 « s - 1 i + 1 + 3flog(s-1)n]+2s. But " $ i S "S"''+ rjys-1i-l>..^r2Str|o^u.. i^f,og(s)„ll and Therefore < (^ s-l.^ l^ s-l.j) + (T^s-li_1 .2sL-lTns-li_1j)+... < 2s+l + (Tlns-lj.iX^Vij + - 2 ^ - 1 . l J ) H •••"UlogCsUl"8"1-^ 1  n s j -2 s / i s j < 2S+1 + 2 + 1 - ( 2 S - 2 ) ^ ( ^ S - l i - r ' ^ I J + < 2S + 3TlogW»l -2 + r - i 7 ; ± ^ s . V l o g ( s ) | i l l . ^ V r i o k i i " 5 " ' ^ ' 0 8 ' ^ 1 - 1 -But by the inductive hypothesis we have: ^ - • i J l 0 ^ i a " S - ' ' - r ' ° ^ 1 2 5 ' O g ( S - ' ) " 1 - 2 S . Chapter 2: Basic techniques for design of parallel algorithms page 37 > 2 S - l I 1 ^S-1i-riog(s)nl-3riog(s-1)nl-2s 2 s+riog(s)«Tl 2S-1 J ^ ^-^.rio^^^-SflogCs-Dnl^s _ 2 s _ x ( b y F a c t 1 ( a ) ) L 2s+riog(s)n"Ll J - ^ ^ l o g C s U l ' 1 ^tosW-T 1 2 S + r i o g ( s ) n l . i 1 Therefore « i s - 2 S / z i + 1 s < 2«+ 3riog( s>«l -2 + [ 3 ^ ° g ( s 1 } ^ + 2 S ] + 2s-l + 2 < 2*+ 3riog( s )«l +1+ 2*-* < 2S+I 10g(S)rt r l 3riog( s>«l + 2 S + 1 . • N o w we can continue the proof o f the L e m m a 2.11. L e t a,b be the real numbers wh ich bound weights o f elements in a gap, say on level j . Cons ider the last sampling step. In this step level j receives only elements from level j-1. After the last sampling step in any gap on level j there are at most 2 l o S* r t elements f r o m level j . B y Fac t 2, level j-1 has at most 2 2 1 ° g * " + 3riog ( 1 °g*'0rcl+2 l o g*' I + 1 <2 2 1 o g*' ' + 1 interval elements. E v e r y 2 l o g * » o f them are sent to level j . T h u s in a gap on level j there are at most 2 l o g * n + 1 elements originated at level j-1 and 2 l o g * n elements f r o m level j . T h i s proves that the number o f elements in the gap is bounded by 2 l og*"+ 2. • L e m m a 2 . 1 2 : Af ter the sampl ing process the total number o f elements is bounded by 3 « . Proof: L e t a s be the number o f elements after s m sampling step. Obvious ly : ag = n and a s ^ a s . ! + ^ - = a s . i ( l + ^ ) B u t it is easy to check (by induction) that a s < 3n( l - -\-). N o w we show how to implement the sampling process in 0( l o g * « log n) time with n processors. Chapter 2: Basic techniques for design of parallel algorithms page 38 I M P L E M E N T A T I O N O F T H E S A M P L I N G P R O C E S S : Since, by L e m m a 2.12, in any sampling step we have at most 3n elements we have one processor per constant number of elements. H o w e v e r , we must per form some computat ion w h i c h assigns elements to processors. Initially we have one processor per real element. Inductively assume that processors l , . . . , j have been assigned r elements and processors j + l , . . . , « have been assigned r-1 elements. In the s t n sampl ing step the processor associated with a g iven element checks whether this element is the origin of a sequence of sampling elements and i f so, how long this sequence is. (Note that in the s t h sampl ing step the / t h element in a sequence is the origin o f a chain o f length max{i I / =0 m o d 2 s + i _ 1}) . Since the length o f a sampling sequence is bounded by log n the generation o f such a sequence can be done in 0 ( log ri) time using one processor per sequence. T o assign processors to new sampling elements we number these elements in such a way that i f v and u are two sampling elements and the origin o f v is at a level higher than the or ig in o f u, or origins o f v and u are at the same level but the origin o f v precedes the origin o f u, then v receives a smaller number than u. Note that every "old" element (i.e. an element wh ich is not introduced as a sampling element in the given sampling step) knows the n u m b e r o f new sampl ing elements it has orig inated. S o us ing the pref ix sum computation we can compute for every "old" element the number of new sampling elements preceding it. Since, for every new sampling element y, its posit ion in the sequence o f new sampling elements originated by the same element, say x, is k n o w n in order to obtain the number o f y , it suffices to add this posit ion number to the number o f new sampl ing elements preceding x. After numbering all new sampling elements the element numbered m is assigned to the processor numbered (j+m)mod n. T h i s solves the prob lem o f processor allocation. It remains to insert new sampl ing elements into their proper posit ions in the sequences produced in the previous sampling step. T h i s can be done by a g lobal sorting Chapter 2: Basic techniques for design of parallel algorithms page 39 algorithm. Note that it is important that the sorting procedure which we are using is stable (i.e. it preserves the order of equal elements). If it is not, we can number all elements (in a way similar to the way we numbered all new sampling elements) and sort pairs (number of the element, its value) lexicographically. Since the number of sampling steps is 0(log*n), the whole sampling process can be implemented in 0(log*n log n) time with n processors. In the description of the cascading sampling method we assumed that f is the identity function. Now we can discuss properties of f which are needed to apply the technique. The basic property which we need is, what we call, the distribution by sampling, and can be described as follows (compare Figure 2.6). ( f ( X l , x r ) # y i „ . . y s ) = ^ , (x 1 . . .x^y 1 . .y i , 1 l ly i | | f y i (^ + 1 . . . x#%+1..yj) C ^ •••• * ) ( f(x l t x r) ) # *2 sample (yj Figure 2.6. Distribution by sampling Let xi,....,xr and yi,....,y s be two sorted sequences and let II denotes the concatenation of sequences. Function f converting a sorted sequence into a sorted sequence is said to be distributive by sampling if for any yj we can compute value sample(y[) and function fy. whose complexities are bounded by the complexity of f and such that for any yj if xi,....,xt < sample(yi) < x t + 1 ,....,xr then Chapter 2: Basic techniques for design of parallel algorithms page 40 f y .(x 1 , . . . . ,x t)#y 1 , . . . . ,y i . 1 II yj II f y i (x t + 1 , . . . . ,x r )#y i + 1 , . . . ,y s = f(x l 5....,x r) # y l 5 . . . . , y s . For the function given in Example 2.9a sampleiy) is simply y/2. Function fy. is a modification of the function f and insures a special care of the boundary elements x t and x t + l so that if t is odd then the resulting sequence f y i(xi,....,x t)#yi,....,yj_i II yj II f y i ( x t + i , . . . . , x r ) # y j + Y s contains elements x t +x t + 1 , x t +2+x t +3, ... rather than 2xr, xr+i + xr+2' x r+3 + x r+4»— (which would occur when we simply apply f to subsequnces x l v . . . ,x t and x t + 1,....,x r). A more detailed description of the application of the cascading sampling technique to a problem very similar to the one presented in Example 2.9 a is given in Chapter 4 (section 4.4.2). 2.7. Parallel divide and conquer and the All Dominating Neighbors problem In the divide-and-conquer technique a problem is divided into independent subproblems which are solved recursively. The solution to the problem is obtained from the solutions to its subproblems. In parallel implementations of this technique, we solve the subproblems in parallel. There are two aspects in which this technique is related to tree constructions. First, it can be used for constructing certain types of trees (for example the visibility tree discussed later in this chapter). Second, this technique can be naturally visualized with the help of a tree. Namely, we can represent the recursive partition of the problem with the help of a tree T such that every internal node of T corresponds to one subproblem, and its children correspond to the partition of the subproblem associated with the given node into further subproblems. To solve a problem one has to compute solutions to all subproblems in a bottom up fashion. This computation can be implemented by performing h iterations (where h is the height of the tree) such that at the i * iteration we Chapter 2: Basic techniques for design of parallel algorithms page 41 compute the solutions to the problems defined by the internal nodes which are on level h-i+1 of the tree T. In particular, if T has height |~log nl then such an implementation requires Q(log n) time and Q(«) processors (and therefore Q(nlog n) total work), even if the problem admits a linear time sequential algorithm. The usual way of dealing with this problem is to reduce the number of processors using Brent's scheduling principle, or to apply a sequential algorithm for the subproblems of logarithmic size (i.e. subproblems associated with internal nodes from level Tloglog n\) and a parallel algorithm for all other subproblems. A natural generalization of the latter approach is to divide the computation into a finite number of phases such that at each phase we compute, using different algorithms, solutions to the problems associated with internal nodes from a certain range of levels. In this chapter we present such a 3-phase algorithm which leads to an optimal solution for the following problem: given a sequence of real numbers find, for every element x in the sequence, the dominating neighbors of x, that is, the closest predecessor and successor of x which are at least as large as x. We refer to this problem as to the All Dominating Ufiighbors (ADN) problem. This problem is a natural generalization of list merging (simply concatenate one list in descending order and the other in ascending order and solve the problem for the merged list), and appears to have a number of interesting applications. The A D N problem has a natural geometric interpretation which we describe in the next section. An optimal algorithm for the A D N problem leads to simple optimal algorithms for the following problems: triangulation of monotone polygons [BrSchVis88], all closest neighbors problem for a convex polygon [SchVis88], triangulation of a sorted point set, and computing horizontal neighbors for vertices of a (horizontally) monotone polygon. The solution to the A D N problem is also used as an important building block of our optimal algorithm to construct minimax trees which we present in Chapter 5. Merks [Mer86] considered a problem which can be easily translated to the A D N problem as a part of his algorithm for point set triangulation. Merks' algorithm runs in Chapter 2: Basic techniques for design of parallel algorithms page 42 0(log n ) time using n processors on a CREW PRAM. Subsequently, an optimal 0(log n)-time fl/log rt-processor CREW P R A M algorithm (as well as an 0(loglog n) time rc/loglog n-processors C R C W P R A M algorithm) for the A D N problem was proposed by Berkman, Breslauer, Galil, Schieber, and Vishkin [BeBrGalSchVis89]. We present here a different CREW P R A M algorithm which achieves the same complexity bounds. This algorithm illustrates the 3-phase divide-and-conquer strategy and is needed for completeness of the results in Chapter 5. Both the algorithm of Berkman et. al. and our algorithm reduce the problem to merging certain pairs of sorted sequences. We introduce a data structure called the visibility tree, which is exploited by our algorithm. A slight modification of our algorithm (including a slight modification of the visibility tree) leads to a simple optimal algorithm for computing horizontal visibility in a horizontally monotone polygon. 2.7.1. The A D N problem and the visibility tree Assume that we are given a set of points S in the plane such that no two points have the same x-coordinate. For a point (x,y)e S we define its left (resp., right) closest greater element as the element (x',y') e S such that y' > y, x' < x (resp., x' > x) and the distance lx-x'l is minimized (if such an element exist). Since the problem is at least as difficult as sorting the point set on their x-coordinates, we assume that elements of V are sorted by x-coordinate. Only the order of the elements is of importance (not the exact values of their x-coordinates) and therefore sorting reduces our initial problem to the following: Given a sequence yi, . . . ,y„ of reals, find for every element yjin the sequence, the dominating neighbors, that is, the closest predecessor and successor of yj greater than or equal to yv We refer to this problem as to the All Dominating Neighbors (ADN) problem. Chapter 2: Basic techniques for design of parallel algorithms page 43 Consider a graph theoretical chain (i.e. a connected graph all but two of whose vertices have degree two and the two remaining vertices have degree one). A planar embedding of such a chain is called a polygonal line. A polygonal line, C, is said to be monotone with respect to a straight line / if every line orthogonal to / intersects C in at most one point. If / is a horizontal line then C is said to be horizontally monotone. Assume that C is horizontally monotone (in particular, no two vertices have the same x-coordinate). There is a natural ordering of vertices of C, namely the ordering corresponding to the increasing order of x-coordinate. For any vertex v of a polygonal line C its horizontal neighbors are the points on the intersection of C with the horizontal line through v which are closest to v on both sides. It is easy to see that if C is a horizontally monotone polygonal line then the problem of finding horizontal neighbors can be reduced to two instances of the A D N problem. We now introduce basic notions whose properties are used by our parallel algorithm for the A D N problem. a) a right visibility sequence (bold) b) a left visibility sequence (bold) Figure 2.7. Visibility sequences Let V = v o , v 1 , . . . , v „ , v n + i where vi,... ,v n is a sequence of reals and vo=v n + 1 = co . For each i , l < i < « define dp(i) = max{j<il Vj> v,}(dominating predecessor) and ^(i)=min{j>il Vj> Vj} (dominating successor). A maximal subsequence Vj l v . . ,Vj r of a sequence Vi, . . . ,v i + k such that ij=i and ij+i = ds(ip (resp., ij_i = dp(ij)) is called the right (resp., the left) visibility sequence for the sequence Vi, . . . ,v i + k (see Figure 2.7). Note that Chapter 2: Basic techniques for design of parallel algorithms page 44 a right visibility sequence is a nondecreasing sequence and a left visibility sequence is a nonincreasing sequence. As an immediate consequence of the above definition we obtain: Lemma 2.13. Let Si=Vi,...,Vi+k and S2 = V j + k + i , . . . , V i + k + / . Let U^ui1,...,".,-1 be the right (resp., the left) visibility sequence for the sequence Si, and U2=ui2,...,ut2 be the right (resp. the left) visibility sequence for the sequence S2- Then the sequence u^ 1,...^, 1,^ 2,...^ 2 (resp., ui^.L.Uj^ui 2,...^ 2), where Uj 2 (resp., Uj 1) is the first element of U2 (resp., the last element of U^ ) which is greater than or equal to Uj.1 (resp., u i 2 ) is the right (resp., the left) visibility sequence for the sequence Vj , . . . v i + k , v i + k + 1 , . . . v i + k + / . As we have mentioned before, the ADN problem is a natural generalization of list merging. An optimal log n-time n/log n processor parallel algorithm for list merging was presented by Shiloach and Vishkin [ShiVis81], Like list merging, the ADN problem has a simple linear sequential solution. Consider, for example, the function ds. We process the elements of the sequence one after another. At stage i of the algorithm the elements which do not yet have the value ds computed and whose index is less than / are stored on a stack. The elements stored on the stack form a decreasing sequence. Initially the stack contains element vi. At stage i we process element vj. Note that i is equal to dsQ) for all elements Vj on the stack which are less than or equal to Vj. We remove these elements from the stack and put vj on the stack. Note that the elements stored on the stack at this stage of the algorithm form the left visibility sequence for the sequence Vi=vi,...,Vi_i. In our parallel algorithm visibility sequences are used in a different way. We divide the input sequence into two subsequences of approximately equal size, then each of them into two subsequences and so on. This recursive partition is represented by an almost balanced binary tree T such that elements of V are in the leaves of T and a node u of T is Chapter 2: Basic techniques for design of parallel algorithms page 45 associated with the subsequence of V spanned by the leaves of the subtree of T rooted at u. Let Si=Vj,...,Vj+]c be the sequence spanned by the leaves of the left child of u and s2 = vi+k+l'--'vi+k+/' b e m e sequence spanned by the leaves of the right child of u. Let Ui=uj^ ....Uj.1 be the left visibility sequence for the sequence sj, and U2=ui2,...,ut2 be the right visibility sequence for the sequence s2. Assume that u^  l<u^ (the case when u^>u^ is symmetric). Then the sequence ui2,...,Uj_i2 where Uj 2 is the first element of U 2 which is greater than or equal to uj 2 is called the right hidden sequence associated with node u and the sequence u21,...,ur1 is called the left hidden sequence associated with node u (see Figure 2.8). Tree T together with the visibility sequences and hidden sequences associated with every internal node is called the visibility tree. 2 a left hidden sequence a right hidden sequence Figure 2.8. Hidden sequences (bold) 2.7.2. A n optimal algorithm for the A D N problem Assume that we are given an input sequence V and its visibility tree. (We associate a visibility/hidden sequence with a node by giving pointers to the first and the last elements of the list). Note that every input element (except for the end elements) belongs to exactly one hidden sequence. Thus it suffices to compute dp(x) and ds(x) for all elements vx from a hidden sequence. In the following description we assume that vx belongs to the left hidden sequence associated with an internal node u (the case when v x belongs to the right hidden sequence is symmetric). In order to compute dp(x) it suffices to find the first Chapter 2: Basic techniques for design of parallel algorithms page 46 element in the left visibility sequence associated with the left child of u which is greater than or equal to v x. The value ds(x) is equal to the index of the first element of the right visibility sequence associated with the right child of u which is greater than v x . This element either belongs to the right hidden sequence associated with v or is equal to U j 2 (recall Figure 2.8). It can be decided in constant time which of the two cases holds. The only case which involves more than constant time per element is finding ds(x) in the case when it is one of the elements of the right hidden sequence associated with u (recall our assumption that v x belongs to a left hidden sequence). We find ds(x) for all elements to which this case applies with the help of a merging algorithm. We merge the right hidden sequence with the corresponding left hidden sequence in such a way that in the case of equality the elements from the right sequence follow the elements from the left sequence. Then for every element from the left sequence we search for the closest element from the right sequence following it. This reduces our problem to the problem of merging at most n pairs of sequences such that each pair is associated with one internal node of the visibility tree. The total number of elements in all such sequences is bounded by n. These merging problems can be batched into one merging problem of size n. To do this we number the internal nodes of the visibility tree, say in the postfix order (using for example the Euler tour technique described in section 2.4), and associate with each element in a right or left hidden sequence the sequential number equal to the number of the internal node with which the given sequence is associated. Then we concatenate left and right sequences separately in the order of the sequential numbers of their elements. This gives us two sequences each lexicographically sorted according to the triple (sequential number, value of the element, side) where side=left for elements from a left hidden sequence and side=right for the elements from a right hidden sequence. We define left<right and simply merge the sequence in 0(log n) time using rc/log n processors ([ShiVis81]). The third element of a triple ensures that in the case of equality the elements from a right sequence follow the elements from the corresponding left sequence. Chapter 2: Basic techniques for design of parallel algorithms page 47 It remains to show how to construct the visibility tree in 0(log n) time using n/log n processors. We construct the tree in bottom up fashion using Lemma 2.13. Let u be an internal node and let U i , U2, and U j 2 be defined as in the previous section (recall Figure 2.8.). Assume again that u i 1 < u t 2 (the case u^1 > u t 2 is symmetric). Then: - the right visibility sequence associated with u is the concatenation of the right visibility sequence of the left child of u and the sequence U j 2 , . . . , u t 2 ; - the left visibility sequence associated with u is equal to the left visibility sequence of its right child; - the left hidden sequence associated with u is U2 1 , . . . ,u r 1 ; - the right hidden sequence associated with u is u i 2 , . . . , ^ . ! 2 ; Thus the computation of the visibility and the hidden sequences for an internal node reduces to finding the vertex U j 2 . We assume in the description that > u t 2 ; the case u\l < u t 2 is symmetric. The algorithm is divided into three phases (the levels of tree nodes are numbered in the leaves-to-root order): PHASE 1: Computing sequences associated with internal nodes on levels 0 to floglog n\ Each of the rc/log n processors computes the sequences associated with internal nodes of one subtree rooted at an internal node from level Tloglog n~] using a sequential linear algorithm. During the remaining phases the visibility sequences are represented as follows: (i) Each sequence is subdivided into subsequences of size at most log n and each of them is represented by an array, (ii) Each subsequence is assigned to one processor and each processor is assigned to a constant number of subsequences. (iii) The processor assigned to a subsequence keeps the length of the subsequence, the address of the first element, and a pointer to the first (for the left visibility sequence) or Chapter 2: Basic techniques for design of parallel algorithms page 48 the last (for the right visibility sequence) subsequence of the sequence in its local memory. This representation can be computed during the first phase of the algorithm and then preserved through the rest of the algorithm in the following way: Assume that we compute a right visibility sequence for an internal node and assume that the element Uj 2 has been computed. Let b be the subsequence containing Uj 2. Then the new sequence contains all subsequences of the right visibility sequence of the left child, the part of the subsequence b containing all elements greater than or equal to Uj 2, and all subsequences of the right visibility sequence which follow b. We assign the processor previously associated with b to the part of the sequence b which is in the new visibility sequence. The rest of the processors are associated with the same subsequences as before. The information described in point (iii) can be updated for each subsequence in constant time. PHASE 2: Computing sequences for internal nodes on levels floglog nl+1 to 2floglog n\. We process the nodes on these levels in a bottom-up fashion. For every internal node v every processor associated with a subsequence of the right visibility sequence associated with the left child of u tests if u^1 lies between the first and the last element of the subsequence to which it is assigned. If so it applies a binary search algorithm to compute Uj 2. So the total amount of time spent in the second phase is 0((loglog ri)2). PHASE 3: Computing sequences internal nodes on levels 2Tloglog nl+1 to flog wl. We assign Llog n\ processors to each internal node on level 2Tloglog nl+1 and define these processors as special processors associated with the given internal node. The special processors for an internal node on a level greater than 2Tloglog nl+l are defined as the special processors of its right child. We perform Tlog nl-2Tloglog n\ parallel steps. As in the second phase, for every internal node u from the currently processed level, every processor associated with a subsequence of the right visibility sequence associated with the Chapter 2: Basic techniques for design of parallel algorithms page 49 left child of v tests whether uj 1 lies between the first and the last element of the subsequence it is assigned to. If so we assign the special processors assigned to u to the elements of this subsequence and find Uj 2 in one step taking constant time. Thus this phase of the algorithm can be implemented in 0(log n) time with n/log n processors. This gives a divide-and-conquer algorithm which provides an alternative proof of the following theorem: Theorem 2.14. [BeBrGalSchVis89]: The ADN problem can be solved in 0(log n) time using n/log n processors on a CREW PRAM. 2.7.3. Applications As we mentioned at the beginning of this chapter, an optimal algorithm for the ADN problem has a number of interesting applications. We present here two such applications. First we present a reduction of the All Stricdy Dominating Neighbors (ASDN) problem to the ADN problem. The solution to the ASDN is also used in our optimal algorithm to construct minimax trees presented in the next chapter. Then we present an optimal algorithm to compute horizontal visibility in a horizontally monotone polygon. Our algorithm uses a modified version of the visibility tree. 2.7.3.1. The All Strictly Dominating Neighbors (ASDN) problem We present a simple optimal algorithm which computes, for every element in an input sequence, the strictly dominating neighbors, that is, the closest predecessor and successor which are strictly greater than the given element (if such an elements exists). We refer to this problem as the All Strictly Dominating Neighbors (ASDN) problem. We show a simple solution to the ASDN problem which is based on the solution of the ADN problem. Consider, for example, the problem of computing for every element Vj of the input Chapter 2: Basic techniques for design of parallel algorithms page 50 sequence its strictly dominating successor (sds(i)). Let T be the forest formed by elements of the input sequence and pointers ds. For all elements Vj such that vi<v,jS(i) we set sds(i)=ds(i) and remove from T edges (i,ds(i)). This splits T into a number of lists of equal elements and with equal values of sds. The last element of each such list has its sds already computed. So the values of sds for the remaining elements can be found by an application of a list ranking algorithm ([AndMil88],[ColVis86]). 2.7.3.2. Computing horizontal neighbors for vertices of a monotone polygon A simple modification of the A D N algorithm presented in section 2.7.2 leads to an optimal algorithm for computing horizontal visibility (i.e. determining the horizontal neighbors of every point of a polygon) in a horizontally monotone polygon. Let P be a monotone polygon. Assume, without loss of generality, that it is decomposed into the upper polygonal line and the lower polygonal line, i.e. two polygonal lines monotone with respect to a horizontal line. Let Y= yi, . . . ,y„ be the sequence of y-coordinates of vertices of P listed in the order of increasing x-coordinate. (Note that given the two polygonal lines which comprise P one can compute Y in 0(log n) time with rc/log n processors by a merging algorithm). In order to find for any vertex v its horizontal neighbors it suffices to find the edges of the polygon which contain those neighbors. Our algorithm to find horizontal neighbors is based on the same idea as the algorithm to solve the A D N problem described in section 2.7.2. We also build a visibility tree (with leaves labelled by elements of Y) and find horizontal neighbors by merging hidden sequences. However the visibility information stored in the internal nodes of the visibility tree is more complex. This only leads to difficulties of a technical nature which, as one will easily observe, can be solved by considering a number of simple cases. Chapter 2: Basic techniques for design of parallel algorithms page 51 Let S be a set of edges. A point p from an edge e of S is called left (resp., right) horizontally visible in S if there exists a horizontal line through p such that e is the first (resp., the last) edge cut by this line. An edge which contains a point which is left (resp., right) horizontally visible in S is said to be a left (resp., right) horizontally visible edge. Let T be an almost balanced binary tree with leaves labelled in left to right order by elements of Y and let v be an internal node of T. Let E v be the set of edges with at least one endpoint belonging to the set of vertices spanned by the leaves of the subtree of T rooted at v. We associate with each such node v, its left and right visibility information which consists of two, possible empty, parts : (i) the subset of edges from E v which belong to the upper polygonal line and are horizontally visible in E v ; (ii) the subset of edges from E v which belong to the lower polygonal line and are horizontally visible in E v . It is not difficult to see that the computation of the visibility information of an internal node from the visibility information of its children can be carried out using the same method as used for the A D N problem, with an additional constant factor in the time complexity. In a natural way we associate with each internal node at most three pairs of hidden sequences. (The three general cases are presented in Figure 2.9.) Hidden sequences can be computed using a method similar to the method described in section 2.7.2 for the A D N problem with only additional constant factor in the time complexity. As in the case of the A D N problem, every vertex of the polygon belongs to exactly one hidden sequence. Given a vertex in a hidden sequence we can find its horizontal neighbors using a method similar to the method described in section 2.7.2. Thus we reduce the problem to merging of 0(n) sequences of total length equal to n. As we have pointed out in the previous section this can be done in Q(log n) time with n/log n CREW processors. techniques for design of parallel algorithms page 52 the first pair of hidden sequences the second pair of hidden sequences the first pair of hidden sequences the second pair of hidden sequences the third pair of hidden sequences the first pair of hidden sequences the second pair of hidden sequences the third pair of hidden sequences Figure 2.9. Hidden sequences (bold lines) Chapter 2: Basic techniques for design of parallel algorithms page 53 2.8. Summary This chapter introduced general parallel techniques and algorithms which support our tree construction techniques. In Sections 2.1 trough 2.4, we described well-known parallel techniques: Brent's scheduling principle, list ranking, and the Euler Tour technique. In Section 2.5, we discussed the tree contraction technique. The simple tree contraction algorithm presented in this section is joint work by Abrahamson, Dadoun, Kirkpatrick, and Przytycka [AbrDadKirPrzy87]. This work, together with other results ([ColVis86c], [GibRyt86], [KosDel88], [He86a], [MilTen87], [GibRyt88]) provides a step towards a simplification and a formalization of the tree contraction technique introduced by Miller and Reif [MilRei85] and independently by Rytter [Ryt85]. In Sections 2.5.2 and 2.5.3, we introduced (based on [AbrDadKirPrzy87], [He86a], and [MilTen87]) the Bottom-up and Top-down Algebraic Tree Computation algorithmic schemes. In example 2.7, we showed a nontrivial interpretation of the scheme. In that example, we presented an algorithm to compute a certain tree labelling which is used later in Chapter 5. In our solution we made an essential use of all components provided by our 1ft_Cl cTG scheme: functions associated with internal nodes, functions associated with edges, and nontrivial indexing of these functions. In Section 2.6, we introduced the cascading sampling technique. The technique can support parallel algorithms based on a sequence of merging steps. As we pointed out the technique is loosely related to the cascade merging paradigm introduced by Cole [C0I86] and generalized by Atallah, Cole, and Goodrich [AtaColGoo89]. This technique is used in Chapter 4 of the thesis to obtain one of the basic results of this chapter. Finally, Section 2.7, was devoted to the parallel divide and conquer technique and to an optimal parallel algorithm for the Al l Dominating Neighbors (ADN) problem. The Chapter 2: Basic techniques for design of parallel algorithms page 54 solution to this problem is used in Chapter 5. The first optimal algorithm to solve the A D N problem was presented by Berkman et. al. ([BeBrGalSchVis89]). In Section 2.7, we presented an alternative solution based on a divide and conquer strategy. Often one can naturally parallelize a sequential divide and conquer algorithm. Thus, finding a divide and conquer algorithm for a given problem can be an important step towards the design of an efficient parallel algorithm for the problem. To obtain an optimal parallel algorithm the divide and conquer strategy has to be usually supported with other parallel techniques (e.g. Brent's principle, cascading divide and conquer [AtaColGoo87], multi-way divide-and-conquer [Goo87]). In order to obtain an optimal solution to our problem we used an interesting 3-phase divide-and-conquer strategy. Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 55 CHAPTER 3: PARALLEL TREE EXPANSION -CONSTRUCTION OF TREE REPRESENTATION FOR COGRAPHS In this chapter we present the parallel tree expansion technique and its application to the design of a parallel algorithm to construct a tree representation for graphs belonging to the family known as cographs. In the parallel tree expansion technique we construct a tree starting from a single node by the iterative addition of sets of vertices of degree one (leaves) or two (subdividing edges). The method is closely related to parallel tree contraction described in Section 2.5. Let Tj be the-tree obtained in the i * iteration. We say that Tj is an expansion of Tu. Let N be the number of steps used to construct the tree. Note that the sequence TN,TN-I. . . ,TO is a tree contraction sequence. In this sense the tree expansion can be viewed as the reverse of the tree contraction method. We generalize further the tree expansion technique by replacing nodes and/or edges by connected subtrees. It is well known that many problems on graphs are NP-hard [GarJoh79], however these problems can often be computed efficiently for some restricted families of graphs. It is often the case that graphs belonging to such families can be represented with the help of a tree. Such a tree representation may follow (for example for cographs and series parallel graphs) from a natural recursive definition of the graphs in the family. A different idea lies behind the tree representation for the graphs from the family of graphs known as chordal Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 56 graphs. A chordal graph (i.e. a graph without chordless cycles) can be represented with the help of the clique tree. The nodes of the clique tree are in one-to-one correspondence with the maximal cliques of the corresponding graph, and for every vertex in the graph the maximal cliques containing the given vertex form a connected subtree in the clique tree. An interesting subfamily of the family of chordal graphs is provided by k-trees. A k-tree is a graph which can be recursively constructed from a k-complete graph by adding new vertices such that each new vertex is adjacent to all vertices of an existing k-complete subgraph. A partial k-tree is a graph embeddable in a k-tree with the same vertex set. Obviously, trees are 1-trees. Series parallel graphs are partial 2-trees. Observe that the recursive definition of k-trees defines a tree structure on graphs from this family. Given a tree representation of a graph, we may use parallel tree computation techniques (for example the tree contraction) to efficiently compute some graph properties which seem to be very difficult to compute for general graphs. This motivates the problem of designing efficient parallel algorithms to recognize membership in the given class and to construct the corresponding parse tree. He [He86b] solved this problem for the class of two terminal series parallel graphs (TTSP graphs). His algorithm constructs a binary decomposition tree if a given graph is a TTSP graph. Given a multigraph with n vertices and m edges the algorithm runs on a CRCW P R A M in 0 ( l o g 2 « + log m) parallel time using 0(n+m) processors. Naor, Naor and Shaffer [NaoNaoSc87] proposed parallel algorithms to construct a clique tree representation for chordal graphs and for computing properties of chordal graphs using this representation1. Rytter and Szymacha [RytSzy89] presented an NC algorithm for the recognition and construction of a parse tree for graphs which can be generated recursively using a context-free grammar. They also proposed 1 Parallel algorithms for chordal graphs ware also discussed by Edenbrant ([Ede87]) and Dahlhaus and Karpinski ([DahKa86], [DahKa87]). Currently the best performance achieve the algorithms presented by Klein ([Kle89]). Dahlhaus and Karpinski ([DahKa89]) also addressed a related problem of computing Minimal Elimination Order for an arbitrary graph. Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 57 parallel algorithms for such problems as edge coloring, vertex coloring, and hamiltonian cycle, which take the parse tree as the input. A parallel algorithm for the construction of cograph tree representation described below was first proposed by Kirkpatrick and Przytycka [KirPrz87]. This algorithm serves here as an illustration of the parallel tree expansion method. The algorithm runs in 0(log2n) parallel time using 0 ( n 3 / l o g 2 « ) processors on a CREW PRAM, where n is the number of vertices. In the next four sections we outline an implementation using 0 ( « 3 / i o g «) processors. Section 3.7 describes the reduction to 0(n3/log2n) processors. Independently, several other algorithms have been proposed for this problem ([Shy88], [Nov89], [AdhPen89]). Each of the algorithms uses a different method and performs a construction using time and processors resources which are comparable to those used by our algorithm.2 Przytycka and Corneil [PrzCor89] presented an algorithm for the recognition of parity graphs which can be easily converted to an algorithm which produces a parse tree for graphs from this family. We sketch this algorithm in section 3.7. 3.1. Definitions and basic properties A complement reducible graph, also called a cograph, is defined recursively in the following way: (i) A graph on a single vertex is a cograph; (ii) If G j , G 2 are cographs, then so is their union ; and (iii) If G is a cograph, then so is its complement. Cographs are easily seen to satisfy the following property (cf. [CorLerSte81]): ^Recently Novick [Nov90a] claimed to be able to reduce the processor cost to 0(n2). Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 58 Property 3.1. An induced subgraph of a cograph is a cograph. Cographs are precisely the class of graphs which do not contain P 4 as an induced subgraph ( P4 is a path of four vertices). This characterization suggests a simple parallel algorithm for the recognition of cographs that operates in O(l) time using 0 ( « 4 ) CRCW processors. Such an algorithm, however, will not necessarily reveal the simple recursive structure that is imposed by the cograph definition and exploited in many cograph algorithms. Cographs were first introduced and studied by Lerch in [Ler71],[Ler72]. As a family of graphs, cographs have arisen independently in connection with several different mathematical problems. In the work of Sumner [Sum74], motivated by empirical logic, cographs are defined as Hereditary Dacey graphs (HD-graphs). In Burlet and Uhry [BurUhr84], cographs are referred to as 2-parity graphs and are related to a broader class of graphs called parity graphs. A family of graphs equivalent to cographs is also defined by Jung in [Jun74] and called D*-graphs. In this same paper is shown that D*-graphs are equivalent to comparability graphs of multitrees. Corneil, Lerch and Stewart [CorLerSte81] show that cographs are the underlying graphs of the family of digraphs known as transitive series parallel graphs. For more information about cographs (including various equivalent characterizations) see [CorLerSte81]. The definition of a cograph suggests a natural parse tree representation. However this way of presenting a cograph may not be unique. A unique representation is provided by the so-called cotree [CorLerSte81]. A cotree, T Q , is the tree presenting the parsing structure of a cograph G in the following way : - The leaves of T Q are the vertices of G. Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 59 - The internal nodes of T Q represent the operation complement-union (that is, the graph associated with an internal node is the complement of the union of the graphs associated with its descendent nodes). - Each internal node except possibly the root has two or more children. The root has a single child if and only if the graph is disconnected. This representation can be constructed in 0(n+m) sequential time (including testing if the given graph is a cograph) [CorPerSte85]. The cotree representation is used in the formulation of linear algorithms for determining the maximum independent set, chromatic number, graph isomorphism, number of cliques and other properties of cographs (see [CorLerSte81]). Abrahamson, Dadoun, Kirkpatrick and Przytycka [AbrDadKirPrz87] and Adhar and Peng [AdhPen89] present N C algorithms for a number of such problems. These algorithms also make use of the cotree representation of cographs. In order to simplify the description of algorithms which use the cotree representation of a cograph, each node x of a cotree T is assigned a label, label(x), in the following way: - label(root) = 1; and - if y is a child of x then label(y) = 1 - label(x). Figure 3.1 illustrates a cograph G and its labelled cotree T Q . The labelling of a node x records the parity of the number of complement-union operations on the path between x and the root. To minimize confusion, we talk about vertices when we refer to a graph and about nodes when we refer to a cotree. The nodes of a cotree labelled by 0 are called 0-nodes and those labelled by 1 are called 1-nodes. We also use the following notation: n denotes the number of vertices in G, T v denotes the set of neighbors of the vertex v in G, and lcax(vi,V2) denotes the lowest Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 60 common ancestor of nodes vi and V2 in the tree T (the subscripts G and T are omitted if it is obvious to which graph or tree we refer). G: b c Figure 3.1. A cograph and its cotree It is easy to confirm that: Property 3.2. Two vertices u and v in a cograph G are adjacent iff in the cotree T defining G, the lcax(w,v) is a 1-node. To ensure readability of our figures we use the following notation: A A Arbitrary subtree (possibly empty except for the root) Nonempty subtree Figure 3.2. Notation concerning subtrees 3.2. Bunches and lines in a cotree In this section we study properties of cotrees which are interesting and useful for parallel computation. In particular, we examine how the relative position of a given node in Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 61 the cotree can be determined from information about the neighborhood of the corresponding vertex in the associated cograph. We introduce notions of bunches and lines which describe collections of vertices in a cograph. These are used by our algorithm as basic building blocks for cotrees. Define the following relations between vertices of a graph G: (1) SO(M,V) <=> T v - {u} = T u - {v} and u,v are not adjacent, (2) SI(M,V) <=> r v - {u} = T u - {v} and u,v are adjacent, (3) Zo(v,«,w) <=> (i) T v © T u = [u} , where © denotes the symmetric difference (ii) r u - v * T v - u , and (iii) w is not adjacent to either of v or to u, (4) Z I O M M V ) <=* ( i ) r v © r w = (ii) r v - v ^ T u - u , and (iii) w is adjacent to both v and u. The vertices satisfying relation Sj (i = 0,1) are called siblings. The vertices satisfying So are called weak siblings and the vertices satisfying S i are called strong siblings. The following theorem [CorLerSte81] provides another characterization of cographs: Theorem 3.3. G is a cograph if and only if any nontrivial induced subgraph of G has at least one pair of siblings. Lemma 3.4. Two leaf nodes vi and v2 have the same parent in the cotree T Q iff the corresponding vertices vi and v2 are siblings in G. Proof : (=>) Assume that vi and v2 have the same parent in the cotree T. Note that for any vertex v such that v # vi and v #v2 , lca(v,vi) = lca(v,v2). Hence, by Property 3.2, any vertex adjacent to vi is adjacent to v2 and TV 1 - {v2} = TV2 - {v\}. Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 62 (<= ) Assume that v i , V2 have different parents. Let v = lca(vi,V2). At least one of the paths from v to v,- (i = 1,2) in cotree T is longer than one. Assume w.l.o.g. that the path from v to vj is longer then one. We can find an internal node u on this path which has a label different from v. Thus, there exists a node w (w # vi and w & V2) such that lca(w,vi) = u and lca(w,V2) = v. But this means that w is connected to exactly one of vi, V2 , so neither So(vi,V2) nor Si(vi,V2) holds.B A maximal set of weak siblings is called a 0-bunch set and a maximal set of strong siblings is called a 1-bunch set. A smallest connected subgraph of the cotree T containing a 0-bunch set is called a 0-bunch and a smallest connected subgraph of the cotree containing a 1-bunch set is called a 1-bunch (see Figure 3.3). The vertex with the smallest index among the vertices in a bunch set is called the representative of this set. (0) (i) 0-bunch 1-bunch Figure 3.3. A 0-bunch and a 1-bunch If we replace a bunch set in a cograph G by its representative, say v, then, by Property 3.1, the graph G' = (V',E') obtained in such a way is also a cograph. Consider the following construction of a tree T' from the tree T: (1) If vertices in the bunch set are the only children of some internal node then substitute the representative of the bunch set for the bunch to which they belong (see Figure 3.4a)). Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 63 (2) If the vertices in the bunch set are not the only children of some internal node then remove from T all vertices in this set except for the representative (see Figure 3.4b)). V Figure 3.4. Replacing a bunch by its representative Note: The labels of the bunch set's representative and its parent are different ensuring that this substitution is reversible. Lemma 3.5. The tree T' obtained from the tree T in the way described above is the cotree of the cograph G'. Proof: Note that for u,w e V'-{v}, label(lcax(«,w)) = label(lcaT'(M,w)). Also label(lcaT(«,v)) = label (lcar(M,v)). So, by the definition of G' and Property 3.2, the tree T' is the cotree of G'. • The vertices in relation Zj (i = 0,1) also occupy special positions in the cotree. They are specified by the following lemma: Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 64 L e m m a 3.6: The relation Zo(v, u,w) holds iff v,u, and w are positioned in the cotree as illustrated in Figure 3.5a. Similarly, the relation Z.\(v,u,w) holds iff v,u, and w are positioned in the cotree as illustrated in Figure 3.5b. Figure 3.5. Relations Zn(v,w,vv) and Z\(v,u,w) Proof: We will prove the lemma for the relation Zn only. The proof for the relation Zj is similar. (<=) Assume that v,u, and w are positioned as illustrated in Figure 3.5a. By Property 3.2, v and w have no neighbors in Ti. Assume f ^ Ti and t & v,u,w then lca(v,?) = lca(w,f) and (i) follows. As immediate consequences of the cotree definition we have (ii) and (iii). (=>) From (i) and (iii) we have that v and w are not adjacent, v and u are adjacent, u and w are not adjacent. This implies the position of the nodes as in Figure 3.6a. From (i) we know that there are no nodes between a and b, u and a , w and b, and from (ii) we have additionally T v T u. This implies the more restricted position of the nodes shown in Figure 3.6b. Finally, point (i) restricts us to the positions shown in Figure 3.5a. • Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 65 (0). W V u a) b) Figure 3.6. Restricting of the possible positions of nodes v,u,w satisfying Zo(v,u,w) A vertex u for which there exist vertices v,w such that Zo(v,u,w) or Zi(v,«,w) is called a contractible vertex. The corresponding leaf in a cotree is a contractible leaf. If a node has a contractible leaf as a child then it has exactly two children, one of them being a leaf and the other being a nonleaf. A contractible sequence is a maximal sequence of distinct vertices (leaves in the cotree) ui,U2,...,Uk such that there exist two vertices v,w for which Z[(v,ui,U2), Zi-i(w/,W2,M?), Zi(M£_7,M£,w) a l l hold, and there does not exist an x such that Z\-i(x,v,ui) holds. Define a branching node as an internal node having more than two children or having more than one leaf as a child. Note that any nonbranching node appears in the cotree as node v in Figure 3.7. Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 66 Figure 3.7. A nonbranching node A smallest connected induced subgraph of a cotree containing a contractible sequence is called a line . A line is a 0-line if the lowest level internal node is a 0-node and a 1-line otherwise. By Lemma 3.6, lines have the form presented in Figure 3.8. The set of vertices associated with a 0-line is called a 0-line set and the set of vertices associated with a 1-line is called a 1 -line set. The leaf which has a lowest level in the cotree among other vertices in a line (i.e. vertex v; in Figure 3.8) is called the representative of the given line set. (0) (i) i l a) 0-line b) 1-line Figure 3.8. A 0-line and a 1-line Let G' be the cograph obtained from G by replacing a line set by its representative. Let T' be the tree obtained by removing from T all elements of a line set and their parents except the representative and its parent. The parent of the representative takes as its new parent the (former) parent of the highest level vertex in the line set (see Figure 3.9). Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 67 Figure 3.9. Replacing a line by its representative Lemma 3.7. The tree T' obtained from the tree T in the way described above is the cotree of the cograph G'. Proof: Similar to the proof of the Lemma 3.5. • As an example, in Figure 3.10, af and g are branching nodes, {v\,V2,a} and {v8,V9,g} induce 0-bunches and {v^,V4,V5,b,c,d} induces a 1-line. The vertex vi is the representative for the first bunch and the vertex vg for the second. The vertex V3 is the representative for the line. Note that in this example all line sets and bunch sets are disjoint. This is true in general as formalized by the following lemma: Lemma 3.8. Let each of U,W be a line set or a bunch set. If U * W then UnW = 0. Proof : By Lemmas 3.4 and 3.6, an element of a bunch set cannot belong to a line set. Note also that Si(w,«) and Sj(u/v) implies i = j and Si(v,«), so an element of a 0-bunch set cannot belong to a 1-bunch set. If U and W are both line sets or both bunch sets then U n W * 0 contradicts the maximality of U and W. • Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 68 3.3. A top level descript ion of the cotree construct ion a lgor i thm We will assume that the input graph is connected. If it is not we can run a parallel algorithm for finding connected components ([HirChaSaw79]) and join the cotrees obtained for each connected component according to the cotree definition. Let the input graph be Go = (Vo,Eo). Assume for now that Go is a cograph and denote its cotree by To. The idea is to partition the set of vertices into subsets, remove from each subset all but one vertex (its representative), and reduce the problem to constructing the cotree for the graph induced on the diminished vertex set. Repeating this step, we obtain a sequence of graphs Go = (Vo,Eo), G i = (Vi,Ei) Gk = (Vk,Ek), such that Vi is obtained from Vj . i by performing a partition of Vi and then removing all but one vertex in each set of the partition. The sequence should have the property that the cotree T[.\ for Gi-i can be constructed easily as an expansion of the cotree Ti for Gi. A natural approach is to partition Vj into bunch sets. Unfortunately, the length of the sequence of graphs which Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 69 is constructed in this way is proportional to the length of the longest path in the cotree To which may be proportional to IVol if To is unbalanced. This is the reason why line sets must also be considered. By Lemma 3.8, the set of vertices of a cograph can be partitioned into 0-bunch sets, 1-bunch sets, 0-line sets, 1-line sets and single vertex sets. For any set U from a partition, we can consider the smallest connected subtree of the cotree T which contains elements of this set as leaves. This subtree will be called the fragment ofT induced by U. Note that in the proposed partition the only possible fragments are bunches, lines or single vertices. The algorithm proceeds in stages. In stage i, it produces a triple (Gi,Ui,Fi) such that the sequence of triples produced by the algorithm satisfy the following conditions : (i) The first element of the sequence is the triple (Go,{ {v},ve Vo},{Vo}), (ii) Uj ={LTi1,....,Uit} is a partition of V j - i , (iii) Vj+i = {ui1,...,^1} where up is the representative of Uy, (vi) Gi=(Vi,Ei) is the subgraph induced by V i , (v) Fj = {Fi1,..., Fi1} where Fp is the fragment of Ti-i induced by Up, (vi) The last element in the sequence is the first triple (GfcUioFk) for which lUkl = 1. Note that the cotree T k is just the only fragment in F k . For i = k,...,l, we construct cotree T u from cotree T[. We define the operation reduce which i) partitions the vertex set into bunch sets, line sets and single vertex sets, ii) finds representatives for those sets, iii) constructs corresponding fragments, and iv) constructs the graph induced by representatives of the partition. In the next section we show how to implement this operation in polylogarithmic parallel time. In section 3.6, we outline an algorithm for constructing the adjacency matrix of a cograph from its cotree representation. In the remaining part of this section we show Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 70 that the length of the sequence (Go,Fo,Uo),...,(Gk,Fk,Uk) constructed using the reduce operation is 0(log n) and that having this sequence we can construct the cotree To in polylogarithmic parallel time. Consider a leaf u of the cotree T[. Let r denote a label. Let u be the representative of a set U in the partition Uj. The following diagram summarizes the substitutions of fragments for representatives (sometimes together with its parent) in the tree Tj to obtain the tree Tj-i. Their validity follows from Lemmas 3.5 and 3.7. type of set represented by u associated fragment position of u in the cotree T-position of the fragment in the cotree T ^ single vertex set . u r-bunch set (r) / N Vj v 2 -.. vk 7 u n v 2 . . . . v k u / K n v2 .... v k r-line set X u (r) y \ k Figure 3.11. Substitution of fragments for corresponding representatives To prove that the length of the sequence is 0(log n), we note that the operation reduce satisfies the following properties: Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 71 Property 3.9. Consider the set B of vertices in the graph (i.e. leaves in the cotree) which are in bunch sets of the partition. After a single application of the reduce operation at most [ IBI/2 J of these vertices remain. Property 3.10. Let the partition have k line sets. Consider the set L of vertices in the graph which are in line sets of the partition. After a single application of the reduce operation exactly k of these vertices remain. These properties imply the following theorem : Theorem 3.11. After Wog^/iQn] applications of the reduce operation a cograph is reduced to a single vertex. Proof : It suffices to show that a single application of the operation reduce removes at least 1/10 of the current leaves. Suppose that the operation reduce is applied to a cograph with t vertices. Let B be the set of vertices in the cograph which are in bunch sets of the partition. Consider the following cases : (1) IBI > 115. Then, considering only leaves removed from bunch sets of the partition, the number of vertices left is less than or equal to t - IBI + IBI/2 = t - IBI/2 < 9/101. (2) IBI < 115. Let k be the number of branching nodes in the cotree. Notice that k < IBI -1 and the number of contractible sequences is at most k. Add the root to the set of branching nodes. With each branching node (except the root) we can associate a path of internal nodes in such a way that the first node, say v, is a branching node and the last node is the closest ancestor of v whose parent is a branching node. For every such path there are at most four leaves which are children of nodes in the path and are not contractible leaves (see Figure 3.12 for the worst case configuration). So after a reduce operation the number of leaves which are left is at most IBI/2 + 4k + 1 < 9/2 IBI -3 < 9/101. m Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 72 Figure 3.12. The worst case configuration for case (2) The algorithm outlined above is based on the assumption that the given graph was a cograph. It can be modified to work without this assumption as follows: (* construct the sequence of triples (Gi,Ui,Fi) *) M := riog9/10nl i :=0; U 0:={ {vjtJIvjteVJ; for 1 < k < n d o F 0 k = {v£}; while lUil > 1 and i < M do in parallel i :=i+ 1; (* construct the next triple (Gi,Ui,Fi) *) reduce; - see section 3.4 for details od; if i > M then the input graph is not a cograph; else (* construct the cotree *) Tj := Fi 1 ; (* there is only one fragment in Ft *) while i>0 do in parallel i :=i - 1; obtain Ti by substituting for each representative of the partition Ui+i the corresponding fragment from Fj+i od (* check if correct *) Construct the cograph G' defined by cotree To; — see section 3.5 for details if G V G Q then the input graph is not a cograph. Chapter 3 : Parallel tree expansion-construction of tree representation for cographs page 73 3.4. Implementation of the reduce operation The reduce operation is used to partition the vertices of a graph into bunch sets, line sets and single vertices. It also identifies representatives of those sets and constructs corresponding fragments. We describe this operation in two phases. In the first phase, we define the main steps of the operation. In the second phase, we describe the implementation of those steps. We also note when to check conditions which might disqualify the input graph as a cograph. Some of the technical details of the implementation are left to the reader. The reduce operation proceeds as follows : 1. For each pair of vertices v,w, check if v and w are siblings. 2. Find bunch sets, their representatives and construct corresponding bunches. 3. For each pair of vertices v,w, check for a vertex u such that Z\(v,u,w) (i=0,l). Such a vertex u is a contractible vertex. If there exists a vertex x such that Z\.\(u,w,x) then u,w are successive contractible vertices. 4. Find line sets, their representatives and construct corresponding lines. 5. Obtain Gi+i by removing from Gi all vertices not chosen as representatives. A more detailed description of the implementation follows: STEP 1. For each pair of vertices v.w. check if v and w are siblings. This step can be implemented in 0(log n) time with «3/log n processors. For each pair of vertices v,w compute the exclusive or of columns v and w of the adjacency matrix excluding rows v and w and then sum the elements of the resulting vector. This can be done for every such pair of vertices in 0(log n) time with n/log n processors using the prefix sum computation technique. Store the results of this step in an n xn array A by assigning A(v,w) = 1 if the resulting sum is zero (i.e. v and w are siblings) and A(v,w) = Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 74 0 otherwise. If there exist no sibling vertices (this can be checked in 0(log n) parallel time) then the graph is not a cograph. STEP 2. Find bunch sets, their representatives and construct corresponding bunches. Using the pointer hopping technique and the array A, each vertex can determine the vertex with the smallest index among its siblings. This can be done in 0(log n) time with 0(«2/log n) processors. The unique vertex whose index is smaller than the index of its lowest indexed sibling is the representative of its bunch. The processor associated with this vertex determines its bunch-type (0-bunch or 1-bunch) and builds the parent node of the bunch. Al l the vertices in the bunch set construct pointers to the bunch parent ( whose address is known via the representative which is known to all the vertices in the bunch set). To allow the construction of the cotree a new copy of the representative is constructed along with a pointer to its associated bunch. This copy participates in the next iteration. STEP 3. Find successive contractible vertices. The implementation of this step is similar to that of step 1 but in this case if the corresponding prefix sum computation produces 1 then the position at which the difference occurs indicates the vertex u. Note that the relation T u * T v has been checked in the previous step and that condition iii) can be checked in constant time. First, check for the relation ZQ. Store the result in the array A by assigning A(v,w) = u iff ZQ(V,U,W) and A(v,w) = 0 if otherwise. It is possible for A(v,w) = A(v',w') = u * 0. However, if the graph is a cograph then if A(v,w) = u * 0 and A(v,w') = u ' * 0 then u = u'. For each vertex u , it can be determined if u is an entry of A and, if so, a pair (v,w) can be chosen such that A(v,w) = u. (This can be done in 0(log n) time using a total of 0(«2/log n) processors by exploiting the structure of A). If the pair (v,w ) is chosen for vertex u then this is recorded in vector BQ by setting BQ(V) = u and Bo(w) = w. Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 75 In a similar way, we can check for the relation Z\. If for vertex u the pair (v,w ) satisfying Z\(v,u,w) is chosen, then it is recorded in vector Bi by setting Bi(v) = u and B\(u) = w. STEP 4. Find line sets, their representatives and construct corresponding lines. Note that uj,U2 are two successive contractible vertices iff there exist vertices v and w such that Bj(v) = uj , B[(ui) = U2 , = U2 and Bi-i(«2) = w. This follows from the fact that: Bj(v) = uj , Bi(«7) = «2 => Zi(v,ui,U2) and B i _ i ( M i ) = «2, Bi_i(M2) = w => Z\.\(ui,U2,w)-Thus we can construct a table B such that B(uj) = U2 iff uj and U2 are two successive contractible vertices. From this we can construct the corresponding contractible sequence. This step can be implemented in 0(log n) time with 0(n2/logn) processors using standard pointer hopping techniques. As in the case of a bunch, we construct copies of representatives. Each copy keeps pointers to the beginning and to the end of its associated line. Summarizing the discussion above, we have the following lemma: Lemma 3.12. If the input graph is a cograph then we can construct its cotree in 0(log2n) parallel time, using 0(n /^log n) processors. 3.5. Adjacency matrix construction from the cotree representation of a cograph The algorithm to construct the adjacency matrix [AhoHopU1174] from the cotree representation of a cograph is based on Property 3.2 and is an interpretation of the <T-Cl tT G algorithmic scheme. Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 76 Replace the cotree T by a binary tree T such that newly introduced internal nodes have the same label as the node whose split led to the given node (see Figure 3.13). T: (l) T' e Figure 3.13. Converting a cotree to a binary tree To construct the i-th row of the adjacency matrix we apply the instance of <T—Cl <T"G algorithmic scheme where 9 = {id, zero, one I id(x)=x; zero(x)=0; one(x)=l} and the input tree is the tree T with the labelling of the edges in which an edge is labelled by the constant function equal to the label of its parent vertex if the parent vertex is marked, and the identity function otherwise. After the computation defined by this <T-Cl <TG, the value computed in a leaf j (j * i) is equal to one iff i and j are adjacent in the cograph represented by T. It is easy to confirm that 9 satisfies the decomposability axioms (i)-(ii) of cT-Cl cTtj, so by Theorem 2.8 the i-th row of the adjacency matrix can be constructed in 0(log n) time with n/log n processors. To construct the entire adjacency matrix, 0 ( « 2 / l o g n) processors are used to implement this procedure for all rows in parallel. The construction above, together with Lemma 3.13, implies the following lemma: Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 77 Lemma 3.13. We can test if an arbitrary input graph is a cograph and, if so, construct its cotree in 0(log2n) parallel time, using 0(« 3 / log n) processors. 3 . 6 . Reduction of the processor requirements In this section, we describe a general technique which can be used to reduce the number of processors used by a CREW PRAM algorithm which computes entries of some vector and satisfies some properties stated in the following lemma. This idea is a minor generalization of a processor allocation technique used by Vishkin in [Vis84]. Lemma 3.14. Let v and w be -^vectors and let Alg be an algorithm consisting of M = O(logn) parallel phases, where (i) in each phase Alg updates entries v[j], for all j satisfying w[j] ^ 0, and (ii) Alg sets some fixed fraction c> 0 of the non-zero entries of w to zero. Suppose that each entry of v can be independently updated in t(n) time using p(n) processors. Then Alg can be implemented to run in 0((rfn/)+loglog «)log n) time using 0(p(n) rt/log n) CREW processors. Proof: An implementation using 0(r(nJlog n) time and 0(p(n)n) processors is obvious. To achieve the desired processor reduction, it is helpful to introduce a variable b which gives the number of non-zero elements of w and an array C whose ith value, for 1 < i < b, gives the index of the ith non-zero element of w. With the help of C, it is straightforward to implement one phase of Alg in 0(t(n)\b(\og n)/«l)time using 0(p(n) n/log n) processors. Now, C can be updated, following the update of w, in 0(log n) time using 0(n I log n) processors using standard parallel prefix techniques. Hence the first aloglogrc steps, where a = l/(log(l/(l-c))), can be implemented at a total cost of 0(t(n)+ log log n) time using 0(p(n)/n log n) processors. Thereafter, each step can be implemented in 0(t(n)) time Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 78 using 0(p(n) n/log n) processors by the straightforward implementation. Hence, the total cost is 0((r(,«j+loglog «)log n) time using 0(p(n) nflog n) CREW processors. • In our cotree construction algorithm, the most expensive operation is to compute relations Si and Zj. To compute these relations we compute the entries of array A. Note that the computations in each column of A are performed independently. Thus we can treat A as a vector of vectors and apply Lemma 3.14, assuming p(ri)=n2/log n, t(n) = log n and c = 9/10. This construction together with Lemma 3.13 gives the following: Theorem 3.15. We can test if an arbitrary input graph is a cograph and, if so, construct its cotree in 0(log 2«) parallel time, using 0(rc3/log2rz) processors. The high processor cost of our algorithm follows from the cost of computing the relations Si and Zi. One can observe that it is possible to reduce the number of processors used in the computing of Si by applying a sorting algorithm to rows of the adjacency matrix. Reducing the number of processors involved in computing the relation Zj remains an open question. 3.7. A n appl icat ion of the cotree construction a lgor i thm -construct ion of a tree representation for a par i ty graph The cotree construction algorithm can be used as a fundamental building block in the construction of a tree representation for a richer family of graphs called parity graphs. A graph is called a parity graph if and only if for every pair of vertices all minimal chains joining them have the same parity. Parity graphs are perfect [Sac70] (i.e. for every induced Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 79 subgraph H of a parity graph the size the maximum independent set in H equals the size a minimum clique cover in H), and are a subclass of the Meyniel graphs [Mey84]. The class of parity graphs includes bipartite graphs and cographs. Burlet and Uhry [BurUhr84] noticed that parity graphs can be obtained from a single node by certain construction rules, namely the creation of weak or strong siblings and the operation called extension by a bipartite graph. Thus we can associate a parse tree with every parity graph; this parse tree, however, need not be unique. Burlet and Uhry [BurUhr84] presented a polynomial time sequential algorithm to recognize parity graphs and construct the corresponding parse tree. They show how to reduce a given parity graph to a single vertex by operations which are reverses of the three creation operations. Their algorithm explores the BFS (Breadth First Search) layering structure of parity graphs. They proved that if No,Ni,...,N p are BFS layers, then the induced subgraph on each of the Ni forms a cograph. (In [BurUhr84] cographs are called 2-parity graphs.) Furthermore the relationships between vertices in neighboring layers are not arbitrary. Consider the level Nj. One can distinguish certain families of nested sets of vertices in each BFS layer with the property that elements from each set S of the family have the same set of neighbors in both the layer Ni_i and in the subgraphs induced by Nj-S. The relationship between elements from levels Ni and Nj+i is more complex but one can observe that if S is a maximally nested set then elements from S have the same set of neighbors in Ni+i. Thus the graph induced by such a set can only be reduced with the help of cograph operations, i.e. by the sequential removal of siblings. Furthermore such a graph is reduced either to an empty graph or to a set of independent vertices which do not have connections with the rest of the elements in the layer. The sequential algorithm of Burlet and Uhry considers the BFS layers starting from the most distant one from the root of the BFS tree, and within each layer constructs the corresponding family of subsets, and then processes them starting from a minimal one. Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 80 A nontrivial parallelization of this approach has been presented by Przytycka and Cornell [PrzCor88]. It turns out that not only can all BFS layers be processed in parallel, but also within each layer all sets in the corresponding family can be processed in parallel, treating all sets contained in a given set as "black boxes". Within each set we use only cograph operations. Thus we can construct the corresponding part of a parse tree using the techniques described in the previous sections. From the properties of the operation of extension by a bipartite graph it follows that if such a "black box" has a connection to other vertices in the level, then we are able to reduce it to the empty set with the help of an operation which is the inverse of an extension by a bipartite graph. Otherwise the elements to which the "black box" is reduced form a part of a bipartite graph which is detected and reduced (with the help of the operation which is the inverse of an extension by a bipartite graph) on other level. The algorithm given by Przytycka and Comeil runs in 0(log2n) time with rc4/log2rc processors on a CREW PRAM model. The idea of using the BFS layering structure of a graph for performing parallel computation has been generalized by Novick [Nov90b] to obtain a parallel algorithm for the split decomposition of an arbitrary graph. Przytycka and Corneil [PrzCor88] showed how the BFS layering structure of a parity graph can be used to find a maximum clique in 0(log 2 «) parallel time with « 2/log 2n processors. 3.8. Summary This chapter we presented a parallel tree expansion technique. In a parallel tree expansion technique, beginning with a single node we construct a tree by an iterative replacement of nodes and/or edges by connected subtrees. With this technique we developed the first NC algorithm for construction of the cotree representation of graphs from family of graphs known as cographs (see also [KirPrz87]). First, we identified Chapter 3: Parallel tree expansion-construction of tree representation for cographs page 81 properties of cographs which make it possible to reduce a cograph to a single vertex such that each intermediate graph is a cograph in at most clog n steps (where c is a constant). Furthermore, the cotree of the cograph which results from a reduction step can be efficiendy expanded to the cotree of the reduced cograph. In our algorithm, we first reduce the input graph to a single vertex, then construct the cotree representation for this vertex, and finally, we interatively expand this cotree to the cotree representation of the input graph. Alternative solutions to the parallel cotree construction problem were independently obtained by several other researchers ([Shy88], [Nov89], [AdhPen89]). In general, the basic limitation of the tree expansion method is that it may be difficult to determine whether (and how) to expand a particular edge or a vertex in a given iteration of the tree expansion process. However in the case of the cotree construction problem this method gives a simple and elegant solution. In the last section of this chapter, we sketched an application of a cotree construction algorithm to the problem of computing in parallel a tree representation for a graph from a family of graphs known as parity graphs. In our construction, we relied on the specific structure of BFS layers of a parity graph ([BurUhr84], [PrzCor89]). Our ideas have been extended by Novick [Nov90b] to obtain a parallel algorithm for the split decomposition of an arbitrary graph. Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost optimal weighted path length page 82 CHAPTER 4 : P A R A L L E L L E V E L - B Y - L E V E L TREE SYNTHESIS: CONSTRUCTION OF BINARY TREES WITH ALMOST O P T I M A L W E I G H T E D P A T H LENGTH In this chapter we explore a parallel bottom-up level-by-level tree synthesis technique in connection with a family of parallel algorithms to construct trees with almost optimal weighted path length. The idea of constructing trees which give an approximate solution to the problem of constructing of an optimal tree has been widely explored in the sequential setting. Early approximation algorithms for the optimal binary search tree problem ([Meh75], [Bay75], [Fre75]) applied a top-down technique. Allen [A1182] showed that the cost of some common classes of approximately optimal binary search trees relying on a top-down approach could not be bounded above by the cost of an optimal tree plus a constant. Larmore [Lar86] presented a bottom-up subquadratic algorithm which produces a binary search tree whose cost is bounded above by the cost of an optimal tree plus a constant. Bottom-up techniques also appear to be very useful in a parallel setting. Atallah et. al. [AtaKosLarMilTen89] gave an 0(log(l/e)log2n)-time n2flog2n processor algorithm which Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 83 optimal weighted path length finds a binary search tree whose weighted path length is within e of that of the optimal tree. Their algorithm uses a dynamic programming technique. Part of the motivation of looking for approximate solutions is to understand the tradeoff between the accuracy of a solution and its cost. There is an additional motivation, namely that a slight relaxation of an optimization problem, in which only an approximately optimal solution is sought, can be solved efficiently by restricting attention to trees from a certain family. In the parallel case families of trees of polylogarithmic height seem to be of special interest. Within such a family it is possible to obtain efficient parallel algorithms which produce a tree in a level-by-level fashion. A level-by-level bottom-up technique is strictly applicable if we know the depths of the leaves of the constructed tree. In this case, we can construct the tree in d iterations, where d is the height of the tree, such that in the i t n iteration we construct the parents of nodes on level d-i+1. On the other hand if we know the depths of the leaves of a tree we can construct the tree in 0(log n) time with «/log n processors using the accelerated valley filling technique described in Chapter 5. However we can also consider a level-by-level approach if we do not know the depths of the leaves but instead for every leaf v we can compute a value rank(v) such that rank(v)>/T(v) (i.e. rank(v) bounds the depth of the leaf v in the constructed tree T). Then we can spread the vertices into levels according to the rank function. Now, during the i t n iteration of such a level-by-level construction each vertex which is on level d-i+1 either obtains a parent, which goes to level d-i, or is itself promoted to level d-i. In this chapter we apply this level-by-level construction to obtain various algorithms for producing binary trees with approximately optimal weighted path length. The problem of finding a tree with optimal weighted path length is related to the problem of constructing an optimal code. Let V={vi , . . . ,v r t } be a set of letters and let V V ( V J ) be the frequency of the occurrences of letter Vj in a word. The goal is to find a binary code Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 84 optimal weighted path length for every letter of V such that no code is a prefix of any other code and minimizes the average word length, defined as 5^(v)w(v) (where /(v) is the length of the code of v). v e V Equivalently, one can search for a binary tree T whose set of leaves is equal to V and which minimizes the cost function c(T)= ^ /x(v)w(v), where /j(v) denotes the length of the path v e V from the root to the leaf v in the tree T. For the remainder of this chapter we call such a tree an optimal tree. The notion of an optimal tree extends in an obvious way to the case where w is a weight function such that w: V->R+. However, in this case the problem can be reduced to the normalized problem by dividing the weight of each element v, w>(v), by W = £ w ( v ) - Thus we assume W =1. Note that this does not imply that the cost of an veV optimal tree is bounded by a constant. In fact it may achieve log n (for lower bounds on a weighted tree path see for example [Meh85]). An optimal tree can be constructed in 0(n log n) sequential time by an algorithm due to Huffman ([Huf52]). The tree produced by Huffman algorithm is called Huffman tree. It can be shown (see [Huf73]) that an optimal tree (whose leaves may appear in an arbitrary order) can be realized with a tree whose leaves appear in the sorted order. This observation together with the parallel dynamic programming algorithm of Miller, Ramachandran and Kaltofen [MilRefKal85] leads to an 0(log 2«)-time «6-processor parallel algorithm for construction of an optimal binary tree (see [Ten87] for a detailed description). An improved algorithm has been proposed by Atallah, Kosaraju, Larmore, Miller, and Teng [AtaKosLarMilTen89]. In their algorithm the special structure of the dynamic programming problem has been used to produce a polylogarithmic time algorithm using n 2 processors. This algorithm still does not achieve an optimal speedup over the Huffman algorithm. The question (cf. [AtaKosLarMilTen89]) of whether there exists a parallel algorithm which constructs an optimal tree in polylogarithmic time using n2~e processors remains open. In Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 85 optimal weighted path length the same paper, an approximate solution to the problem is proposed. Let T*y be an optimal tree for set V and let T be an arbitrary tree with leaves equal to V. The error of tree T, AT, is defined as c(T)-c(T*y)- A tree whose error is small is called almost optimal. Atallah, Kosaraju, Larmore, Miller, and Teng [AtaKosLarMilTen89] presented an algorithm which produces a tree T with AT < 1 in 0(log n) time using nllog n processors if the input sequence is sorted according to the weights. Also the parallel algorithm to produce an almost optimal binary search tree presented in the same paper can be used to construct a tree T with AT<l/nk in 0(klog2«) time and with «2/log2« processors. We present a family of parallel and sequential algorithms to construct an almost optimal binary tree. Each of our algorithms is an interpretation of the algorithmic scheme, called the General Construction Scheme (QtS/b), defined in Section 4.3. The use of an algorithmic scheme allows us to state a general theorem which estimates the error obtained when constructing a tree using one of our algorithms. In Section 4.1, we present the Basic Construction Scheme (tfi'G )^ which defines a family of bottom-up tree constructions. This scheme leads to efficient algorithms provided that there do not exist elements of very small weight. We prove that an algorithm which is an interpretation of tI3G^ 6 cannot produce a tree with error greater than 1. We also present a modification of tBT5,£ which reduces the maximal error to 0.172. The algorithmic scheme Q"iZ/6 defined in Section 4.3 is a modification of 1ft T!,©. This scheme leads to efficient algorithms for sets including elements of arbitrarily small weight. In Section 4.4, we present a number of parallel interpretations of 9^ > - In particular, we give an 0(log loglog n ri)- time and n £ *—processor EREW algorithm which constructs a tree with error at most 0.172, an 0(klog n log*«)-time and n-processor CREW algorithm which produces a tree with error at most -r-, and an 0(k2log «)-time rfi -processor CREW algorithm which nK produces a tree with error at most 4-. The algorithm obtained as the result of the second nK Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 86 optimal weighted path length parallel interpretation of 9 ^ ^  achieves almost optimal speedup over the Huffman algorithm and produces a tree with a very small error. This result has been achieved by applying the cascading sampling technique presented in Section 2.6. In the Section 4.6, we present two sequential algorithms which are also interpretations of 9 ^ > ^  • The first of them produces a tree with error at most and runs in O(krc) time assuming a RAM model with bounded register capacity. The second algorithm produces a tree with error at most a n c ^ a * s o m n s * n Otk") time but it uses an integer sorting algorithm which assumes a RAM model of computation with unbounded register capacity. Section 4.7 contains some concluding remarks together with a table summarizing our results and related work. One should be aware of another source of error which we have not addressed in this work, namely the error resulting from representation of real numbers on a computer. Our algorithms use only comparison, addition, division by 2,mod, and TI, with the exception of the third parallel algorithm which uses also division by n. One can show that Huffman's algorithm is numerically stable. Similarly our 0(klog n log*n) algorithm is numerically stable. It is also worth noting that if the input sequence is given as a sequence of integers representing relative frequencies rather than probabilities then we can reformulate our algorithms (with the exception of the second integer sorting), so that they will perform only integer operations using words of size comparable to the size of maximal input element. 4.1. Basic Construct ion Scheme An optimal tree can be constructed by the following simple algorithm due to Huffman: Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 87 optimal weighted path length T H E H U F F M A N ALGORITHM: While IVI > 1 do Let v i ,v 2 be the pair of elements from V of smallest weight. Construct internal node u with v^ and v 2 as children and define w(u)=w(vi )+w(v2). V:=V-{vi,v2}u{u}. Huffman's algorithm can be implemented to run in 0(n log n) time. However, if the input sequence,V, is sorted according to weights then the Huffman tree can be constructed in linear time. Let Q be (initially empty) queue of internal nodes of the constructed tree nodes. We also treat V as a queue. Then the following algorithm constructs the Huffman tree in linear time : CONSTRUCTION OF T H E H U F F M A N T R E E F R O M A SORTED SEQUENCE OF WEIGHTS: While IQuVi > 1 do let v i be a node such that w(vi)=min {w(first(Q), w(first(V)}, delete vi from the corresponding queue; let V2 be a node such that w(v2)=min {w(first(Q), w(first(V)}, delete V2 from the corresponding queue; Construct internal node u with \ \ and V2 as children and define w(u)=w(vi)+w(v2); append u to Q. Both algorithms presented above are highly sequential. We start by presenting an alternative way of constructing a tree isomorphic to the Huffman tree. Like Huffman's algorithm our algorithm produces the tree in a bottom-up fashion. At each stage of the algorithm we are dealing with sequences of roots of disjoint subtrees of the constructed tree. Each subtree has associated weight equal to the sum of weights of the elements in its leaves. If an element v belongs to a sequence X then pred(X,v) (resp., succ(X,v)) denotes Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 88 optimal weighted path length the element which precedes v (resp., follows v) in the sequence X and dist(X,v) denotes the number of elements (including v) which precede v in the sequence X. We use first(X) (resp. last(X)) to denote the first (resp. the last) element of the sequence X. Assume that the input sequence is sorted. Observe that Huffman's algorithm can be divided into the following phases: At each phase we pair two currently smallest elements, insert the resulting element, say v, into the sequence, and then pair in sequence all (but possibly one) elements whose weight are smaller than the weight of v. Finally we merge the sequence resulting from this pairing step with the rest of the sequence. It is not difficult to implement this algorithm in 0(kloglog n) time with n processors where k is the number of phases needed to finish the algorithm. A further modification of this approach allows for a more efficient implementation and makes it possible to obtain a family of approximation algorithms. For every ve V we define rank(v) = [~log(l/w(v))l. If rank(v) = i then we also say that element v belongs to level i. By convention, we think of a tree as having its root at the top and leaves at the bottom so a higher level is a level of elements of smaller rank. We divide the input sequence into subsequences Vi,V2,.. . according to ranks. Let I=max{i I IVjl>0 }. Elements of each of V, are paired in a different step. The i t n step now consists of pairing the elements resulting from the previous step (the sequence U2i) and merging the resulting sequence with the sequence V j . i . Inductively we maintain the invariant that the elements in the sequence U2i have rank at least i (i.e. they are not too big) and that the sum of the two first elements has rank at most i (i.e. it is not too small). Furthermore we design our algorithm in such a way that the cardinalities of all sequences constructed by the algorithm depends only on the cardinalities of the initial partition into sets Vj (see Lemma 4.3) This appears to be a very useful property both for the designing of approximate algorithms based on this approach and for their analysis. Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 89 optimal weighted path length Let sort be an increasing sorting procedure, and merge be a procedure which given two sorted sequences produces a sorted sequence containing all elements from both sequences. Let pair_elements be a procedure which given a sequence U= ui , . . . ,U2/ produces a sequence C = c i ,...,c/ defined as follows. For i=l,...,/, create a common father Cj for the pair of elements U2i_i, u2i defining w(ci)=w(u2i-i)+w(u2i). We use # to denote the concatenation operation on sequences, and - to denote a deletion of a subsequence from a sequence. As we prove later, the following algorithm constructs a tree isomorphic to the Huffman tree: 1. Divide elements of V into sets Vi,V2,....such that ve Vj iff rank(v)=i; 2. For every i do sort(Vj); 3. Let Vi 1 , . . . ,Vi L (i r<i r +i, i^=l) be the list of nonempty sets; i:=iL; L ^ I ^ V T ; k:=L-l; — i is the index of currently processed level, i^ is the index of — the closest nonempty level to be processed 4. while k>0 or IU2i I >1 do 5.1. if IU2il = 1 then U2ik:=U2i#Vik; i:=ik; k:=k-1; — put the only element of U2i into the closest nonempty level 5.2. else c:=pair_elements(/i>5 ,r(U2i),5'MCc{/'/r5r(U2i)); 5.3. U2i.i:=merge(c,U2i-{//^r(U2i),^cc(/i'm(TJ2i)}); — the parent, c, of two first elements may have rank equal to i or i-1 — so it is initially inserted into the sequence of elements of rank i; 5.4. if IU2i-1' is e v e n th&n c:=pred(last(U2i-\))#last([J2i-i) else c:=last(U2i-i); 5.5. Cj_i:=merge(pair_eIements(U2i-i-c),V}_i); — pair elements of U2UI except for the last element (or last two — elements); the last element may have rank equal i-1 (compare — step 5.3) so should not be paired at this point; — merge the resulting sequence with the elements ofV^j 5.6 l ^ ^ m e r g e C q . ^ c ) ; — merge the remaining (one or two) elements form sequence U2i-l — into sequence C^; 5.7. i:=i-l; if IVjl > 0 then k:=k-l. Lemma 4.1. The above algorithm produces a tree isomorphic to the Huffman tree. Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 90 optimal weighted path length Proof: Assume that in the above algorithm we replace the procedure pair_elements with a sequential procedure which pairs elements of an even length from beginning to end. It suffices to prove that during such a pairing step we always pair two smallest elements (i.e. the roots of the two subtrees of smallest weight are given a common parent). Note that all sequences occurring in the algorithm are sorted and that, for any i<k, elements in Vj are greater than elements in V^. Note also that the following statement is an invariant of the"while" loop: elements in Vj_i are greater than elements in U 2 i - This is certainly true before the first iteration. So in step 5.2 we pair two smallest elements. After step 5.3, all elements of U2i_i except, possibly, the last one are smaller than any element of Vj.i. Also for any i the last element of U 2i.i is smaller than any element of Vj_2- Since the last element does not take part in the pairing step in line 5.5, in this step the smallest possible pair of elements is also always paired. After step 5.5 elements of Q . i are smaller than elements of Vj_2. So elements of the sequence U2i_2 created in step 5.6 are also smaller than elements of Vj_2. From this the invariant of the "while" loop follows and consequently the fact that we always pair the smallest possible pair of elements. • Consider the above algorithm from a more general point of view. Replace the sorting procedure by a procedure ORDER which defines some (not necessarily sorted) order and the procedure merge by a procedure M E R G E which given two sequences V, C produces a sequence of elements in V u C with the property that it is sorted according to rank (but not necessarily within each rank). This produces an algorithmic scheme called the Basic Construction Scheme ( B ) . Our initial algorithm is an interpretation of We call this interpretation the Huffman tree algorithm and denote it by H . Note that although pair_elements has a fixed meaning, its implementation depends on the representation of the sequences so, for consistency, we replace pair_elements by a procedure PAIR_ELEMENTS depending on the interpretation. When we refer to a sequence (Vj, Q or Uj) obtained by performing V>ViA in interpretation A, we use A as a superscript in the Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 91 optimal weighted path length name of the sequence (VjA, Q A or U j A respectively). Note that in fact we can use different interpretations of procedure MERGE and PAIR_ELEMENTS in different steps of an interpretation of tBC-o. If that is the case, then we indicate this by adding a subscript equal to the number of the substep of step 5 to the name of the corresponding interpretation. For example, MERGE3 denotes an interpretation of the MERGE procedure used in step 5.3. So: BTS/6 = <J9, INITIALIZE, ORDER, MERGE, PAIR_ELEMENTS) where n JS>= {(x,,...,xn) eR+ x R+ x....x R+ I J^q =1}; i=l ORDER, MERGE, and PAIRJELEMENTS satisfy conditions described above; (we omit a formal axiomatization of the properties of this procedures) P: Input: array [xi,...,xn] and array [vi,...,vn] such that W(VJ) = XJ ; Output: a binary tree with leaves, V, labelled by elements from {x1,...,xn} Scheme: 1. Divide elements of V into sets V1,V_2,....such that ve Vj iff rank(v)=i; 2. For every i do ORDER(Vj); 3. Let Vi 1 , . . . ,Vi L (ir<ir+i, ii=l) be the list of nonempty sets; i:=iL; U2i:=VT;k:=L-l; 4. while k>0 or IU2i I >1 do 5.1. if IU2il = 1 then U2ik:=U2i#V ik; i:=ik; k:=k-l; 5.2. else c:=PAIR_ELEMENTS(//>^r(U2i),^MCc(/i>^r(U2i)); 5.3. U 2 i . i :=MERGE3(c,U2 i- [first(V2\)^ucc(first(\]1i)}); 5.4. if IU2i_il is even then c:=pred(last(XJ2i-i))#last(\J2i-i) else c:=/asr(U2i-i); 5.5. C i. 1:=MERGE 5(PAIR_ELEMENTS(U 2 i. rc),V i. 1); 5.6 U 2 i. 2:=MERGE 6(C i. 1,c); 5.7. i:=i-l; if IVJ > 0 then k:=k-l. Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 92 optimal weighted path length W e define the level o f a sequence U j to be equal to T^ rl. Elements o f U j whose rank is equal to the leve l o f U j f o r m the main subsequence o f the sequence U j . E lements o f U j whose rank is less than the level o f U j form the head o f the sequence U j . Elements o f U j whose rank is greater than the level o f U j form the tail o f the sequence U j . L e m m a 4.2: F o r any i the fo l lowing ho ld : (i) I ta//(U2i) I = 0 , (ii) I headtSSn.i) 1 = 0, (iii) I ta//(U2i.i) I < 1, (iv) I head(U20 1^2, (v) the element in the tail o f a sequence has rank one smaller than the level o f the sequence, (vi) i f IU 2 j l > 1 then the element whose weight is equal to the s u m o f the weights o f two first elements in the sequence has rank equal to or one smaller than the level o f the sequence. Proof: T h e p r o o f fo l lows by induct ion on the leve l o f a sequence. C o n s i d e r first a sequence U j o f level I such that j = 21. T h e sequence U j has an empty tail and head, and all elements in U j have rank equal to the level o f U j so (i) - (vi) are obvious ly true. Cons ider now sequence U 2 T_I . If such a sequence is constructed then it is obtained from the sequence U 2 T by pairing the two first elements and merging the resulting element with the rest o f the elements in the sequence. It is obvious that U21-1 has empty head and has a one-element tail. T h e rank o f the element in the tail is equal to 1-1. S o (i) - (vi) ho ld also for j=2I-l. A s s u m e that (i) - (vi) ho ld for all sequences U j o f level less than i . T o show point (i) note that i f sequence U2i+i has not been constructed then sequence U 2 j contains elements f r o m V j and the only element o f the last nonempty sequence U 2 k (k>i). If U2i+i has been constructed then U j contains elements f rom V j , Q and at most two elements f r o m U 2 i + i -S ince elements in V j and Q have rank equal to i and by inductive hypothesis point v) Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 93 optimal weighted path length elements in U2i have rank at most i, point (i) follows. To show points (iv) and (vi) note that the elements in the head may come either from the sequence U2i+i or, if U2i+i has not been constructed, from the last nonempty (one element) sequence U2k (k>i). In the first case (iii) follows from the fact that U2i+i has no head and in the second case it follows from the fact that in this case there is only one element in the head. Point (ii) follows from the facts (iv) and (vi) which have been proven above. Point (iii) follows from point (i) by the construction of tft ISA. Point (v) follows from point (vi) by the construction of I B C ^ J Lemma 4.3 (the oblivious property) : The cardinalities of all sequences occurring in the description of "fir £5 A and the number of iterations performed by an interpretation of IB f3 A does not depend on the interpretation. Proof: Note that in any interpretation of we start with the sequences V i , . . . , V j such that for each i=l,...,I the cardinality of V , does not depend on the interpretation. The cardinality of any sequence constructed by an interpretation of tRUA depends only on the cardinalities of the sequences used for the construction and therefore, by induction, is independent of the interpretation. Similarly the number of iterations depends only on the cardinalities of the sequences and therefore is independent of the interpretation. • An important consequence of the above lemmas is that if T is a tree constructed by an interpretation of tft "G A then AT can be expressed in the following way: Lemma 4.4: Let T be a tree obtained by some interpretation, A, of B1ZA and let Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 94 optimal weighted path length if U2i has not been constructed or IU2il=l w(first(\J2iA))+w(succ(first(\J2iA)))^ if IU2il>l 0 if U2i_i has not been constructed or IU2i_il=l A2i_i =< w(last(XJ2i-iu))-w(last(U2i-\A)) if IU2i.1l * s °dd a"d i is greater than 1 [ w(tor(U 2i.i%+w(pr^(^ otherwise. 21 ThenAT = XAj. j=i Proof : At any stage of the algorithm we are dealing with the forest consisting of the subtrees constructed so far. The roots of the subtrees belong either to the most recently constructed sequence Uj or to sequences Vj (i<T^ -~|). Let c(TjH) (resp., c(TjA)) be the cost of the forest such that the roots of the trees in this forest belong to the sequence U r H (resp., U r A ) where U r H (resp., U r A ) is the last constructed sequence such that r>j. By the definition of Aj we have for j<21: c(TjA)-c(TjH) = c(T j + 1 A )-c(T j + 1 H )+A j + 1 . Thus AT = 21 l A j . • j=i We use the above lemmas to prove: Theorem 4.5: If T is a tree obtained by an interpretation of IB C £ then AT <1. Proof: Let dj=A2i+A2i_i. We prove first that d j < - i r + - ^ r . ( * ) Let UA2i =uAi,uA2,...uA k 2 i be the sequence constructed by an interpretation, say A, and UH2i =uHi,uH2>—uHk2i b e m e sequence produced by the interpretation H (the Huffman Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 95 optimal weighted path length tree algorithm). Note that if U2i is not constructed then U2i_i is also not constructed and then dj=0. Alternatively consider the following four (exhaustive) cases: 1) Neither of the interpretations creates a tail. Then by Lemma 4.2 point (vi) we have 4- < w(uA!)+w(uA 2) and ^ < w(uH!)+w(uH2) < ~ . Then A 2 i < j{ and A 2 i _i< 4 S o d ^ ^ r + i -1 21"1 21 2) Both interpretations create a tail. We can interpret this case as a case when in both interpretations all but at most one (the last) of the elements are paired. Since unpaired elements have rank equal to i it follows that dj< --j . 3) Interpretation H creates a tail and interpretation A does not create a tail. Then < w(u A i)+w(uAo) < - T - r and -4-r < w ( u H i ) + w ( u H 2 ) ^ - T - T . Assume that 1 1 1 1 w(u H i )+w(u H 2)= ^ n " + z - T h e n A2i^-z and A 2 i . i £ + +z, so d^^y-4) Interpretation A creates a tail and interpretation H does not create a tail. Then -jr < 21 w(u H 1)+w(u H2) <-^Y and - r y < w(u A i ) + w ( u A 2 ) ^ " j j Assume that 2^  2^  2^  w(uAi)+w(uA 2)= 4---+Z. Then A 2 i <|r+z and A 2 i . !< | r - z , so di<4-Note that the most expensive case is case 1. However, if in this case IU A 2 j l is even, then A 2j_i < ^ r . If I U A 2 i l is odd (and greater than 2), then this step is followed by step of type 1 such that A 2 i . i = -A2j_2 • So in general we can assume that dj< + z i + 1 - Zj where ZJ=A2J i if U2i i has even number of elements and 1) holds and Zj=0 otherwise. I 1 i Thus we have AT =]Tdj < \ - y y . It remains to show that d i = - Z 2 - It is obvious that i=i J^JZ 1 i=l A ^ O . If n=2 then obviously AT = 0. Thus assume that n>2. Then has at most one element. If V j has one element then U3 has at most 2 elements with neither of them in a tail Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 96 optimal weighted path length (otherwise the sum of the weights would be greater than one). Thus in this case di =-Z2- If Vl has zero elements then U3 either has four equal elements (and the result is obvious) or at most 3 elements. If it has 3 or fewer elements then U2 has two elements and therefore A2=0. If U3 has 2 elements then one of them must be a tail so Z2=0. If it has 0,1 or 3 elements then 1) does not hold and Z2=0 as well. • From the inequality (*) above, it follows that vertices of higher level may potentially contribute more to the total error. Thus it is natural to ask how far we can reduce the error if we run an approximate algorithm until we reach some level, say t, and then use the Huffman tree algorithm, i.e. when we reach level t we sort all sequences on levels t and higher, and for the remaining iterations interpret M E R G E as an exact merging procedure. To see how much we can reduce the error using this approach consider first the following problem: Let W=wi,W2,....,wk where k = n-r, r > 0, and wi+W2+....+wk<l. Let L = 1-(w1+W2+....+wk). A sequence wi,W2,....,wk,wk + 1,....,wn such that w k +i>....>w n and w k + l + — + w n = L is called an extension of W. Elements W k + i , . . . . , w „ are called flexible elements. A sequence P=wi,W2,....,wk,wk+1,....,wn is called a feasible extension of the sequence W if, for every i,j such that Wj,Wj<max{w k + 1 , . . . . ,w n } , WJ<2WJ . Denote by IF (W) the set of all feasible extensions of W. Assume that JF (W) is nonempty. Let Pe IF (W). We denote the cost of an optimal tree for the sequence P by C(P) . Let AW = max C(P)-C(Q). We are going to estimate the value AW. Lemma 4.6. Let/: N x N->R be the function defined as/( x»y) =2^+y • T h e n m e r e e x i s t s a pair of integers r i ,r 2 such that ri+r2=n-k and the sequence Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 97 optimal weighted path length W*= w 1 , w 2 , . . . . , w k v 2 / ( r 1 , r 2 ) , . . . , 2 / ( r 1 , r 2 ) / ( r 1 , r 2 ) , . . . / ( r 1 , r 2 ) belongs to ^(W) and satisfies C(W*)=p min^C(P). Furthermore there exists an optimal tree T* for the sequence W* in which all flexible leaves of weight f(j\,^2) occur on one level, say h, and all flexible leaves of weight 2 / ( r 1 , r 2 ) occur at level h-1. Proof: Let Q = wi,w2,....,wk,wk +i,....,wn be a feasible extension of W=wi,w2,....,wk which satisfies C(Q) = min C(P). Let T be an optimal tree for Q. Let u be the maximal flexible element of Q. First we show that there is an optimal tree in which all elements less than or equal to u occur on two consecutive levels. Assume that there are two elements WJ,WJ< u such that wj belongs to level h and Wj belongs to level h-s (s>l). Then the parent of Wj, say x, has weight at least twice as big as the weight of the smaller of its children. Since Q is a feasible extension of W it follows that x > Wj. Therefore we can switch WJ with x without increasing the cost of the tree. Thus there is an optimal tree for the sequence Q, say T', in which all flexible elements occur at two consecutive levels. Let the number of flexible elements on level h-1 of tree T' be equal to r ^ and the number of flexible elements on level h be equal to r 2 . We do not increase the weight of the tree if we assign the weight 2/(r i , r 2 ) to flexible nodes on level h-1, and the weight/(ri,r2) to flexible nodes on level h. In this way we obtain tree T* which satisfies the conditions stated in the lemma. • In Lemma 4.6 we constructed a sequence W* such that C(W*) = min C(P). Now PeSXW) we are going to construct a (non-necessarily feasible) extension W of W such that C(W')> max C(P). Let P,Q be a pair of extensions of W such that P is obtained from Q PeD^ W) V by reducing the value of a flexible element of Q, say Wj, by some value x and increasing the value of another flexible element of Q, say Wj, where Wj>Wj, by the same value x. Then we say that P is obtained from Q by an elementary shift of weight. Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 98 optimal weighted path length Lemma 4.7: If P is obtained from Q by an elementary shift of weight then C(P)<C(Q). Proof: Assume that P is obtained from Q by reducing the value of a flexible element of w, say Wj, by some value x and increasing the value of another flexible element of w, say Wj, where WJ>WJ, by the same value x. Let T be a tree which is optimal for the sequence Q. Let T' be a tree obtained from T by changing the weights of leaves corresponding to Wj and Wj by subtracting and adding x respectively. Since 1T(WJ)<1t(WJ) it follows that c(T)>c(T"). Furthermore the cost of T is greater than or equal to the cost of an optimal tree for P. • Lemma 4.8. The sequence W'=W],w 2 , . . . . ,w k , %^ ^ — ^ - satisfies C(W') > max C(P). P e J r ( W ) Proof: We show that for any feasible extension P=wi,W2,....,wk,wk+i,....,wn, there exists a sequence of elementary shifts of weight leading from W' to P. We define this sequence inductively. Let Wj = w 1,W2,....,w k,w k + 1 i,....,w n i be the sequence obtained after the i t h elementary shift of weight (W 0 = w' = w i , w 2 w k , ~ , . . . . y ) = w 1 , W 2 , . . . . , w k , w k + 1 ° , . . . . , w n ° ) . If Wj * P then perform the following shift of weight: Let Wji be the first flexible element such that WJ J <WJ and w t J be the last flexible element such that wt' >wt. Then define W ; + 1 as follows: for s*j,t w s i + 1 =w s i ; Wji+l=Wji+min(Wj-Wji,wti-wt) ; Wji+lrzw^-minCwj-Wji.w^-Wj) ; (shift min(w k +i-w t i ,w t i-w n) weight from wt* to WjJ). It is obvious that a finite number of such steps convert W into P. Thus, by Lemma 4.7, C(W')>C(P). • Now we are ready to prove the following theorem: Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 99 optimal weighted path length Theorem 4.9: If W=w1 ,W2,—,wk where k<n and l-(wi+W2+....+wk) = L>0 then AW <L(3-2%T2). Proof: Let T* be the optimal tree from Lemma 4.6 and let T" be a tree obtained from T* by replacing all flexible vertices with vertices of equal weight (=~^- Of course c(T") > c(T) where T' is an optimal tree for the sequence where all flexible vertices are equal. So AW < c(T")-c(T*) = r 2 ( - - y^—) = ^  • "~k~l2 . K ' v ' z\x 2vi+V2/ n-k 2(n-k)-r2 Consider A W as a function of r 2 . This function achieves its maximum, equal to L(3-2V2) < 0.1716L, for r2=r(2-V2). Thus AW < L(3-2V2).B Corollary 4.10: If B T J ^ O is interpreted in such a way that an approximate construction is carried out to level t-1, and the exact construction is then performed for all levels greater than or equal to t, then A T < 10.1716. Proof: Let W=wi,...,wk be the sequence of weights of elements of rank smaller than t. Then for any interpretation of T3 A the sequence obtained by sorting of the sequence U2t-i is a feasible extension of W. By (*) and Theorem 4.9 it follows immediately that AT < + 0.1716.U Note that from the above corollary it follows that if we start the exact construction from level 11 then AT < 0.172. 4.2. Approx ima te sort ing and merging of approx imate ly sorted sequences A sequence ui,U2,...uic is e-sorted if and only if max(max(w(uj)-w(uj)))<£. i i<i J Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 100 optimal weighted path length A sequence ui,U2,...u k is an e-approximation of the sequence vi ,v 2 , . . .v k if for every i, w(Uj)-r-£>w(vj)>w(uj)-£. Note that if ui,U2,...u k is an e-sorted permutation of a sorted sequence \\,V2,...vk, then it is also an e-approximation of the sequence vi ,V2,...vk. A procedure performs e-merging if, given two e-sorted sequences, it produces an e-sorted sequence. Example 4.11. Consider the standard merging procedure applied to two e-sorted sequences C = Ci ,C2, . . .c k and V = vi,V2,. . .v r (i.e. the procedure which inductively compares the first elements of the input sequences, removes the smaller of them, makes it the next element of the output sequence, and so on). Let U=ui,U2,...u k + r be the resulting sequence. To see that this procedure performs e-merging note that for any two elements Uje V, Uje C (resp., Uj€ C, Uj€ V) if i<j then there exists an element ut€ C (resp., u te V) such that i <t < j and w(ut) > w(uj). Since C (resp., V) is e-sorted it follows that w(ut) < W(UJ) - e. So w(uj) < W(UJ) - e. Example 4.12: Consider a merging procedure which first divides input sequences V and C into m subsequences V 1 ,V2, . . .V m and C i , C 2 v C m respectively (some of them possibly empty) such that the i t n subsequence contains elements whose weights are in the interval ^m *~m^ ( r e c a ^ t n a t a ^ elements are from the interval (0,1]). The merged sequence is equal to Vi ,Ci ,V2 ,C2 , . . . ,V m C m . It is easy to see that this procedure first constructs - sorted sequences and then performs ^-merging of those sequences. An important property of an e-merging procedure is given in the following lemma: Lemma 4.13: Let C A = c A i , c A 2 , . . . c A k and V A = v A i , v A 2 , . . . v A r b e two e-sorted sequences. Assume also that V A is an e-approximation of a sorted sequence V H and that C A is an e-approximation of a sorted sequence C H . Let U A be a sequence obtained by Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 101 optimal weighted path length merging V A and C A by an e-merging procedure, and let U H be a sequence obtained by the exact merging of V H and C H . Then U A is a 2e-approximation of U H . Proof: Let u A and u H be two elements with the same index in U A and U H respectively. Assume without loss of generality that the number of elements from C A in the sequence U A which precede element u A is less than or equal to the number of elements from C H which precede element u H in U H . Then there exists j such that the j t n element of list V A (VJA) occurs in U A before u A or is equal to u A , and the j t n element of list V H (VJH) occurs in U H after u H or is equal to u H . But V A is an e-approximation of V H so W(VJ A ) > w(vjH)-e. However W(VJ h ) > w(uH) and (since U A is e-sorted) w(uA) >w(vjA)-e. So w(uH)-w(uA) < 2e. Two prove that w(uA)-w(uH) < 2e we use a symmetric argument (with the role of C and V exchanged). • 4.3. General Construction Scheme (9tS/6) Note that if set V contains elements of very small weights then computing ranks may become a bottleneck for any interpretation of B £> A .To obtain efficient implementations we divide all elements into two groups : heavy elements and light elements. More precisely let K(n) be an integer function of n. An element whose rank is less than or equal to K(n) is called a heavy element and an element whose rank is greater than K(«) is called a light element. We assume that K(n) is chosen in such a way that it is easy to decide whether a given element is light or heavy and that it is easy to compute ranks of heavy elements. Denote the set of heavy (resp., light) elements of V by Vj, (resp., V/) and let V'= V^U {u} where u is an arbitrary element of V / . The General Construction Scheme (9£>/©) is a modification of the basic construction scheme. Roughly speaking, we use tfr £5/6 for the set of heavy elements and then add to Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 102 optimal weighted path length the resulting tree a subtree of light elements. (A similar approach was also taken in [AtaKosLarMilTen89] for the algorithm to construct an almost optimal binary search tree.) GENERAL CONSTRUCTION SCHEME (QVA) 1. Divide set V into sets Vjj and V/. 2. Divide elements of into sets V 1,V2,. . . .VK(«) according to ranks 3. For every i compute ORDER(Vj). 4. Choose an arbitrary light element u and add it at the beginning of the sequence VK(n) (let V'K(n) be the resulting sequence) 5. Perform steps 3-5 of the tflCo for set V'= V h U {u}; 6. Replace u by an almost full binary tree composed of all light elements. Note that the error of a tree constructed by an interpretation of 9 ^ ^ is composed of two factors: the error resulting from an interpretation of V> t> A and the error from the light elements. We call the first component construction error and the second component truncation error. The total error can be approximated with the help of the following lemma: Lemma 4.14: Let T' be an approximation of an optimal tree for V and let T be the tree obtained from T' by replacing u by any binary tree of all light elements. Then 2 AT<AT'-f " 2KO0 " Proof: Since every leaf has depth at most n in T we have: ra2 ^ x » r ™ n 2 c(T) < c(T') + n 5>(v) < c(T') + < c(T*v0+ AT+ soc(T)<c(T*v)+AT+ • 4.4. Parallel interpretations of 9 ^ A As we have mentioned before, the 9 /6 presented in the previous section can be divided into two parts: computing a tree for heavy elements and modification of the Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 103 optimal weighted path length resulting tree with a subtree of light elements. The second part can be implemented in 0(log n) time with n/log n EREW PRAM processors independently of the choice of K(ri). The first part involves 0(K(n)) iterations of step 5 of A3 tZ A so in order to obtain an efficient parallel algorithm it is natural to chose K(n)=kflog n l where k is some integer constant. With this definition of K(n), truncation error is bounded by —j-r. So we concentrate on an interpretation of the first part (i.e. on an interpretation of the H3tj/6 for heavy elements). 4.4.1. 0(log n) time n~y^rn~ E R E W processors parallel interpretation of 9 C A with error bounded by 0.172 By Theorem 4.5, any interpretation of gives a construction error bounded by 1. By Corollary 4.9 any interpretation of A3 tj,£ in which starting from level t we apply the Huffman tree algorithm leads to a construction error bounded by -—r + 0.1716. So, in particular, we can start with arbitrarily ordered sequences and for sequences on levels lower than t interpret MERGE as concatenation of two sequences. Then at level t, we sort all sequences and finish the construction interpreting MERGE as an exact merging procedure. We can compute ranks for heavy elements in 0(loglog n) time with 0(«) EREW processors by a binary search or ( simulating i ^ ^ g n processors by one processor) in 0(log n) time with n°,^^ n EREW processors. Then, using the parallel bucket sort lOg YI algorithm of Cole and Vishkin [ColVis86a] which sorts integer elements in the range [O...log n] in 0(log n) time with n /log n processors, we distribute the elements to the corresponding subsets. All concatenation and pairing steps can be implemented in total of 0(log n) time with n EREW processors. However, by applying Brent's scheduling principle (since we can maintain information about the position of every element within a Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 104 optimal weighted path length list, the processor allocation is not a problem) we can reduce the number of processors to n . Since there are at most 2 l elements on levels t and higher, the "exact" part of the algorithm can be implemented in 0(t log2t) time using Cole's parallel merge sort and an EREW impelemention Valiant's parallel merging procedure. Let t < log n - loglog n. Then the entire algorithm can be implemented in 0(log n+t log2t) time with n n EREW processors. In particular, if we choose t=k=l 1 we obtain: Corollary 4.15: A tree whose cost differs by at most 0.172 from the cost of an optimal tree can be constructed in 0(log n) time with « " ~ ] ^ r f " ^ EREW processors. 4.4.2 A 0(kIog n log*n) time n processor parallel interpretation of 9 ^ ^ with error bounded b y ' l / n k We represent sequences in the form of lists such that for every element its position within the list is known. To achieve zero construction error we can implement ORDER with Cole's parallel sorting algorithm [C0I86] which runs in 0(log n) time using n CREW processors and M E R G E with Valiant's merging algorithm ([Val75],[BorHop85]) which merges two sorted arrays of sizes rt;,«2 (ni^n2) m 0 ( l ° g l o g «?) time with rt;+«2 CREW processors. This permits a straightforward implementation of step 5 of A3 A in 0(loglog n) time with n processors. By the definition of heavy elements, we have 0(klog n) iterations. Thus this implementation runs in 0(klog n loglog n) time using n processors. To reduce the running time to 0(log n log*n) we use the cascading sampling technique described in Section 2.5. Note that we can view our solution as a sequence of parallel merging steps which, by the nature of the problem, have to be performed one after another. Thus we cannot improve the time complexity by pipelining the sequence of mergings. However, the cascading sampling techniques makes it possible to break each Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 105 optimal weighted path length merging problem into smaller merging problems which can be solved in parallel. We define sample(y)=y/2 and perform the preprocessing step as discussed in Section 2.6. Recall from Section 2.6 that this results in introducing new elements, called sampling elements, to each level. For each sampling element, x, there is a unique element (the source element for the element x) in the next higher level whose weight has been divided by half to obtain x. For any sampling element, x, source(x) is defined to be equal to the source element of x. Recall also that if u\, u 2 , is a pair of sampling elements from the same level such that there are no other sampling elements between them, then the subsequence of elements which lie between u i and u 2 is called a basic sequence, and the sequence of elements from the higher level which lie between the source of uj and the source of u 2 is called a gap. We also say that the gap defined by u^  and u 2 corresponds to the basic sequence defined by u ^ and u 2 . From Lemma 2.10 it follows that the gap size is bounded by 2 l o S* / 1 + 2 . To efficiently implement one iteration , say the i t n , of Q^A, we have to efficiently pair real elements from level |~log n~\ - i + 1 and merge the resulting elements into level flog n~\ -i. Similarly to the cascading functions problem, the existence of sampling elements allows us to subdivide each merging problem into subproblems such that at least one of the sequences in each merging subproblem is bounded by 2 l o 8* n + 2 . The existence of sampling elements makes the implementation of the PAIR_ELEMENTS procedure more involved. We only have to pair the real elements of a sequence. On the other hand the sampling elements (with doubled weight) must stay in the sequence after the pairing step. These elements are needed for the next merging step. Thus in our implementation of the PAIR_ELEMENTS procedure we first rearrange the sequence (not changing the relative order of real or sampling elements) in such a way that real elements which are going to be paired occur as consecutive elements. Furthermore positions of sampling elements are chosen in such a way that the list obtained by pairing real elements and doubling of weights of sampling elements is sorted. For this purpose for every element in a sequence we keep Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 106 optimal weighted path length the value nrjr equal to the number of real elements which precede the given element in the sequence (including the element itself), and leftjr which is the pointer to the closest real element to the left. To efficiently merge two sequences we have to determine, for each element in a sequence, the merging subproblem to which it belongs. For this purpose we keep, for each element, sequence pointers left_sa and left_so which define respectively the closest element to the left which is a sampling element and the closest element closest to the left which is a source element. In this way, each sampling element defines a basic sequence and its source defines the corresponding gap. We also keep, for every element in the sequence, the value nrso equal to the number of sampling elements which precede the given element in the sequence (including the element itself). This information is needed to efficiently compute the functions defined above for the sequence resulting from a merging step. This can be described in more detail as follows: REPRESENTATION OF SEQUENCES: Each sequence is represented by a list formed by the pointers succ. Also, for every element of a sequence, the following information is given: nr_sa - the number of sampling elements in the sequence, which precede the given element (including the element itself), nr_r - the number of real elements in the sequence which precede the given element, left_sa - the pointer to the closest sampling element to the left, left_r - the pointer to the closest real element to the left, °left_so - the pointer to the closest element to the left which is a source element, nrso - the number of sampling elements in the sequence which precede the given element. and for every sampling element we have: source - the pointer to the source of the given element. Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 107 optimal weighted path length To simplify the description we will also assume the following pointers (these pointers can be computed in parallel using the information provided by the pointers defined above): right_r - the pointer to the closest real element to the right, pred - the reverse of the succ pointer, source'1 - the reverse of the source pointer, dist - the sum nr_so+nr_r. INITIALIZATION: The source pointers are built in the sampling process. All the other information can be computed by applying the parallel prefix technique. PATR_ELEMENTS: STEP 1: Rearrange the sequence in such a way that real elements which are going to be paired occur as consecutive elements. For every sampling element x compute yl(x):=left_r(x); y2(x):=right_r(x); A sampling element x such that w_r(yl(x)) is odd is called a skipped element. For every skipped element the following two tests are performed: AFTER(x) 4=> 2w(x) < w(yl(x))+ w(y2(x)) INSERT(x) O AFTER and ( w(yl(x))+ w(y2(x)) < 2w(succ(x)) or succ(x) =right_r(x)) The first test checks whether the two real elements yl(x), y2(x) should be inserted somewhere after x and the second test checks whether the two real elements should be inserted immediately after x. However it may happen that the pair of real elements should be inserted before all sampling elements which occur between them. To detect this case every real element y performs the following test: FIRST(y) 4=» nr_r(y) is odd and w(y)+ w(right_r(y)) < 2w(succ(y)) STEP 2. For every skipped sampling element x update left_r and nrjr : if AFTER(x) then left_r(x):=left_r(left_r(x))\ nr_r(x):=nr_r(x)-l otherwise /e/r_r(x):=y2(x); nr_r(x):=nr_r(x)+\ STEP 3. Rearrange the elements on the list: For every skipped element x for which INSERT(x) is true do: Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 108 optimal weighted path length succ(pred(yl(x))):=succ(yl(x)); succ(pred(y2(x))):=succ(y2(x)); succ(yl(x)):=y2; succ(y2(x)):=succ(x); succ(x):=yl(x); For every real element y for which FIRST(y) is true do: succ(pred(right(y))):=succ(right(y)y, succ(right_r{y)):=succ(y); succ{y):=right_r{y) STEP 4. For every real element which changed its place compute leftsa, nrsa: For every skipped element x for which INSERT(x) is true do: left_sa(succ(x)), left_sa(succ(succ(x))):=x; nr_sa(succ(x)), nr_sa(succ(succ(x))) :=nr_sa(x); (we don't need pointer left_so for the list which is currently at the lowest level) For every real element y for which FIRST(y) is true do left_sa(succ(y)):=left_sa(y); nr_sa{succ{y)):=nr_sa{y) STEP 5. Form a new sorted list by pairing real elements and doubling weights of sampling  elements. Elements obtained from pairing real elements are considered as real. All the functions (nr_r, nr_sa, left_r, left_sa, succ, pred) can be easily computed from the corresponding functions of the old list. MERGEj(C,V) for i=3,6 is implemented as one or two insertion steps (we use the concurrent read facility to find the proper place for the inserted element). MERGE5(C,V) is implemented as follows: Step 1. Identify gaps and corresponding basic sequences: - For every element of V decide (based on left_so) to which gap it belongs. - For every real element of C decide (based on left_sa) to which basic subsequence it belongs. - If x is a sampling element then the basic sequence defined by this element corresponds to the basic sequence defined by sourceix). Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 109 optimal weighted path length STEP 2. Merge every basic subsequence with the corresponding gap We use Valiant's merging algorithm. Let x be an element from a merged list and let d(x) be the number of elements in a merged list which precede x and which are from a sequence other than the sequence to which x belonged before merging. This value can be computed as the difference between the current position in the (merged) subsequence and the previous position in the gap or basic subsequence. STEP 3. Compute the representation of the merged sequence: - Since we know the position of every element in V we may assume that we have immediate access to every element of V. Denote the i 1" element of sequence V by V(i). For every xe V: nr_sa(x), leftjsa -remains unchanged, nr_r(x):=d(x)+nrj-(x)+nr_r(source'1(left_so(x))); For every xe C: y:=V(dist(source(left_sa(x)))+d(x)); find the closest element from V preceding x in the merged sequence nr_sa(x) :=nr_sa(y); left_sa(x):=left_sa(y);nrj-(x):=nr_r(x)+nr_r(y)); - For every x: dist(x):=nr_sa(x)+nr_r(x) - Computing left_r: Let R be an auxiliary array. For every real element x do R(«r_r(x)):=x (assume R(0)=null). If x is a real element then left_r(x):=R(nr_r(x)-l) otherwise left_r(x):=R(nr_r(x)). The remaining functions can be easily computed in 0(1) steps. This finishes the description of the algorithm. We can summarize the main result of this section in the following theorem: Theorem 4.18: A tree whose cost differs by at most - i - from the cost of an optimal tree nk can be constructed in 0(k log n log*rt) time using n CREW processors. Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 110 optimal weighted path length 4.4.3.0(k2log n) time n 2 processor parallel interpretation of 9 C /6 with error bounded by - T -In our first interpretation of the 9 we left the elements in each of the sequences in their initial order. In our second interpretation we maintain the sorted order in all sequences. The interpretation which we present in this section lies between these two approaches. Here we approximately sort initial sequences and use an approximate merging algorithm which combines two sequences in constant time. The idea of the merging algorithm is taken from Example 4.12. First, we describe an algorithm which works in 0(klog n) time with « 6 k processors and then we show a hierarchical data structure which allows an 0(k2log n)-time «2-processors implementation. The idea is to partition the main subsequences (i.e. sequences with tails or heads excluded) into n 6 k subsequences such that element x belongs to the subsequence j if and only if w(x)-i€ [ '^•^-, ~^~r) where i is the level of the subsequence (we treat heads and tails separately). If an element, say x, belongs to the sublist we say that its subrank is equal to j (denote subrank(x)=j). In order to pair the elements in a sequence we need to know for each element the distance (or at least the parity of the distance) of a given element from the beginning of the sequence. If we pair two elements we have to compute the rank and the subrank of the resulting element. This is relatively easy if both elements have the same rank. Then the subrank of new element is approximately equal to the average of the subranks of the two initial elements. This becomes technically more involved when the paired elements have different ranks (this may happen when we pair the first two elements of a sequence). We show how this can be done in time proportional to the difference of ranks of these elements. In order to merge two sequences of the same level we concatenate corresponding subsequences (cf. Example 4.12). For each element in the new sequence we want to compute its distance from the beginning of the sequence. To do this it suffices, for Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 111 optimal weighted path length each element, to find an element from the other sequence which precedes the given element in the merged sequence. For this purpose, for each subsequence, we maintain the pointer to the closest nonempty subsequence following it and to the first and the last element of the given subsequence. This motivates the following representation of the sequences: REPRESENTATION OF SEQUENCES: For every element, x, we have: dist(X,x) - the position of element x in the sequence X, succ(X,x) - the successor of element x in the sequence X, If XJ is a subsequence of the basic subsequence of the sequence X then SUCC(XJ) - the closest nonempty subsequence following X J . FIRST(XJ) - the first element of the subsequence XJ. LAST(XJ) - the last element of the subsequence Xi . (If a subsequence j is empty then FIRST(XJ)=LAST(XJ)=0. INITIALIZATION: It is not difficult to construct the above data structure in 0(klog «)time with n 6 k processors. PAIR_ELEMENTS: First we show how to compute the subrank of the parent, say u, of two elements u^ , u 2 in time lrank(u2)-rank(ui)l. We assume that for every element u we know the boundary values 2rank(u) a n ( * 2rank(u)-l • ^ ul> u2 n a v e ^ G s a m e r a n k m e n , subrank(ui)+subrank(uo), , , / s , subrank(ui)+subrank(u2), . |_ — —J ^ subrank(u) < \_ ^ J + l • We can compute in 0(1) time the boundary values of the two possible subranks of element u and in this way determine one of two possible values. Assume that rank(ui)-rank(u2) = Ar > 0. In this case we normalize the subrank of the smaller element by dividing it by 2^. Note that u has rank equal to rank(u2) or rank(u2)-l. In the first case we have , subrank(ui) , , . N N , ^  , . . . , subrank(ui) |_ subrank(u2))J < subrank(u) < |_ +subrank(u2))J+l Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 112 optimal weighted path length and in the second case we have: subrank(ui) subrank(u2) 2Ar+l 2 -J < subrank(u) < |_ subrank(ui) subrank(u2) 2Ar+l 2 so again we have to determine one of two possible values. To be able to do this we shall compute the boundary values of the two subranks possible for u. We can compute them from the boundary values of subranks of elements uj, u 2 using a method similar to the one described above. Procedure PAIR_ELEMENTS2 has only two elements to pair. We simply create a common parent for both of them and compute the subrank of the new element. Procedure PAIR_ELEMENTS5 can be implemented as follows: STEP 1. Create a common father u for every element u^ whose value distCU.ui) is odd and  the element u\=succ(\JLet C be the resulting list. STEP 2. For each element v. dist(C.v):= \distCUMt(v))ll\. STEP 3. Construct the representation for the list C. For every element v from the resulting list C compute its subrank (i.e. divide C into sublists). STEP 4.Compute the functions FIRST and LAST To compute these functions we decide for every element of list C if it is the first and/or the last element of this subrank by comparing the subrank of the given element with the subranks of its neighbors. STEP 5. Compute the functions PREP and SUCC: IfFIRST(O>0 then PRED(Ci):=IN(pare«r(prec(U,/e/r(FIRST(C))))) else PRED(d):=IN(parenf(LAST(PRED(UJ)))) where IN(x) is a function which returns the pointer to the subsequence containing element x. Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 113 optimal weighted path length Function SUCC can be computed similarly. So the time to implement the above procedure with n 6 k processors is 0(Arj+l) where Ar, is equal to the difference of ranks of the first two elements on list U 2 i . But i XArj=0(K(«)) so the total time spent on the pairing step is 0(K(«)). j=i MERGEi(C,V): For i=3,6 this procedure is implemented as one or two insertion steps. If the inserted element has rank greater or smaller than the level of the sequence then it forms the tail or head of the sequence and is treated separately. For k=5 procedure MERGEk(C,V) can be implemented as follows. STEP 1. Obtain the resulting list U Put, for every j , elements of subrank j from list C before elements of subrank j from list V. STEP 2. For each element v of subrank j in the list U compute distCUj.v): if v is an element from list C then: dist(U,v) = dist(C,\) + dist(\, LAST(PREC(VJ)) else ifFIRST(Ci)*0 then dist(\J,v) = dist(V,v) + dwr(C,LAST(CJ)) else dist(U,\)= dwr(V,v)+dw/(C,LAST(PREC(CJ))). STEP 3. Compute the functions FIRST. LAST. PREP. SUCC for the list U: if FIRST(CJ)*0 then FIRST(UJ):=FIRST(C1) else FIRST(UJ):=FIRST(V,j); PRED((UJ):=max(PRED(CJ),PRED((VJ)); if LAST(Ci)=0 then LAST(UJ):=LAST(d) else LAST(UJ):=LAST(VJ); SUCC((UJ):=min(SUCC((CJ),SUCC((VJ)). It is easy to see that procedure MERGE can be implemented in 0(1) time with rt processors. This leads to the following lemma: Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 114 optimal weighted path length Lemma 4.19: A tree whose cost differs by at most -^-r from the cost of an optimal tree can be constructed in 0(klog n) rime using « 6 k CREW processors. Proof: The processor and time bounds follow directly from the description of the algorithm. The truncation error is —\-r. We will show that the construction error is bounded nk-z 8 4 by -rr. Let dj=A2j+A2j_i. We prove that dj < —— which, by Theorem 4.5, implies the n k 2lnk 2 25d-i) result. More precisely we show, by induction, that A 21 <---—r 25klog« a n c * ^2i-i -2 25(1-0+2 . 2 i T 25klog«' ^ o r e v e r y J t n e s e c l u e n c e U A j constructed by the algorithm is an approximation of the corresponding sequence U H j constructed by the Huffman tree A 1 25(*-0 algorithm. It suffices to show that U A 2i is a —r-r - approximation of the sequence U H 2i and UA2i_i is ^ ^ ^ ^ S k l o g n ' a P P r o x i m a t i ° n O I " t n e sequence U H 2 i _ i . For U H 2 i this fact is obvious. For other values of i note that, by Lemma 4.13, each application of M E R G E at most doubles the approximation error. Also each application of PAIR_ELEMENTS at most doubles the approximation error. Since in between creation of a sequence U2j and U 2 i_ i we have two calls of M E R G E and PAIR_ELEMENTS, and between the creation of a sequence U 2j_i and U2i_2 we have three calls of M E R G E and PAIR ELEMENTS the result follows. • Note that in the above algorithm the high number of processors follows from the fact that we use one processor for each subsequence. But in any sequence there are at most n nonempty subsequences. To avoid this inefficient utilization of both space and processors, we divide a sequence into subsequences in the following recursive way. A sequence is divided into n subsequences, then every nonempty subsequence is divided into n subsubsequences, and so on (6k times). The partition of sequences is reflected by a hierarchical data structure. The number of subsequences at every level of the hierarchy is Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 115 optimal weighted path length bounded by « 2 . To merge two sequences we concatenate corresponding subsequences. (Note that heads and tails of sequences have to be treated separately). The merging step is a natural simulation of the merging step described for the previous algorithm on such modified data structure. On each level of the hierarchy, we keep the pointers PRED, SUCC, FIRST, and L A S T , whose meaning is similar to the n6k-processor algorithm. To be able to move up and down within the hierarchical data structure we maintain, for each subsequence represented in the hierarchy, pointers UP and D O W N . For a given subsequence X the pointer UP points to the subsequence which contains X and is immediately higher in the hierarchy, and pointer D O W N points to a block of sequences defined by the next step of the recursive partition of X (see Figure 4.1). I I I " * ~ M i l I«I I—l—l—I—L^_l mr •—r III 1*1 I STVX f / c / 'I I. I III M i l l * I I' I M l l l l l l » l I I l*.| I I [ ST LAST R E D P R E D P R E D P R E D • • Figure 4.1. The hierarchical data structure used by the «2-processor algorithm (not all pointers are shown) The pairing step is more involved. To represent the sequence resulting from pairing elements of an even length sequence of elements of equal ranks, we modify the data Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 116 optimal weighted path length structure of the input sequence. During the pairing step we may obtain elements of subranks which have not been represented in the initial sequence. Thus we may be forced to extend our hierarchical structure. Some sequences may become empty and we should remove their representation from the hierarchy. However all these modifications can be carried out in time proportional to the depth of the hierarchy. More formally: Let X be a main subsequence of level i and let t=6k. Then 1. X is divided into n subsequences X 1 , . . . ,X" (some of which may be empty) according to the weights, such that xe XJ iff w(x)-i<= R-^-i-, -^i-). 2. Each nonempty sequence X 1 1 1 2 " l r , where, r<t is divided into n subsequences x iii 2....i ri x . i 1 i 2 . . . . i rn s u c h that xeXi iii2--irJ iff W(x) - i<l+ — + ^  + ... + i ' i i v ' 2i n n2 H . ) g [ j ± i J _ i ) n t J L„r+1 2 i ' «r+l 2i y We say that X a is a rtn order subsequence iff a is a sequence of k indices. If xe X a and a is a sequence of r indices such that a=pj then we say that subrankT(y.)=]. We maintain the subsequences of each order in lexicographical order of their upper index. The sequences are represented by the following data structure: REPRESENTATION OF SEQUENCES: For each element, v , from the sequence X we have: dist(X,v) - position of v in the sequence X Let X be the main subsequence of the sequence X. For every subsequence X a we have: FIRST(X a ) - the pointer to the first element of the subsequence. Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 117 optimal weighted path length L A S T ( X a ) - the pointer to the last element of the subsequence. (If subsequence X « is empty then FIRST(X<X)=LAST(X a)=0). For a each subsequence X a of order t we have: S U C C ( X a ) - the pointer to the closest nonempty subsequence of order t following X a . P R E D ( X a ) - the pointer to the closest nonempty subsequence of order t preceding X a . The subsequences which differ only by last index are kept in an array (called a block) ordered according to the last index. For each subsequence of order smaller than t we have: D O W N ( X a ) - the pointer to the block of subsequences into which X a is divided. For each subsequence X a of order greater than zero (where zero is the order of whole sequence) we have: U P ( X a ) - the pointer to the subsequence of one order lower than the order of X a which contains the given subsequence. For every element we know its t subranks. INITIALIZATION: Assign n processors to every element. We sort the input sequence using Cole's parallel merge sort. For every element compute all its subranks. This can be done in 0(klog n) time using n processors, by k applications of binary search (performed for every element in parallel). Use the first subrank to divide sequences into first order subsequences. To compute functions FIRST and L A S T it suffices to compare the subrank of every element with the subranks of its neighbors. Compute (using the prefix sum computation) the number of nonempty subsequences preceding a given subsequence. Divide every nonempty first order subsequence into second order subsequences according to the value subrank2 and construct the pointer DOWN. Thus we obtain, for every nonempty subsequence, n second order subsequences (some of them possibly empty). Assign one processor for every n elements of the second order subsequence (say one of n processors associated with the first element of the subsequence of first order). For every Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 118 optimal weighted path length second level sequence construct the pointer UP (we can do it in O(l) time time with n2 processors). Since the number of first order subsequences preceding a given subsequence is known and every first order subsequence is divided into exactly n second order subsequences, we can treat second order subsequences as consecutive elements of some array. (We can compute the position of every second level subsequence in such an array in 0(1) time.) Thus we can use a prefix sum computation to compute, for every second order subsequence, the number of nonempty subsequences preceding it. Similarly we compute the subsequences of next orders, the corresponding functions FIRST, L A S T , UP, DOWN, and the number of nonempty subsequences of the given order preceding given subsequence. From the last information we can compute PRED and S U C C for subsequences of order t in the following way: Use an array, say A, and assign to A(i)the i m nonempty subsequence. For a subsequence X with index j in A do PRED(X):=A(j-l); SUCC(X):=A(j+l). The initialization step can be implemented in 0(klog n) time with « 2 C R E W processors. PAIR_ELEMENTS: To show the implementation of this procedure we first show how to compute in 0(t Irank(ui)-rank(u2)l )for any two neighboring elements u i , U2, the subranks of their parent, say u. But it is easy to compute in 0(t) time the value subrank(u) from the sequence subranki(u), subrank2(u),....,subrankt(u) and the opposite. Thus we can use the method presented for the « 6 k -processor algorithm. PAIR_ELEMENTS2(U): In this case we have only two elements to pair. We simply create a common parent for both of them and compute all subranks of the new element. PAIR_ELEMENTS 5(U): STEP 1,2 : AS in the n6k-processor implementation Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 119 optimal weighted path length STEP 3. Construct the representation for the sequence C. Let ui and u 2 be a pair of elements which are given a common father, say u. To construct the data structure of the new sequence C modify the data structure of sequence U by removing elements ui and u 2 and inserting element u. 3.1. Compute all subranks of every newly created element u. 3.2. Find, using pointers UP, the subsequence of the highest order, say s, to which both of uj, u 2 belong. If u belongs to a subsequence of order k+1 which was previously empty then build subsequences of orders s+2, ...,t (together with the pointers UP, DOWN). Since the sequence is a one-element sequence we can do it, for every new element, in O(s) time with n processors (using the information about subranks). STEP 4. Compute the function FIRST and L A S T for every level and every subsequence. Use the same method as in the initialization step.Then for every subsequence check (based on the values FIRST and LAST) whether it is an empty subsequence. If yes and if the higher level subsequence containing the given subsequence is also empty then remove this subsequence from the data structure. STEP 5. Compute the functions PREP and SUCC. Let INr(u) be the reference to the subsequence order r containing u. For any order r subsequence C 0 " of the sequence C do If FIRST(C a i)^0 then PREP(Cod):=INt(parenr(prec('U,left(nRST(Cod))) else if the subsequence U 0 " was represented in the data structure then PRED(C c d):= IN r (pare«r(LAST(PRED(U a i ))) else there is exactly one element, x, in the subsequence C a . Let xe C a l if i>j then PRED(Ca i)=INr(x) else PRED(Cai)=INr(pred(C,x)). Function SUCC can be computed similarly. MERGEj(C,V) (for i=3,6): This procedure is implemented as one or two insertion steps. If the inserted element has rank equal to the level of sequence into which it is inserted then it is added to the hierarchical data structure. Since the ranks of the element are known it can be done in O(k) time. If the rank of the inserted element is smaller or greater than the level of the sequence then the inserted element is added to the head or tail of the sequence. (Note that we never have more than two elements in a head nor more than one element in a tail). Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 120 optimal weighted path length MERGE5(C,V): Note that at this step neither of the merged sequences have a nonempty tail or head. Let U be the resulting sequence. We merge the sequences C and V in a top-down fashion: STEP 1. Perform merging on the lowest level of the hierarchy Using n processors, combine (for each j) VJ with O. If one of the subsequences is empty then UJ is represented by the nonempty one. If both VJ and Ci are nonempty then we call UJ an active subsequence of level order 1. Note that we may have at most n active subsequences. STEP 2. Propagate the result of Step 1 to higher levels of the hierarchy 2.1 .current_order:=l; 2.2.While current_order<t do For each active subsequence of the current order recursively combine (using n processors) the subsequences of the next order (use the pointer DOWN to find the proper block of subsequences). Let V a and C a be the merged subsequences. If current_order+\ = t then put the elements of V a before C a . If current order+1 <t and if one of the subsequences is empty then U a is equal to the nonempty sequence. Otherwise U a is an active subsequence of order current_order+l. current_order.=current_order+1; STEP 3. Compute the functions FIRST. LAST. PRED. SUCC for the lowest level. Use the same method as in step 4 of PAIR_ELEMENTS5. Theorem 4.20: A tree whose cost differs by at most from the cost of an optimal tree can be constructed in 0(k2log n) time using n2 CREW processors. Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 121 optimal weighted path length Proof: The algorithm is a modification of the n6k-processor algorithm in which we use n 2 processors and the time of each call of MERGE or PAIR_ELEMENT is multiplied by the depth of the hierarchical data structure. Thus the time complexity is 0(k2log n). The bound for the construction error follows from Lemma 4.19. • 4.5. Sequential interpretat ions of the 9 E A In the previous sections we presented parallel algorithms to construct an approximately optimal tree which are based on the idea of approximate sorting and merging. Here we show that the ideas developed in the previous sections can be also used to obtain linear time algorithms to construct an almost optimal tree. A natural sequential interpretation of the general construction scheme is to obtain an e-sorted sequence using an integer sorting algorithm and implement MERGE as standard merging procedure (recall Example 4.11). Since the cost of merging using the standard merging procedure is proportional to the sum of the lengths of the merged sequences, the total time which is spent on merging is O(n). To obtain a linear time implementation of the general construction scheme we must be able to compute ranks in linear time. Since a computation of the rank of a single element requires more than constant time this certainly cannot be done by computing the ranks of the elements of the sequence one after another. Assume that the ranks are bounded by cf(n) and that in linear time we can sort integers in the range [0,2cf(")]. Then we associate the value fw(vj)2c f( r t)l with element V j and sort the elements of the sequence according to this value. Now we are going to merge into this sequence, a sequence of so called boundary elements. Boundary elements are defined in such a way that elements between two consecutive boundary elements have the same rank. However we have to keep the number of boundary elements linear in the size of the input Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost optimal weighted path length page 122 sequence. On the other hand we would like to choose the boundary elements in such way that the difference between them is as small as is needed to distinguish two elements with different values rw(vj)2cf(w)~l. To satisfy both these condition we use a hierarchical approach similar to the one used in the previous section for the « 2 -p r 0 cessor algorithm. We first merge the sequence with a "sparse" subset of boundary elements and interatively add more boundary elements by merging more additional boundary elements into nonempty subsequences bounded by two boundary elements. Following this idea we can compute ranks in Ofrclog ^ ) time by the following algorithm: 1. Sort the sequence according to rw(v;)2cf(/l)l , 2. Merge the resulting sequence with the following sequence of boundary elements 1, 2 n , 2 n ,...,2 " . Let Xi be the resulting sequence. 3. i:=l; 4. while i < logCf^-l c): 4.1. Let X ' j + 1 be the sequence obtained from Xj by removing those boundary elements which have boundary elements immediately before and immediately after them; 4.2. Each boundary element belonging to X'j + 1 which has a real element immediately before it, defines a new boundary element equal to the geometric average of its value and the value of the closest boundary element which occurs in X ' i + 1 before the given boundary element. Denote by Bj + 1 the sorted sequence of these new boundary elements; 4.3. Obtain X i + 1 by merging X ' i + 1 and B i + 1 ; 4.4. i:=i+l; 5. Now every non-boundary element is between two boundary elements which are consecutive powers of two. Elements which are between 2X and 2 i + 1 have rank cf(n) - i. If we assume f(«)=log n and c=ll-2k we can use the integer sorting algorithm of Kirkpatrick and Reisch [KirRe84] which sorts integers in the range [0,« c] in 0(n(l+log c)) time. As a result we obtain a "^ T-sorted sequence. If we apply Q'CA with K(«)=2 klog n nP then we can compute the ranks of heavy elements in 0(k«) time with the help of the algorithm described above. This interpretation leads to the following theorem: Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 123 optimal weighted path length Theorem 4.21: A tree T such that AT ^ — 7 can be constructed in 0(k«) time. n2 Proof: It is obvious that the algorithm presented above runs in O(kn) time. The truncation error is at most —\—. It suffices to show that the construction error in this algorithm is at g most —k . Using the same technique as in the proof of Lemma 4.19 we can show that A 2j n2 2 25(I-0 2 25(1-0+2 < ——: andAo; 1 <——: • which implies the result. • 2i w 2k 210-2klogn 1 1 1 2'rt2k 2l0-2klog/i r If we assume a RAM with unbounded register capacity as our computation model then we can sort n integers in the range [0,2CW) in 0(n(l+log c)) time ([KirRe84]). If we assume c=7-2k, f(«)=n, and K(«)=2k«, then we can use the algorithm described at the beginning of this section to obtain a ^"-sorted sequence of heavy elements and to compute ranks of the heavy elements in O(krc) time. This construction leads to the following theorem: Theorem 4.22: A tree T such that AT < —^—r can be constructed in O(kzz) time on a 2«2 k RAM with unbounded register capacity. Proof: This uses exactly same techniques as in the proof of Theorem 4.21. • Like the parallel algorithms presented in previous sections, our sequential algorithms have been stated as explicit interpretations of the scheme. In the parallel setting we made an essential use of the fact that elements are divided into subsets according to their ranks. This allowed us to determine which elements can be processed in parallel. In the sequential setting the explicit computation of ranks is not necessary. In this setting the fact that the computation is naturally divided into phases corresponding to consecutive iteration of the "while" loop was helpful in the analysis of error but was not essential for the computation itself. In fact, if we restrict our attention to heavy elements only, the tree Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 124 optimal weighted path length produced by our algorithm that computes ranks explicitly is identical with the tree produces by linear time algorithm described in Section 4.1 applied to the approximately sorted sequence. 4.6. Summary Traditionally a level-by-level tree construction algorithm consists of d steps (where d is the height of the constructed tree) such that at step i the internal nodes on depth d-i are constructed. This approach, in particular, requires that we know the depths of all leaves of the constructed tree. However, if these depths are known, we can construct the corresponding tree in 0(log n) time with n/log n processors using the accelerated valley filling technique presented in Chapter 5. In this chapter, we presented a different approach to a level-by-level tree construction. In our approach, we assume that for each leaf v of the constructed tree we can compute value rank(v) which bounds from above the depth of the leaf in the constructed tree. During the i t n iteration of such a level-by-level construction each vertex which is on level d-i+1 either obtains a parent, which goes to level h-i, or is itself promoted to level d-i. The basic limitation of this method is that it can be used to obtain efficient parallel algorithms only for constructing trees of polylogarithmic height. However, even if the tree which we want to construct is potentially unbalanced, there exists a tree of polylogarithmic height which closely approximates the properties of the tree we are interested in. We have concentrated on parallel algorithms for constructing binary trees with almost optimal weighted path length. Since for many applications the weights of leaves are computed with finite precision or are assigned as the outcome of some experiment, and therefore already admit some error, this approach is justified. We approximate an optimal Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 125 optimal weighted path length solution with the help of a tree of logarithmic depth. The problem of finding a binary tree with optimal weighted path length admits a simple and elegant sequential 0(n log «)-time solution due to Huffman [Huf52]. The best currently known parallel algorithm for the problem is due to Atallah et. al ([AtaKosLarMilTen89]). It uses 0 ( l o g 2 « ) time and « 2/k>g n processors. With the parallel level-by-level technique described above we have been able to develop a family of efficient parallel algorithms for the relaxed version of the problem, in which only an approximately optimal solution is sought. time t(n) processors p(n) error 1. 0(log2n) n2 0 + 2. 0(log«) n 1 + 3. O(logn) n » L 0.172 J_ 4. 0(klog*rt log n) n 5. 0 (k 2 l og« ) n2 6 0 (k log 2 «) n2/log2n 4 - + 7. 0(k«) 1 8. 0 ( k « ) ! 1 n2 1_ k 1 2 n 2k Figure 4.2. The summary of results of Chapter 4 We summarize the results of this chapter and the related work in Figure 4.2 (* stands for results presented in this chapter, + stands for results obtained in or following from [AtaKosLarMilTen89]). In particular, the algorithm corresponding to the fourth entry in the table produces an exact solution if the weights of all leaves are bounded from below by 1 On aRAM with unbounded register capacities Chapter 4 : Parallel level-by-level tree synthesis - construction of binary trees with almost page 126 optimal weighted path length Al l of the algorithms presented in this chapter are interpretations of one algorithmic scheme. This makes it possible to estimate the error made by each of them using one universal lemma. The same analysis is applicable to the sequential algorithms presented at the end of the chapter. Obviously, one can propose different approximation algorithms based on the idea of approximate sorting and merging which are not interpretations of our algorithmic scheme. However, in general the accurate estimation of the error associated with an approximation algorithm is significantly more challenging than the formulation of such algorithms. For this reasons we see the formulation of the approximation scheme introduced in this chapter as being at least as significant as any of its instantiations tabulated above. Chapter 5: Valley filling technique and construction of minimax trees page 127 C H A P T E R 5 : V A L L E Y F I L L I N G T E C H N I Q U E A N D C O N S T R U C T I O N O F M I N I M A X T R E E S The parallel level-by-level tree synthesis method presented in Chapter 4 can be used to obtain efficient parallel algorithms for the construction of trees of polylogarithmic height. In this chapter we present a different tree synthesis technique which is applicable to weighted trees of arbitrary height. The technique, which we call accelerated valley filling, can be viewed as the parallel analogue of the method used in the T-C algorithm (the Hu-Tucker algorithm) ([HuTuc71], [Hu75]) for constructing alphabetic trees with optimal weighted path length. A simpler version of this parallel technique has been used in [AtaKosLarMilTen89] and we refer to the method used there as the basic valley filling technique. The technique basically consists of dividing the sequence of leaf weights into so-called valley sequences, and computing the parts of the tree corresponding to each valley sequence independently by performing 0(log n) iterations of what we call a valley filling step. During a valley filling step we construct a sequence of subtrees such that the sequence of weights of their roots has its number of valleys reduced by at least half. The basic idea behind the accelerated valley filling technique is to speed up the basic algorithm by replacing the iterative application of the valley filling step by one pipelined parallel step. We apply our technique to obtain an optimal algorithm for the problem of constructing minimax trees. Let V={v1,...,vM} be the set of leaves of a binary tree and w:V->N be a weight function. The (non-alphabetic) minimax tree problem takes a set of Chapter 5: Valley filling technique and construction of minimax trees page 128 leaves and a weight function w and constructs a binary tree which minimizes the cost function c(T) = max(w(v)+/-r(v)) where /-r(v) denotes the depth of the leaf v in the tree T. veV Similarly, the alphabetic minimax tree problem takes an ordered sequence of leaves and a weight function w and finds an alphabetic (ordered) binary tree which minimizes the value c(T). If W is a sequence of weights then we use C(W) to denote the cost of an alphabetic minimax tree whose leaves are weighted with the elements of W in the left-to-right order. Note that the weight function can be naturally extended to internal nodes by associating with an internal node the weight equal to the maximum of the weights of its children plus one. In this way, a minimax tree can be seen to minimize (over all trees with appropriate weighted leaf set) the weight of the root. We present optimal algorithms for both alphabetic and non-alphabetic minimax tree problem. There are several ways of generalizing the binary alphabetic minimax tree problem to t-ary trees. Kirkpatrick and Klawe [KirKla85] and Coppersmith, Klawe, and Pippenger [CopKlaPip86] presented linear algorithms for various versions of the t-ary alphabetic minimax tree problem. Our alphabetic minimax tree algorithm can be generalized to an 0(log «)-time n /log ^-processor algorithm for the t-ary alphabetic minimax tree defined as in [CopKlaPip86]. Minimax trees have several interesting applications [Gol76], [HooKlaPip84]. The complexity of the minimax tree problem has been studied in [Gol76], [KirKla85], [CopKlaPip86]. One can observe that in the sequential setting the techniques which can be used to construct trees with optimal weighted path length can be also used to construct minimax trees. In particular, Golumbic [Gol76] presented an 0 ( « l o g «)-time sequential algorithm for the non-alphabetic minimax tree problem which is an adaptation of Huffman's algorithm [Huf85] for constructing of trees with optimal weighted path length. Considering alphabetic versions of the two problems we observe that both binary alphabetic minimax trees and binary alphabetic trees with optimal (leaf) weighted paths Chapter 5: Valley filling technique and construction of minimax trees page 129 length can be constructed with the help of the T - C algorithm ([HuTuc71], [Hu73]) originally designed for the second of the problems. (The T-C algorithm requires 0(n log n) time so it does not lead to an optimal algorithm for constructing minimax trees). The two problems seem to have a different nature when a parallel setting is considered. In this chapter we present an 0(log n)-time rc-processors algorithm for constructing non-alphabetic minimax trees. Interestingly, as we have mentioned in Chapter 4, there does not currently exist a parallel algorithm to solve the problem of constructing trees with optimal weighted path length whose total work is 0(n 2 _ e). The algorithm of Atallah, Kosaraju, Larmore, Miller and Teng runs 0(log2n) in time using n2/log n processors on a CREW PRAM. In Chapter 4 an 0 ( log*« log «)-time n-processor CREW P R A M algorithm was presented which gives an approximate solution to this problem. We also present an 0(log rc)-time «/log rc-processor algorithm for constructing alphabetic minimax trees. In contrast the best currently known algorithm for constructing alphabetic trees with optimal weighted path length applies the parallel dynamic programming technique of Miller, Ramachandran, and Kaltofen [MilRamKar88] and requires 0 ( l o g 2 « ) time with roughly tfi processors. This algorithm solves in fact a more general problem, in which the internal nodes may also have weights. Atallah, Kosaraju, Larmore, Miller, and Teng [AtaKosLarMilTen89] presented an 0 ( log 2 «) - t ime n 2/log 2n processor algorithm which gives an approximate solution to this problem. Interestingly, our optimal parallel algorithm for constructing alphabetic minimax trees was motivated in part by the T - C algorithm for constructing alphabetic trees with optimal weighted path length. The alphabetic minimax tree problem can be also viewed as a generalization of the following problem of constructing the tree from a sequence of leaf depths: Given a sequence of integers l\,...,ln representing the depths of leaves of a binary tree construct the corresponding tree. One can prove that if in a minimax tree T the value w(vj)+/j(vi) (where Chapter 5: Valley filling technique and construction of minimax trees page 130 /j(vj) denotes the depth of the leaf Vj in T) is constant then the tree is unique. Consequently, the above problem can be reduced to that of constructing the minimax tree for the weight sequence ...,-ln. An 0 ( log 2 «) - t ime rc/log ^-processor CREW P R A M algorithm for the problem of constructing the tree from a sequence of leaf depths was presented by Atallah, Kosaraju, Larmore, Miller, and Teng [AtaKosLarMilTen89]. So, as a special case, our algorithm improves the last result. In addition to the accelerated valley filling technique mentioned above we make use of several existing parallel algorithms and design techniques to achieve our results. We start our presentation by outlining the basic ideas behind the valley filling technique. Then we present, what we call a level tree, a data structure which allows us to speed up the basic valley filling technique. We present an optimal algorithm which constructs such a tree. Finally we give an optimal algorithm which given a level tree constructs an alphabetic minimax tree. In the last section of this chapter we show how our results for alphabetic minimax trees can be applied to non-alphabetic minimax tree problem and the minimax tree problem for a real weight function. We also discuss t-ary minimax trees. 5.1. Valley Fil l ing Technique Consider the bottom-up construction of a weighted tree. At each stage of such a construction we are dealing with a sequence of weights of roots of subtrees of the constructed tree called a construction sequence 1 . Our initial construction sequence is w(v0),w(v1),...,w(vn),w(vn + 1) where w(v0)=w(vn + 1)=co .2 The term "construction sequence" as well as "valley sequence" is taken from [Hu75]. We thing of oo as an integer which is at least equal to the weight of the root of a minimax tree for the sequence w(vj),...,w(v n). Chapter 5: Valley filling technique and construction of minimax trees page 131 A subsequence u k ,u k + i , . . . ,u m of a construction sequence is called a valley sequence if it is a bitonic sequence, where a bitonic sequence is defined to be a sequence which is first nonincreasing and then nondecreasing. An element Uj is called a maximal element of a valley sequence u k , u k + 1 , . . . , u m iff u k = u k + 1 =....= Uj or u; = U j + 1 =...= u m . The weight of the maximal elements of a valley is called the level of the valley. The observation that every construction sequence can be divided into valley sequences provides the basic idea behind the basic valley filling technique: BASIC VALLEY FILLING ALGORITHM while the construction sequence contains more than one element of weight less than infinity do: (i) divide the current construction sequence into valley sequences; (ii) for every valley build in parallel a forest of trees such that the leaves of each forest are the elements of the subsequence of the construction sequence forming the valley and the roots have weights equal to the level of the valley. The process of replacing a valley sequence by a sequence of roots of trees whose weight is equal to the level of the valley is called filling the valley and each repetition of the while loop is called a valley filling step (compare Figure 5.1) Since at each valley filling step the number of valleys is reduced by at least half, the algorithm performs 0(log m) valley filling steps in total, where m is the number of valleys in the initial construction sequence. One can implement each valley filling step in 0(log n) time using «/log n processors (such an algorithm for the special case when the input sequence represents a leaf depth pattern was presented in [AtaKosLarMilTen89]). This leads to an 0(log m log «)-time rt/log n -processor algorithm. Chapter 5: Valley filling technique and construction of minimax trees page 132 Figure 5.1. A valley filling step The basic idea behind the accelerated valley filling technique is to speed up the basic algorithm by avoiding 0(log m) distinct iterations. To this end we precede the construction of a minimax tree by a preprocessing step in which we construct what we refer to as the level tree. This tree contains, in particular, information about the number of internal nodes of the constructed tree which occur on certain distinguished levels. This information allows us to replace the iterative application of step (ii) by one pipelined parallel step. 5.2. Level tree and its construct ion We start our description of the level tree with the following geometric construction (see Figure 5.2) : Represent the sequence of weights corresponding to the left-to-right order of the leaves of a constructed alphabetic minimax tree by a polygonal line : for every element Vjdraw on the plane the point (i,w(vj)), and for every i=l,..., n-l connect the points (i,w(vj)) and (i+l,w(vj+1)). For every Vj such Vj > V j + 1 (resp., VJ > Vj.i) draw a horizontal line going from (i,w(vj)) to its right (resp., left) until it hits the polygonal line. The intervals defined in such a way are called level intervals. We also consider the interval (oo ,oo) and the degenerate intervals ((i,w(vj),(i,w(vj)) as level intervals. Let e be a level interval. Note that at least one of e's endpoints is equal to (i,w(v;)) for some index i. If Chapter 5: Valley filling technique and construction of minimax trees page 133 only one endpoint coincides with such a point then we call the leaf Vj the defining leaf for e. If both endpoints of e coincides with such points, then we choose the leaf corresponding to the left end of e as the defining leaf for e. Thus for every level interval e there exists a unique defining leaf which we denote by def(€). We define the level of a level interval to be equal to the weight of its defining leaf. Figure 5.2. Level intervals Note that a minimax tree can be embedded in the plane in such a way that the root of the tree belongs to the level interval ( o o , cc) and that internal vertices whose weights are equal to the weight of one of the leaves lie on the horizontal line going through this leaf. Furthermore, if there is a tree edge cutting a level interval, then adding a vertex subdividing this edge to the minimax tree does not increase the weight of the root. By this observation we can consider minimax trees which can be embedded on the plane such that no edge intersects a level interval other than at an endpoint (see Figure 5.3). Chapter 5: Valley filling technique and construction of minimax trees page 134 Figure 5.3. Embedded minimax tree A level tree (see Figure 5.4) for a given sequence of weights is an ordered tree whose nodes are in one-to-one correspondence with the level intervals defined as above. For a node v define its parent to be the internal node which corresponds to the closest level interval which lies above the level interval corresponding to v. The left-to-right order of children of an internal node corresponds to the left-to-right order of the corresponding level intervals in the plane. Figure 5.4. A level tree Chapter 5: Valley filling technique and construction of minimax trees page 135 We use the level tree to compute, for every level interval, of the number of nodes of the constructed minimax tree which belong to this level interval (assuming the embedding as described above). To this end, for every node u of a level tree we define load(u) to be equal to the number of nodes of the constructed minimax tree which belong to the level interval corresponding to u. We show how to compute this function using the tree contraction method. 5.2.1. Construction of level tree To construct the level tree we have to establish the "parent" relation and the ordering of every internal node's children. It is easy to observe that to find the parent of a node corresponding to a level interval e, it suffices to find the strictly dominating successor and predecessor of def(e). Recall that the strictly dominating successor (resp., strictly dominating predecessor) of an element VJ in the sequence w(vo),w(vj),...,w(vn+1) is the element Vj satisfying w(vj)<w(vp that is closest to the right (resp. to the left) of V j . Observe that the parent of the node associated with a level interval e which is different than (co ,oo), is the node associated with a level interval defined by the dominating predecessor or successor of def(e) (whichever has smaller weight). Thus the "parent" relation can be established using the solution to the ASDN problem presented in section 2.6. To construct lists of children of internal nodes, every node has to decide whether it is the first or the last node on a list of children and (if it is not the last node on a list) find its successor on the corresponding list. To solve this problem we use the solution to the A D N problem presented in the previous chapter. Observe that to construct lists of children it suffices to compare, for every node u, the weight of def(u) with the weight of the dominating successor of def(u) (see step 3 of the algorithm). Chapter 5: Valley filling technique and construction of minimax trees page 136 Let us present now a more detailed description of the algorithm to construct the level tree for a given input sequence of weights. Assume first that we have n processors and that the sequence of the weights of the leaves (in left-to-right order) is given in an ^-element array W. We assign one processor to each element of the array W (and therefore to each leaf). We also assign the processor assigned to def(t) to the level interval e. So each processor is assigned to at most three nodes of the constructed level tree. S T E P 1: Solve the A D N and ASDN problems for the sequence W. We use the optimal algorithms for the A D N and ASDN problems described in the previous chapter. Let ds(v[), rfp(vj), sds(v0, and sdp(v{) be the dominating successor, dominating predecessor, strictly dominating successor, and strictly dominating predecessor of the i t n element, respectively. STEP 2: Establish the parent relation For every level interval ej let yj = sdp(def(e-J) if sdp(def(ej) <sds(def(e[)) and yi = sds(def(&\)) otherwise. - Define the parent of the level tree node which corresponds to the level interval ej to be the node which corresponds to the (nondegenerate) level interval defined by yj which lies above ej. S T E P 3: Define the ordering of the children For every level interval check whether the tree node associated with it is the first (or the last) child of its parent (in the left-to-right order). Observe that Uj is the first child of some internal node if one of the following holds: a) Uj corresponds to a leaf Vj (a degenerated level interval) such that w(vj_i) > W(VJ) (see Figure 5.5 a), b) Uj corresponds to a nondegenerate level interval e such that w(dp(def(e))) > w(def(e)) (see Figure 5.5 b). The last element of the sequence can be determined in a similar way. Chapter 5: Valley filling technique and construction of minimax trees page 137 For any element Uj which is not the last element of a list of children, the next element on the list is defined in the following way: - if Uj is a leaf and it is not the last element of a list of children then Uj is the left end of a level interval and the internal node corresponding to this level interval follows Uj on the list; - if Uj is an internal node and it is not the last element of a list of children then the right endpoint of the level interval to which Uj corresponds coincides with a leaf node. This leaf node follows u; on the list of children. a) b) Figure 5.5. Introducing the ordering of children By Theorem 2.14, step 2 of the algorithm can be implemented in 0(log n) time with ra/log n processors. The remaining steps can be performed in constant time with n processors. Thus they can be computed in 0(log n) time with «/log n processors by a straightforward simulation of log n processors by one processor. 5.2.2. Computing the load function Now, for every internal node u we want to compute the value load(u) equal to the number of nodes of the minimax tree which belong to the level interval corresponding to u. Chapter 5: Valley filling technique and construction of minimax trees page 138 Lemma 5.2 : The function load(\x) can be computed for every internal node u in 0(log n) time with n/log n processors. Proof : If u is a leaf then load(xx) = 1. Assume that u is an internal node. Let u^. . . ,^ be the children of u. Let Au denote the minimum of the value ["log nl and the difference between the level of the level interval corresponding to node u and the level of the intervals corresponding to its children. It is easy to confirm that / (^u)=r/^ (tti)+"-+/ofld(uk)i 2Au We compute the function load(u) for every internal node with the help of an algorithm which is an interpretation of a 1B-Cl tTt3 scheme. In order to apply the scheme we have to replace the level tree by a binary tree. Let T' be a tree obtained from the level tree by replacing each internal node, u, by a sequence of nodes u',u,i,...,u'j f.i as on Figure 5.6 (ui,...,Uk are children of u). We assign Au'j=0. Then it is easy to see that load(u)=load(u'). u' Figure 5.6. Binarization of a level tree We associate the function foAu(x>y) with every internal node u of the binary tree. To do this we build a table of size flog nl which keeps the value 2) for every j = 1, Hog n~\. Such a table can be build in 0(log n) time sequentially. Then, for every internal node, the index of the function associated with it can be computed in constant time. In this Chapter 5: Valley filling technique and construction of minimax trees page 139 way we have obtained the bottom-up tree computation problem considered in Example 2.7. As was shown in section 2.5.2 this can be solved by an interpretation of the tB-Ct cT£> scheme in 0(log n) time with n/log n processors • 5.3. A n opt imal a lgor i thm for alphabetic min imax tree prob lem Consider a node u of a level tree. With each such a node we have load(u) associated nodes of the minimax tree which we want to construct. Let us call those load(u) nodes the group of nodes associated with u. If u is an internal node of the level tree then the sequence of groups of nodes associated with children of u (in left-to-right order) is called the block of nodes associated with u. Let g(u) be the number of the elements in the block associated with u. A balanced forest with n nodes and m roots is a forest of m trees and total number of leaves equal to n which has the minimal depth (where by the depth of a forest we mean the maximum of the depths of the trees in the forest). 1 load(u) U group of nodes assicated with u u 1 u u k 2 a) b) 1 load(i^) j^l block of nodes associated with u Figure 5.7. Construction of a balanced forest a) node u in a level tree b) corresponding part of the constructed minimax tree Chapter 5: Valley filling technique and construction of minimax trees page 140 In order to construct the minimax tree for every internal node u we have to construct the group of load(u) nodes, determine the block of g(n) nodes associated with u, and build a balanced forest with g(u) leaves and load(u) roots (compare Figure 5.7). To minimize the number of internal nodes of the constructed minimax tree we remove internal nodes of degree one. This can be summarized in the following algorithm: STEP 1: Construct a table NODES such that each element of the table corresponds to one  node of the constructed tree. Furthermore nodes from the same block have associated  consecutive positions in the table. For any node v from the level tree let group_index(v) denote the index in the table NODES of the first element of the group associated with v. Similarly define the block_index(v) as the index of the first element of the block associated with v. 1.1. Recall that every internal node of the level tree keeps the lists of its children. Concatenate these lists in any order (say using the Euler Tour Technique [TarVis84]). Let L be the resulting list. The order of the elements in the list defines the order of storing blocks in the table NODES. 1.2. For every node v in L compute its group_index(v) by summing (using a prefix sum computation) the values load(u) for all nodes u preceding v on the list L . The sum over all elements u in L of values load(u) gives the size of the table NODES. 1.3. For every node v compute its block jndex (v) that is the group_index of the first child of v. STEP 2: For every element of the table NODES compute the index of its parent and for  every node corresponding to a leaf of the minimax tree construct the pointer to the element  of the input sequence labelling the given node. 2.1. Divide the table NODES into n/log n segments of length log n each, and associate one processor to each segment. Note that each segment can contain a number of blocks. Within every segment use a sequential linear algorithm to build a balanced forest for Chapter 5: Valley filling technique and construction of minimax trees page 141 each block of size at most log n which is entirely contained in the given segment or intersects the right boundary of the segment. 2.2. All remaining blocks have length mj>log n and as a consequence of step 2.1. each block has assigned Lmj/log n] processors. We can decide which processor is assigned to which block as follows: Every processor decides by a sequential search whether it is assigned to an interval containing the beginning of a block. If so it writes one in its local memory. Then a prefix sum computation gives, for every , the number of the block it is assigned to. With this processor assignment we can finish the computation in 0(log n) time using standard techniques (i.e. for each block use a sequential linear time algorithm to construct at most m subtrees of |~log n \ leaves and a parallel algorithm to construct the remaining nodes of the tree). STEP 3: Remove the internal nodes with only one child using an interpretation of B— Cl cTG scheme. Identify maximal chains of internal nodes with only one child. We consider the lowest level vertex in a chain as the beginning of the chain. Given n processors it is easy to determine in constant time for every internal u whether u belongs to such a chain and if so who is its predecessor and successor (if any). Since one can simulate log n processors by one in using 0(log n) time this can be implemented in 0(log n) time with n/log n processors. To remove internal nodes of degree one we have to compute for the first element on every chain the corresponding last element. This can be done using the following interpretation of the (full) Ift-Cl cTG scheme. We assume that the only child of an internal node of degree one is the left child.We add a right child to each such node. Let 9={idl id(x)=x}u{labels I labelj(x)=i}, 0F'={id'l id'(x,y)=x}u{zero I zero(x,y)=0}. It is easy to confirm that 9 and y satisfy axioms (i)-(ii) of B - C l <TG scheme with P=l and T=0(1). We associate with every edge (v,parent(v)) such that v has degree two in the original tree or is a leaf the function labelv and the function id with all other edges. With every internal node of degree 2 in the original tree we associate the function zero and with internal nodes whose degree in the original tree is one we associate the function id'. The result of this bottom-up Algebraic Tree Computation is that for every node which has degree two in the original tree, the values associated with the edges leading to its children define the addresses of its new children. Chapter 5: Valley filling technique and construction of minimax trees page 142 Since all steps of the algorithm can be implemented in 0(log n) time with n/log n processors, this yields the following theorem: Theorem 5.3 : The binary alphabetic minimax tree problem can be solved in 0(log n) time with n/log n processors. 5.4. Other versions of the min imax tree problem 5.4.1. t-ary alphabetic minimax trees There are several ways of generalizing the binary alphabetic minimax tree problem to t-ary trees. Kirkpatrick and Klawe [KirKla85] considered regular t-ary alphabetic minimax trees (assuming that the number of leaves is equal to 1 mod (t-1). Coppersmith, Klawe, and Pippenger [CopKlaPip86] considered alphabetic minimax trees of degree (at most) t. As is shown in these papers, both types of trees admit linear time sequential construction algorithms. It is easy to confirm (see Figure 5.8) that the best regular t-ary alphabetic minimax tree may have a higher cost than some at most t-ary alphabetic minimax tree for the same input. Figure 5.8. A regular t-ary alphabetic minimax tree and a t-ary alphabetic minimax tree Coppersmith, Klawe, and Pippenger [CopKlaPip86] also addressed the question of minimizing the number of internal nodes in an alphabetic t-ary tree. The number of internal 4 2 2 11 3 1 12 2 5 2 2 1 1 3 1 1 2 2 Chapter 5: Valley filling technique and construction of minimax trees page 143 nodes of a t-ary tree is bounded from below by [~(rc-l)(t-l)l. Coppersmith, Klawe, and Pippenger [CopKlaPip86] gave a linear time algorithm which converts an alphabetic t-ary minimax tree into an alphabetic t-ary minimax tree with the number of internal nodes bounded by L(n-l)(t-l)+(t-2)(n+l)/3(t-l)J. However the tree obtained by this compaction process is still not guaranteed to minimize the number of internal nodes. It is easy to convert our alphabetic binary minimax tree algorithm to an algorithm which constructs an alphabetic t-ary tree. It suffices to replace the value 2 A u in the proof of Lemma 5.2 (the recurrence for the load function) by t A u and the construction of a binary balanced forest in step 1 of the tree construction algorithm by a balanced t-ary forest. Here we sketch a parallel minimax tree compaction algorithm which converts a minimax tree into tree of the same cost with a possibly smaller number of internal nodes. The resulting tree satisfies the same properties as the tree which results from the compaction algorithm of Coppersmith, Klawe, and Pippenger [CopKlaPip86]. As in [CopKlaPip86] we define a leaflet to be an internal node that has only leaves as children and has degree less than t. The tree produced by the compaction algorithm satisfies the following conditions: (1) Each internal node either has degree t or is a leaflet (2) No two adjacent leaves are the children of different leaflets. (3) Each leaflet has degree at least two. The upper bound on the number internal nodes of a t-ary tree satisfying conditions (l)-(3) is given in the following lemma: Lemma 5.6 [CopKlaPip86]: If T is a tree with n leaves satisfying conditions (1), (2), and (3), then t has at most L(«-l)(t-l)+(t-2)(n+l)/3(t-l)J internal vertices. Chapter 5: Valley filling technique and construction of minimax trees page 144 Similar to the sequential algorithm of Coppersmith et.al., our parallel algorithm compacts the tree in two steps. We first present a high level description of these two steps and then present them in more detail. During the first step we compact internal nodes which are not leaflets. The sequential algorithm of Coppersmith et. al. compacts such nodes by traversing them one after another in preorder. To allow for parallel computation, we cover the tree by disjoint paths and compact the nodes on each path independently. Let p = u i ,...u r be a path of internal nodes in the tree T (u^ is the highest level vertex on the path). To compact p means to replace it by a path p' such that the following conditions are satisfied: (pl) the children of nodes of elements on a path p becomes children of nodes on path p'; (p2) all but the last element of p' have t-1 children which are not on p' and the last element of p' has at most t and at least 2 children; (p3) the cost of the tree T' obtained from the tree T by replacing by the path p' the path p is at most equal to the cost of T; (p4) T and T' have the same order of leaves. In our algorithm we compact a path by moving the children of vertices on the path from the end of path towards the beginning. To ensure condition (p4) we use the following algorithm (compare Figure 5.9). For each vertex v on the path p we define its sequential number, as its distance from the end of the sequence. With each child of v which does not belong to the path p, we associate its path index defined as follows: if a child is a left sibling of a node on the path p its path index is equal to the negative of the sequential number of its parent otherwise it is equal to the sequential number of its parent. Chapter 5: Valley filling technique and construction of minimax trees page 145 -4 / -4\ oN o -i -4 -4 4 -3 A A A A - 2 - 1 1 1 A A A A 0 0 A A -4 -4 -3 4 A A A A - 2 - 1 1 1 A A A A 0 0 Figure 5.9. Path compaction (t = 5) Chapter 5: Valley filling technique and construction of minimax trees page 146 THE P A T H COMPACTION ALGORITHM STEP 1: Compute sequential numbers. For each node v on the input path p and for each child of v which does not belong to p compute (using a prefix sum computation) its path index. STEP 2: Concatenate. Concatenate sequences of children of nodes from the path p, excluding nodes which belong to p. We divide the resulting sequence into blocks of size t-1 except for the last block which may be of size at most t. STEP 3: Sort. Within each block we sort elements according to their path index. STEP 4: Construct the resulting path p'. Cnstruct path the p' by creating one internal node per block.The children of a node from p' are defined as follows: If a node v corresponds to the last block then its children are the nodes in this block. Otherwise, in addition to the nodes in the corresponding block, v is given the internal node corresponding to the next block as its child. The order of children agrees with their order in the corresponding block, and the internal node corresponding to the next block is inserted between the children of negative and positive path index. Assume that a tree T has been partitioned into vertex disjoint paths. Then the tree resulting from T by the compression of all paths satisfies conditions (1) and (3) at all internal nodes except at the nodes resulting from compacting a path to a single node. To ensure conditions (1) and (3) for all internal nodes we iterate the compaction step for different partitions of the tree into paths. During the second step of the algorithm we compact leaflets. We construct monotone lists of leaflets and within each such list we move (if possible) all but one children from leaflets of smaller weights to leaflets of greater or equal weight. If a leaflet is left with one child this child replaces the given leaflet in the sequence of children of the parent of the leaflet. To do this we iterate a compaction step two times. During the first iteration we consider maximal nondecreasing sequences of neighboring leaflets, and compact the Chapter 5: Valley filling technique and construction of minimax trees page 147 leaflets on these sequences (see Figure 5.10). During the second iteration we consider maximal nonincreasing sequences of neighboring leaflets and compact the leaflets on these sequences. Thus the tree compaction algorithm can be described as follows: T H E TREE COMPACTION ALGORITHM: STEP 1 : compaction of internal nodes Repeat the following compacting step t times: 1. Partition the tree into independent paths by choosing, for any node v which has a nonleaf child, its first nonleaf child as its path successor. 2. Compact in parallel all the paths computed in the previous step. STEP 2 : compaction of leaf nodes 1. Construct lists of leaflets as follows: For each leaflet v, check whether it is adjacent to a leaflet with greater or equal weight. If so, this leaflet follows v on the list. Let Z1; be the number of leaflets on the i m list and Z2} be the sum of their children. 2. Let ki=[~(/2i - ll[ ) / (t-l)l. For each list divide the last / 2j - lli + kj elements of the sequence of children of the leaflets of the list into blocks of size t (except possibly for the first block). These blocks of leaves became the new children of the last kj leaflets. The remaining elements replace the remaining leaflets (we have one element per leaflet). 3. Repeat steps 1 and 2 replacing nondecreasing lists by nonincreasing lists and switching the meanings of adjectives "last" and "first". b a Figure 5.10: Leaflets compaction (t = 4) Chapter 5: Valley filling technique and construction of minimax trees page 148 Lemma 5.5 : The algorithm described above compacts the input alphabetic minimax tree to a minimax tree satisfying conditions (l)-(3). Proof: It is obvious that after Step 1, the condition (3) is satisfied. An easy inductive argument shows that after the i-th iteration of the path compaction step each node which has less than t children and is not a leaflet has at least i children, and the first i of them (in the left-to-right order) are leaves. To see that (1) and (3) are satisfied after step 2 of the algorithm first note that step 2 never changes the number of children of a node which is not a leaflet. Step 2 consists of two compacting steps each of which consists of shifting children of leaflets of smaller weight to leaflets of greater weight. There is at most one leaflet left on each list of adjacent leaflets. Thus condition (2) is also satisfied. • 5.4.2. Non-alphabetic t-ary minimax trees The main result of this section is based on the following lemma: Lemma 5.6: The cost of a non-alphabetic minimax t-ary tree is equal to the cost of the alphabetic minimax tree whose leaves form a sorted sequence. Proof: We use the following result proven by Golumbic [Gol76] : If T is a minimax tree then c(T)= riogtStw(v)l. (5.7) veV It follows immediately that replacing t elements of weight w by one element of weight w+1 does not change the cost of the minimax tree. Also, if the number of minimal elements is smaller than t, then replacing them by an element of the weight greater by one does not change the cost of the minimax tree. The second fact follows from the observation that if a subset of the set of elements of minimal weight share a common parent with an element of Chapter 5: Valley filling technique and construction of minimax trees page 149 greater weight, then we can insert an internal node which becomes a new parent of the minimal nodes and a child of their old parent. This justifies the following algorithm for the construction of a (non-alphabetic) minimax tree: 1. Sort the leaves in nonincreasing order of their weights. Let W be the resulting construction sequence. 2. While there are more than t elements in the construction sequence do: Let w be the weight of the last element of the sequence. If t or more elements have weight w replace the first t elements of weight w by a common parent. Otherwise replace all elements of weight w by a common parent. 3. If more than one element remains, construct a common parent for all remaining elements It is easy to observe that the current construction sequence remains sorted as an invariant of the above algorithm. Thus the algorithm constructs an alphabetic tree (for the sorted sequence of leaf weights) whose cost is equal to the cost of a non-alphabetic minimax tree. • By this result and the results of the previous section we can construct a non-alphabetic (integer) minimax tree in 0(log n) time with n CREW processors using the parallel sorting algorithm of Cole [ C 0 I 8 6 ] . It is also worth noting that in the case of an alphabetic minimax tree with leaf weights in sorted (say nonincreasing) order, one can give a parallel algorithm which minimizes the number of internal nodes. We precede the sketch of such an algorithm with a number of definitions and observations. A maximal subsequence of elements Uj,uj+i , . . . ,Uj + k of equal weights such that W(UJ.I ) > W(UJ) is called a tread. A tread is called a short tread iff the number of elements in the tread is less than t. Otherwise it is called a long tread. A monotone sequence, all of whose treads have length at most t, is called a slope. A monotone sequence without long treads is called a cliff. Chapter 5: Valley filling technique and construction of minimax trees page 150 A maximal sequence u i + 1 , . . . , u i + t , u i + t + 1 , . . . , u i + ^ such that w(ui+l)=-=w(ui+t-l)> w(u i + ( t. 1 ) + 1)=w(u i + ( t. 1 ) + 2)=...=w(u i + 2( t.i))=w(u i)-l, w (Mr- l ) ( t - l )+ l ) = w ( u i+ (r - l^ and w(uj) < W(UJ.I) is called a stair. • " * t-1 : t Figure 5.11. A stair Lemma 5.8 (tread cutting lemma): Let U be a construction sequence containing a long tread Uj,Uj+i,...,Ui+k such that W(UJ_I) >w(uj), and let k+1 = st+q (0<q<t). Let U' be a construction sequence obtained from U by replacing each of the subsequences ui+pt'ui+pt+l>"->Ui+pt+t-l>P-0>".,s-l by a common father u p ' of weight W(UJ)+1. Then C(U) =C(U'). t t . . . t Figure 5.12. Treads cutting Proof: Immediately from equality (5.7) • Lemma 5.8 (stair climbing lemma): Let U be a sequence containing the stair w(u i + 1), . . . ,w(u i + t),w(u i + t + 1), . . . ,w(u i + r t ), . . . . ,w(u i + ( r . 1 ) t + 1 ). . . ,w(u i + r t ),w(u i + r ( t . 1 ) + i) and Chapter 5: Valley filling technique and construction of minimax trees page 151 let U* be a sequence obtained from U by replacing the stairs by the tree T presented in Figure 5.13. Then C(U)=C(U'). t Figure 5.13. Stair climbing Proof: This follows from r applications of the tread cutting lemma. • Lemma 5.9. (tread climbing lemma) Let k be the length of the longest long tread in the construction sequence. Then after flog tkl applications of the tread cutting lemma the input sequence is reduced to a slope. Proof: Let mj be the length of a maximal tread after i applications of the tread cutting lemma. After the i+l s t application of the tread cutting lemma we have mj < L -y-rJ + t-1. This follows from the fact that at most t-1 elements from a tread do not obtain a parent, and there are at most new nodes coming from the tread below to the tread above it. Thus after flog tkl applications of the tread cutting lemma mr] o g k"| <t. • Lemma 5.10 (slope climbing lemma). Let U be a sequence forming a slope. Then the application of the stair climbing lemma to all stairs of the slope reduces the slope to a cliff. Proof : By the maximality condition in the definition of stairs, the root of a tree which replaces a stair cannot be a part of a long tread. Since all long treads are removed as the Chapter 5: Valley filling technique and construction of minimax trees page 152 result of stair climbing, and no new long treads are created, the resulting sequence forms a cliff. • Lemma 5.11. (cliff climbing lemma): Let U = w(ui). . . ,w(u r ( t _i) + j), where 1 < j < t, be a cliff. Then C(U) is equal to the cost of the tree created as in Figure 5.14. Figure 5.14. Cliff climbing Proof: This follows from the immediate observation that the cost of this tree is equal to w(ui )+l , and that this is a minimax tree for the sequence U. • The following algorithm for constructing a non-alphabetic minimax t-ary tree which minimizes the number of internal nodes is an immediate consequence of the above lemmas and Lemma 5.6: 1. Sort the input sequence of weights applying Cole's sorting algorithm; 2. Apply the treads climbing lemma to reduce the input sequence to a slope; 3. Apply the slope climbing lemma to reduce the slope obtained in step 2 to a cliff; 4. Apply the cliff climbing lemma to the cliff obtained in step 3. It is straightforward to implement steps 2-4 of the algorithm in 0(log n) time with n /log n processors (use Brent's pronciple to reduce the number of processors of an obvious implementation of step 2). Since all but (possibly) one internal nodes of the tree have t children the tree constructed by the above algorithm minimizes the number of internal nodes. Chapter 5: Valley filling technique and construction of minimax trees page 153 5.4.3. Minimax trees with real weights Kirkpatrick and Klawe [KirKla85] showed that the alphabetic minimax tree problem for real leaf weights can be reduced to 0(log n) instances of the integer version. Let W=w 1,...,w n and a p w ^ w j . Define W(aj) to be the following (integer) sequence of weights r w r ajl, Tw2- a ^ l , T w n - ajl. Let bi, b n be the number aj rearranged into ascending order and let brj= b n. The reduction is based on the following lemma [KirKla85]: Lemma 5.12 [KirKla85]: Let j be such that C(W(bj))+bj = min{ C(W(bi))+bil 1 < i < n}. Then: (a) C(W) = C(W(bj))+bj, and a minimax tree for C(W(bj)) yields an minimax tree for C(W); (b) if i < j then C(W(bi)) > C(W(bj)); (c) C(W(b0)) - C(W(bn)) =1. The proof technique used in [KirKla85] also applies to all the types of minimax trees considered in this chapter. This immediately leads to 0(log2n)-time, n/log n-processor (or an 0(log n )-time n 2/log ^-processor) parallel algorithms for the alphabetic and non-alphabetic minimax tree problems. 5.5. Summary In this chapter, we identified a parallel tree synthesis technique called the valley filling technique. The technique is applicable to the construction of weighted trees where weights are derived from a well ordered domain. The technique basically consists of the iterative application of a valley filling step in which the sequence of weights is divided into so-Chapter 5: Valley filling technique and construction of minimax trees page 154 called valley sequences, and then the parts of the tree corresponding to each valley sequence are computed independently. As the output of a valley filling step we obtain a sequence of rooted trees. The corresponding sequence of weights of the roots of these trees forms the input for the next iteration of the valley filling step. The idea of performing independent computation within a valley sequence probably originates with the T-C algorithm (the Hu and Tucker algorithm) for construction of alphabetic trees with optimal weighted path length ([HuTuc71], [Hu75]) Later Atallah et. al. [AtaKosLarMilTen89] used an independent computation within valley sequences (referred to there as "fingers") for their 0(log2n)-time rt/log n -processor algorithm to construct the tree from a given sequence of depths of leaves. The basic idea behind the accelerated valley filling technique is to speed up the basic algorithm by replacing the iterative application of the valley filling step by one pipelined parallel step. Towards this end, our algorithm contains a preprocessing step in which it precomputes the sequence of weights of the roots of the subtrees which will be used to fill any particular valley. This is done based on the result of a bottom-up Algebraic Tree Computation before corresponding subtrees are constructed. Then it remains to construct these subtrees and glue them together into the resulting tree. The accelerated valley filling technique is applied to obtain an 0(log n)-time /i/log n -processor algorithm to construct the (integer) alphabetic minimax tree. Since the problem of constructing the tree from a given a sequence of leaf depths can be formulated as a minimax tree problem, this improves, in particular, the result of Attalah et. al. mentioned above. We show that our optimal algorithm to construct alphabetic minimax tree can be used to obtain an 0(log «)-time ^-processor algorithm for non-alphabetic minimax trees. In fact, if the input sequence is sorted then only 0(log n) time and n/log n processors is required. (Observe that the problem is as least as difficult as integer sorting.) We present a 0(log n) time ^-processor algorithm to construct a t-ary non-alphabetic minimax tree Chapter 5: Valley filling technique and construction of minimax trees page 155 minimizing the number of internal nodes. Finally, we show an 0(log n) time n /log n processor algorithm which reduces the number of internal nodes of an alphabetic t-ary minimax tree. This algorithm parallelizes the incremental sequential algorithm of Coppersmith, Klawe, and Pippenger [CopKalPip86] using a path compaction technique. Chapter 6: Concluding remarks page 156 C H A P T E R 6 : C O N C L U D I N G R E M A R K S In this thesis, a number of parallel techniques are presented for efficient construction of certain families of trees (cf. chapters 3-5). Along with these tree construction techniques, a number of parallel techniques are developed which have broader applications (cf. chapter 2). These techniques are illustrated with new parallel algorithms to construct various types of trees, with concrete results summarized at the end of each chapter. One objective of this final chapter is to reconsider the problems discussed in the thesis from a different perspective. For a large part of the thesis, we have been dealing with the problem of the parallel construction of trees which are optimal with respect to some cost function. Many such optimization problems can be solved using the parallel dynamic programming technique developed by Miller, Ramachandran, and Kaltofen [MilRamKal86]. The basic hmitation of this technique is its high processor cost. The technique (when applied to construction of optimal weighted trees) generally involves iterative multiplication of rc2 x « 2 matrices and thus requires M(n 2) (by current knowledge roughly rc6) processors. However parallel dynamic programming technique remains a basic tool for constructing optimal trees, even for problems which can be solved optimally by sequential algorithms which do not use dynamic programming. Sometimes one can exploit the special structure of matrices associated with a given problem and in this way reduce the processor cost ([AtaKosLarMilTen89]). In our approach we have been looking for solutions which completely avoid dynamic programming. Chapter 6: Concluding remarks page 157 A technique which can accomplish this is to relax an optimization problem and search for almost optimal solutions. This allows us to confine our attention to a restricted family of trees (in our case to trees of polylogarithmic depth) and design algorithms which relay on the structure of the trees in the family. This approach has been taken in Chapter 4 where we consider almost optimal solutions to the problem of constructing trees with minimal weighted path length. We present a whole family of parallel algorithms naturally related to the Huffman algorithm. In Chapter 5, we present optimal parallel algorithms to construct minimax trees which also avoids dynamic programing, yet constructs an exact solution. As we previously mentioned, our approach has been motivated in part by the T-C algorithm - a sequential 0(n log n) time algorithm to construct alphabetic trees with optimal weighted path length. We identify the valley filling technique and developed its accelerated version - the accelerated valley filling technique. Using this accelerated valley filling technique we obtain an optimal parallel algorithm for constructing minimax trees. We next consider techniques for accelerating parallel algorithms whose natural implementation involves the iteration of some basic step which depends on the result of the previous iteration. This is one of the fundamental problems in parallel computation. We can think of the consecutive iterations as of consecutive levels of computation. We identify a few approaches: 1. Cascading sampling. This technique is introduced in Chapter 2 (section 2.6) and considered further in Chapter 6. The basic idea is to precede the iteration by a preprocessing step. During this preprocessing step, for each level of computation, a computation is performed on a sample subset of the data available at the given level and the results are distributed to the other levels of computation. The additional information which arrives at a given level during this preprocessing step is used to speed up the iterated step. Chapter 6: Concluding remarks page 158 2. Pipelining This technique makes it possible to start computation on a higher level before the computation on a lower level is finished. This approach can be applied when it is possible to start computation on a higher level based on a partial results obtained from a lower level of computation. This approach has been taken in Cole's optimal parallel merging sort algorithm. A pipelining technique is usually combined with a sampling algorithm, that is with an algorithm which chooses the portion of information to be submitted to the next higher level prior to the completion of the computation at a given level ([Col85],[Kos89]). 3. Collapsing an iterative computation into one step This is a specific mixture of the two previous approaches. Sometimes it may be possible to obtain in a preprocessing step all information required for all levels. Then the computation on all levels can be completed by performing one parallel step. Such approach is taken in Chapter 5 to speed up the general valley filling technique to produce the accelerated valley filling technique. We now consider the tree contraction technique. Following the work of Miller and Reif [MilRei85], applications and simplifications of this technique have been studied in a broad range of papers including some of the results reported in this thesis. One of the first steps was to abstract the technique from its applications. Another step was to systematize classes of problems which can be solved using this technique. One step in this direction are Bottom-up and Top-down Algebraic Tree Computation Schemas defined in Chapter 2.5. This formalism however does not capture all possible applications of the technique. The idea of tree contraction occurs in implicit or explicit ways in parallel solutions to many problems which do not seem to have a natural definition as Algebraic Tree Computations. The cotree construction algorithm presented in Chapter 3 is an example of such a problem. The process of cotree construction can be viewed as the reverse of a cotree contraction Chapter 6: Concluding remarks page 159 process. As well, the general valley filling technique (Chapter 5) has a hidden application of the tree contraction technique. Namely, if we consider the level tree corresponding to a given input sequence then we can observe that consecutive iterations of the valley filling step can be visualized as iterative contraction steps performed on the level tree. This observation provides more intuition as to why the explicit application of the tree contraction technique makes it possible to obtain the accelerated version of the general valley filling technique. Both tree contraction and list ranking techniques were originally developed to support parallel dynamic evaluation of an expression provided in the form of a tree or a list. In the first case, we usually deal with a parse tree of an expression. In the second case, we have one associative operation which is applied to all elements of the list. We assume that all arguments are available at the beginning of the computation. Both the tree contraction and the list ranking, can be viewed as techniques for efficient scheduling operation. It is natural to ask which scheduling technique should be applied if the arguments in the leaves of a computation tree or a list arrive with certain (known) delays. A partial answer to this question is summarized in Figure 6.1. In this table, basic two questions are left open providing an interesting opportunities for future research. We have presented a number of parallel tree construction algorithms. Some of these algorithms are optimal and some are open for improvement. A challenging open question which is whether there exists an efficient parallel algorithm to construct an optimal binary tree such that the processor time product is 0(n log n) (or even 0(n2'e) as stated in [AtaKosLarMilTen89]). Chapter 6: Concluding remarks page 160 Description of an expression no delays delays One associative and commutative operation on a sequence of data presented in the form of a list list ranking non-alphabetic minimax tree One associative operation on a sequence of data presented in the form of a list list ranking alphabetic minimax tree One associative and decomposable operation on a sequecne of data presented in a list list ranking ? • A decomposable algebraic tree expression tree contraction ? • Figure 6.1. Generalizations of the parallel dynamic expression evaluation problem As mentioned before, the parallel valley filling technique discussed in Chapter 5 is related to the sequential algorithm of Hu and Tucker (the T - C algorithm) for the construction of an alphabetic tree with almost optimal weighted path length. It would be interesting to see whether this technique (in its basic or accelerated version) can be used to obtain a parallel algorithm for this problem (in its exact or approximate version) and other families of trees which can be built sequentially using the T-C algorithm [HuKleTan79]. As we have mentioned before, the best currently known algorithm for constructing alphabetic trees with optimal weighted path length uses the parallel dynamic programming technique and requires 0( log 2 «) time with roughly n 6 processors. The best approximation algorithm for the problem is due to Atallah et. al [AtaKosLarMilTen89] and requires 0 ( log 2 «) time using n2/log2nprocessors. REFERENCES page 161 References [AbrDadKirPrz87] K.ABRAHAMSON, N.DADOUN, D.G.KIRKPATRICK, T.PRZYTYCKA, A simple parallel tree contraction algorithm, Proc. 25th Allerton Conference on Communication, Control and Computing (1987), [AbrDadKirPrz87b] K.ABRAHAMSON, N.DADOUN, D.G.KIRKPATRICK, T.PRZYTYCKA, A simple optimal randomized parallel list ranking algorithm, Computer Science Department Technical Report 87-14, University of British Columbia Vancouver, to appear in Information Processing Letters. [AbrDadKirPrz89] K.ABRAHAMSON, N.DADOUN, D.G.KIRKPATRICK, T.PRZYTYCKA, A simple parallel tree contraction algorithm, Journal of Algorithms 10, 1989, 287-302. [AdkPen89] G.ADHAR, S. PENG, Parallel algorithms for cograph recognition and applications, Proc. of 1989 Workshop on Algorithms and Data Structures, August 1989, Ottawa, 335-351. [AhoHopUlI86] A.V.AHO, J.E.HOPCROFT, J.D.ULLMAN, The Design and Analysis of Computer Algorithms, Addison-Wesley, Reading, M A , 1974. [A1182] B.ALLEN, On the cost of optimal and near-optimal Binary Search Trees, Acta Inform. 18, 1982, 255-263. [AltHagMehPre97] H.ALT, T.HAGERUP, K.MEHLHORN, F.P.PREPARATA, Simulation of idealized parallel computers on more realistic ones, SIAM Journal of Computing, 16 (5), 1987, 808-835. [AndMil88] R.J.ANDERSON, G.L.MILLER, Deterministic parallel list ranking, VLSI Algorithms and Architecture, 3rd Egean Workshop on Computing (1988) 81-90. [AtaColGoo89] M.J .ATALLAH, R.COLE, M.T.GOODRICH, Cascading divide-and-conquer: A technique for designing parallel algorithms", SIAM, J. Comput. Vol 18, No 3, 499-533, 1989. [AtaKosLarMilTen89] M.J.ATALLAH, S.R.KOSARAJU, L.L.LARMORE, G.L.MILLER, S-H . TENG, Constructing trees in parallel, Proc 1st A C M Symposium on Parallel Algorithms and Architectures, 1989, 421-431. I. BAR-ON and U. VISHKIN, "Optimal parallel generation of a computation tree form". ACM Transactions on Programming Languages and Systems 7,2, 1985, pp. 348-357. P.J.BAYER, Improved bounds on the cost of optimal and balanced Binary Search Trees, Project M A C Technical Memorandum 69, MIT, Cambridge, 1975. [BarVis85] [Bay75] [BeBrGalSchVis89] O.BERKMAN, D.BRSLAUER,Z.GALIL, B.SCHIEBER, U.VlSHKIN, Highly parallelizable problems, Proc. of 21th Annual A C M Symposium on Theory of Computing, 1989, 309-320. REFERENCES page 162 [BerLawWon85] M . W . B E R N , E . L . L A W E R , A . L . W O N G , Why certain subgraph computation require only linear time, 26th Annual Symposium of Foundations of Computer Science, (1985) 117-125. [Bop89] [Bor77] [BorHop85] [BurUhr84] [BrSchVis88] [Bre74] [Call857] [Call859] [ChaKozSto81] [C0I86] [ColVis86] [ColVis86a] [ColVis88] R . B O P P A M A , Optimal separations between Concurrent-Write Parallel Machines, Proc. of 21th Annual A C M Symposium on Theory of Computing, 1989, 320-327. A . B O R O D I N , On relating time and space to size and depth, SIAM J. Comput., vol 6, 1977, 733-744. A . B O R O D I N , J . E . H O P P C R O F T , Routing, merging and sorting on parallel models of computation, / . Comp. Sys. Sci., Vol. 30, 1985, 130-145. M . B U R L E T , J . P . U H R Y , Parity graphs, Annals of Discrete Mathematics 21 (1984) 253-277. D . B R S L A U E R , B . S C H I B E R , U . V I S H K I N , Some double logarithmic parallel algorithms based on finding all nearest smaller values, UNIMACS-TR-88-79, University of Maryland Inst, for Advanced Comp. Studies (1988) R . P . B R E N T , The parallel evaluation of general arithmetic expressions, JACM 21 (1974) 201-208. A . C A Y L E Y , On the theory of the analytical forms called trees, Philosophical Magazine, vol. XIII, 1857, 172-176. A . C A Y L E Y , On the analytical forms called trees. Second part., Philosophical Magazine, vol. XVIII, 1859, 374-378. A . K . C H A N D R A , D . C . K O Z E N , L J . S T O C K M E Y E R , Alternation, JACM, vol 28, 1981, 114-133. R . C O L E , Parallel merge sort, Proc 27th Annual IEEE Symp. on Foundation of Computer Science, 1986, 511-516. R. C O L E and U. V I S H K I N , Approximate and exact parallel scheduling with applications to list, tree and graph problems, Proc. 27th Annual IEEE Symposium on Foundations of Computer Science (1986) 478-491. R. C O L E and U. V I S H K I N . Deterministic coin tossing and accelerating cascades: micro and macro techniques for designing parallel algorithms, Proc 18th Annual Symposium on Theory of Computing, 1986, pp. 206-219. R. C O L E , U. V I S H K I N , The accelerated centroid decomposition technique for optimal parallel tree evaluation in logarithmic time, Algorithmica 3, 3 (1988) 329-346. REFERENCES page 163 [CooDwoRes86] S.A.COOK, C.DWORK, R.A.REISCHUK, Upper and lower bounds for parallel random access machines without simultaneous writes, SIAM J. Computation, vol 15, 1986, 87-97. [CopWin87] D.COPPERSMITH, S.WINOGRAD, Matrix multiplication via arithmetic progressions, Proc. 28th Annual IEEE Symp. on Foundations of Comp. Sci., 1987, 260-270. [CopKlaPip86] D.COPPERSMITH, M . M . K L A W E , N.J.PlPPENGER, Alphabetic minimax trees of degree at most t, SIAM J. Comput. V o l 15, No 1, 1986 189-192. [CorLerS81] D.G.CORNEIL, H.LERCHS and L.STEWART, Complement reducible graphs, Discrete Applied Mathematics 3 (1981) 163-175. [CorPerSte85] D.G.CORNEIL.Y.PERL.L.K.STEWART, A linear recognition algorithm for cographs, SIAM J.Comput. 14, 4 (1985) 926-934. [DadKir87] N . DADOUN, D. KIRKPATRICK, "Parallel processing for efficient subdivision search". In 3rd A C M Symposium on Computational Geometry, Waterloo, Ontario, 1987, pp. 205-214. [DahKa86] E.DAHLHAUS, M.KARPINSKI, The matching problem for strongly connected graphs is in NC, Research Report No 855-CS, University of Bonn, 1986. PahKa87] E.DAHLHAUS, M.KARPINSKI, Fast parallel computation of Perfect and Strongly Perfect elimination schemes, Research Report No 8513-CS, University of Bonn, 1987. [DahKa89] E.DAHLHAUS, M.KARPINSKI, A n efficient parallel algorithm for the Minimal Elimination Ordering (MEO) of an arbitrary graph, Proc 30th Annual IEEE Symp. on Foundation of Computer Science, (1989), 454-459. [Dij59] E.W.DIJKSTRA, A note on two problems in connection with graphs, Numer Math., 1, 1959, 269-271. [Ede87] A.EDENBRANDT, Chordal graphs recognition is in N C , Information Processing Letters 24, 1987, 239-241. [FicRagWid88] F.E.FICH, P.RAGDE, A.WIDGERSON, Relations Between Concurrent-Write Models of Parallel Computation, SIAM, J.Comp. V o l 17, No 3 (1988), 606-677. [ForWyl87] S.FORTUNE, J.WYLLIE, Parallelism in Random Access Machines, Proc. 10th Annual A C M Symp. on Theoretical Computer Science,1987, 114-118. [Fre75] M .L .FREDMAN, Two applications of a probabilistic search technique: sorting X+Y and building balanced search trees, Proc 7th Annual A C M Symposium on Theory of Computation, 1975, 240-244. REFERENCES page 164 [GarJon79] M.R.GAREY, D.S.JOliNSON,Computers and Intractibility: A Guide to the Theory of NP-completness, W.H.Freeman, San Francisco. [GibRyt86] A. GIBBONS, W. RYTTER, An optimal parallel algorithm for dynamic tree expression evaluation and its applications, Proc.Symp. on Foundations of Software Technology and Theoretical Comp. Sci. (1986) 453-469. [GibRyt88] A. GIBBONS, W. RYTTER, Efficient Parallel Algorithms, Cambridge University Press (1988). [Go78] L.M.GOLDSCHLAGER, A unified approach to models of synchronous parallel machines, Proc. 10th Annual A C M Symp. on Theoretical Computer Science,1978, 89-94. [Gol76] M.C.GOLUMBIC, Combinatorial merging, IEEE Trans. Comp. 25,11 (Nov. 1976), 1164-1167. [Gol80] M.C.GOLUMBIC, Algorithic Graph Theory and Perfect Graphs, Academic Press (1980). [Goo87a] M.T.GOODRICH, Efficient Parallel Techniques for Computational Geometry, Ph.D. thesis, Purdue University, August 1987. [Goo87b] M.T.GOODRICH, Finding the convex hull of a sorted point set in parallel, Information Processing Letters 26,1887,173-179. [Goo89] M.T.GOODRICH, Triangulation of a polygon in parallel, Journal of Algorithms 10 (1989) . [He86a] X. HE, Efficient parallel algorithms for solving some tree problems, Proc. 24th Allerton Conference on Communication, Control and Computing (1986) 777-786. [He86b] X . H E , Parallel recognition and decomposition of two terminal series parallel graphs, Computer & Information Science Research Center Technical Report, The Ohio State University Columbus (1986). [HerBil88] K.T.HERLEY, G.BlLARDI, Deterministic Simulations of PRAM's on bounded degree networks, Prec. of the 26th Annual Allerton Conference on Communication, Control, and Computation, Illinois, 1988. [Her89] K.T.HERLEY, Efficient Simulations of Small Shared Memories on Bounded Degree Networks, Proc. 30th IEEE Symp. on Foundations of Computer Science, 1989, 390-395. [HirChaSar79] D.S.HIRSCHBERG, A.K.CHANDRA, D.V.SARWATE, Computing connected components on parallel computers, Com. of ACM, 22, 8 (1979) 461-464. [HooKlaPip84] H.J.HOOVER, M . M . K L A W E , N.J.PlPPENGER, Bounding Fan-out Logical Networks, Journal of the ACM, Vol 31, No 1 (1984) 13-18. REFERENCES page 165 [HorPre89] [Hu73] [HuKleTan79] [Huf52] [Jar30] [Jun78] [KaUpf88] [KarRam88] . [Kil847] [KirKla85] [KirPrz88] [KirPrz89] [KirRe84] [Kle88] S.W.HORNICK, F.P.PREPARATA, Deterministic P R A M simulation with constant redundancy, Proc of the 2nd A C M Symposium on Parallel Algorithms, Santa Fe, New Mexico, 1989, T.C.HU, "A new proof of the T-C algorithm", SIAM JAppl. Math., Vol. 25, No 1, July 1973, 83-94. T.C.HU, D.J. KLEITMAN, J.K.TAMAKI, Binary trees optimum under various criteria, SIAM J. Appl. Math., 37, 1979, 246-256. D.A.HUFFMAN, A method for the construction of minimum redundancy codes, Proc. IRE, 40, 1952, 1098-1101. V.JARNIK, O jistem problemu minimalnim, Praca, Moravske Prirodovedecke Splecnosti, 1930, 57-63 (in Czech). H.A.JUNG, On a class of posets and corresponding comparability graphs, J.Combinatorical Theory (B) 24 (1978) 125-133. A.KARLIN, E.UPFAL, Parallel hashing-an efficient implementaiton of shared memory, SIAM Journal of Computing, 15 (4), 1988, 876-892. R.M.KARP, V.RAMACHANDRAN, A survey of parallel algorithms for shared-memory machines, Report No.UCB/CSD 88/408, Computer Science Division University of California, Berkeley (1988). G.KIRCHHOFF, Uber die Aufloosung der Gleichungen, auf welche man beider Undersuchund der liniearen Vertheilung gallvanischer Stromegefurd wird, Ann Phis, Chem. 72 (1847) 497-508. D.G.KIRKPATRICK, M.M.KLAWE, Alphabetic Minimax Trees, SIAM J. Comput, Vol 14, No. 3 (1985) 514-526. D.G.KIRKPATRICK, T.PRZYTYCKA, Parallel recognition of cographs and cotree construction, Computer Science Department Technical Report 88-1,University of British Columbia, Vancouver, January 1988; to appear in Journal of Discrete Math. D.G.KIRKPATRICK, T.PRZYTYCKA, Parallel constructions of binary trees with almost optimal weighted path length, TR 89-25,to appear in Proc. 2nd A C M Symposium on Parallel Algorithms and Architectures. D.G.KIRKPATRICK, S.REISCH, Upper bound for sorting integers on random access machines, Theoretical Computer Science 28 (1984) 236-276. P.KLEIN, Efficient parallel algorithms for chordal graphs, Proc. 29th Symp. of Foundation of Comp. Sci., (1988), 150-161. [Kriu68] D. KNUTH, The Art of Computer Programming Volume 1: Fundamental Algorithms, Addison-Wesley, 1968. REFERENCES [Kos89] [KosDel88] [KruRudSni85] [LadFis80] [Lar87] [Ler71] [Ler72] [McC60] [Meg83] [Meh75] [Meh84] [Mer86] [Mey84] [MilRamKal86] [MilRei85] page 166 S.RAO KOSARAJU, Pipelining Computation in a tree of processors, Proc 30th Annual IEEE Symp. on Foundation of Computer Science, (1989), 184-189. S.RAO KOSARAJU, A.L.DELCHER, Optimal parallel evaluation of tree structured computation by raking, Proc. 3rd Aegean Workshop on Computing (1988). C.P.KRUSKAL, L.RUDOLF, and M.SNIR, Efficient parallel algorithms for graph problems, International conference on parallel processing, 1985, 180-185. R.E.LADNER, M.J.FISCHER, Parallel Prefix Sum Computation, Journal of the ACM, 1980, 830-838. L . L . L A R M O R E , A subquadratic algorithm for constructing Approximately Optimal Binary Search Trees, Journal of Algorithms 8, 1987, 579-591. H. LERCHS, On cliques and kernels, Dept. of Comp. Science Technical Report, University of Toronto (1971). H.LERCHS, On the clique-kernel structure of graphs, Dept. of Comp. Science Technical Report, University of Toronto (1972). J.MCCARTHY, Recursive functions of symbolic expressions and their computation by machine, Part I, Com. ACM, 3, 1960, 184-195. N. MEGIDDO, Applying parallel computation algorithms in the design of serial algorithms, Journal of the ACM, 30, 4, Oct. 1983, pp. 852-865. K. MEHLHORN, Nearly optimal binary search trees, Acta Informatica 5 (1975) 287-295. K. MEHLHORN, Data Structures and Algorithms 1: Sorting and Searching, Springer-Verlag (1985). E.MERKS, An optimal parallel algorithm for triangulating a set of points in the plane, International Journal of Parallel Programming, Vol 15, No 5 (1986) 339-411. H.MEYNIEL, The graphs whose odd cycles have at least two crossing chords, Annals of Discrete Mathematics 21(1984) 115-119. G.L.MILLER, V.RAMACHANDRAN, E.KALTOFEN, Efficient parallel evaluation of straight line code and arithmetic circuits, Proc. 2nd Aegean Workshop on Computing (1986) G. L. MILLER and J. REIF, Parallel tree contraction and its application, Proc. 26th IEEE Symp. on Foundations of Computer Science (1985) 478-489. REFERENCES page 167 [MilTen87] [MilTen87] [NaoNaoSc87] [Nov89] [Nov90a] [Nov90b] [Q£m63] [PatHew70] [Pip79] [PraSto89] [Pri55] [PrzCor88] [Ran87] [Rei85] [Ruz80] [Ruz81] G.L .MILLER, S-H.TENG, Systematic method for tree based parallel algorithm development, Second International Conference on Supercomputing, 1987. G . L . M I L L E R , S-H .TENG, Dynamic computing of computational circuits, Technical Report, CRI 87-17 Dept. of Comp. Sciences, University of Southern California, Los Angeles. J .NAOR, M .NAOR, A . A . S C H A F F E R , Fast parallel algorithms for chordal graphs, Proc. 19th Annual ACM Symp. on Theory of Computing (1987) 355-364. M.B.NOVICK, Fast parallel algorithms for the modular decomposition, Notes, Cornell University, Ithaca. M.B .NOVICK, Parallel algorithms for the split decomposition, Notes, Cornell University, Ithaca. M.B.NOVICK, Private communication. Y U . O F M A N , On the algorithmic complexity of discrete functions, Soviet Phisics - Doklady, Vol 7 no 7, 1933, 589-591. M.S .PATERSON, C.E.HEWITT, Comparative Schematology, Project MAC Conference on Concurrent Systems and Parallel Computation, Woods Hole, MA, 1970, 119-127. N.PIPPENGER, On simulating resource bounds, Proc. 20th Annual IEEE Symposium on Foundation of Computer Science, 1979, 307-311. V.R .PRATT, L . J .STOCKMEYER, A characterization of the power if vector machines, J,Comput. System Sci, vol 12, 1979, 198-221. R.C.PRIM, Shortest connection networks and some generalizations, Bell System Tech., J., 36, 1955, 1389-1401. T .PRZYTYCKA, D.G.CORNEIL, Parallel algorithms for parity graphs, to appear in Journal of Algorithms. A . G . R A N A D E , How to emulate shared memory, Proc. 28th IEEE Symp. on Foundations of Computer Science, 1987, 185-192. J.H.REIF, Depth-First Search is inherently sequential, Information Processing Letters 20,1985, 119-234. W.L .RUZZO, Tree-size bounded alternation, J.Comp. Syst. Sci., vol 21, 1980, 218-235. W.L .RUZZO, On uniform circuit complexity, J.Comp. Syst. Sci., vol 22, 1981, 365-383. [Ryt85] W . R Y T T E R , The complexity of two way pushdown automata and recursive programs, Combinatorical Algorithms on Words, eds REFERENCES page 168 Apostolica and Z.Galil, NATO ASI series, F:12, Springert Verlag (1985). [RytSzy89] W.RYTTER, T.SZYMACHA, Parallel algorithms for a class of graphs generated recursively, Information Processing Letters 30, 1989, 225-231. [Sac70] H.SACHS, On the Berge conjecture concerning perfect graphs, in Combinatorial Structures and their Applications, Gordon and Breach, pp 377-384, New York, 1970. [ShiVisi81] Y.SHILOACH, U.VISHKIN, Finding the maximum, merging, and sorting in a parallel computation model, Journal of Algorithms 2, (1981), 88-102. [Shy88] C.H.SHYU, A fast algorithm for cographs, presented at the French Israeli Conference on Combinatorics and Algorithm, November 1988. [Sli82] A . S L I S E N K O , Context-free grammars as a tool for describing polynomial time subclasses of hard problems, Inform. Process. Lett. 14 (2) (1982) 52-57. [Ste78] L. STEWART, Cographs, A Class of Tree Representable Graphs, M. Sc. Thesis, Dept. of Computer Science, Univ. of Toronto (1978). [Sum74] D.P.SUMNER, Dacey graphs, J.Australian Math. Soc. 18, 4 (1974) 492-502. [Sys84] M.M.SYSLO, NP-complete problems on some tree structured graphs: a review, Proc. of the Workshop on Graph Theoretical Concepts in Computer Science, Universitat Osnabruck, June 1983, 342-353. [Tar83] R. E . TARJAN, Data Structures and Network Algorithms, SIAM 1983. [TarVis84] R. E . T A R J A N , U. VISHKIN, Finding biconnected components and computing tree functions in logarithmic parallel time, In 25th Annual Symp. on Foundations of Comp. Science, 1984, pp. 12-22. [Ten87] S-H.TENG, The construction of Huffman equivalent prefix code is in NC, ACM SIGACT, 18(4) 1987, 54-61. [UpfWid87] E . U P F A L . A. WlDGERSON, How to share memory in a distrubuted system, Journal of the ACM, 3 4 (1) , 1987, 185-192. [Vai75] L .VALIANT, Parallelism in comparison problems, SIAM J.Comput., vol. 4, 1975, 348-355. [Vis83a] U. VISHKIN, Synchronous parallel computation — a survey, TR-71, Dept. of Computer Science, Courant Institute, NYU, 1983. [Vis83b] U. VISHKIN, Implementation of simultaneous memory access in model that forbid it, Journal of Algorithms, vol 4, 1983, 45-56. REFERENCES page 169 [Vis84] U . V I S H K I N , Randomized speed-ups in parallel computation, Proc. 16th Annual A C M Symp. on Theory of Computing (1984) 230-239. [Wyl81] J . W Y L L I E , The complexity of parallel computation, Ph.D. dissertation, Computer Science Department Cornell Univ., Ithaca, N Y , 1981 Index page 170 a-compact 22 accelerated valley filling 7,127,132,154 accelerated valley filling technique 157 algorithmic scheme 8, 14, 15, 26, 31, 53, 85, 91,125 All Dominating Neighbors (ADN) 40, 49, 51, 53, 135 All Strictly Dominating Neighbors (ASDN) 49, 135 alphabetic trees with optimal weighted path length 129 ancestor 9 approximate merging 110,121 approximate sorting 99, 110, 121 approximately optimal trees 82, 85,157 approximation of a sequnce 114 aproximate merging 99, 110 balanced forest 139 Basic Construction Scheme (Pxe) 85, 86, 99 basic subsequence 35,109 basic valley filling technique 127 BFS layering structure of a grpah 79, 80, 81 bottom-up Algebraic Tree Computation p-cax 26, 138 bottom-up tree construction 82, 83 Brent's scheduling principle 12, 13, 25, 104 Bypass 21, 23 cascading divide-and-conquer 32 cascading sampling 7, 32, 53, 104, 157 chordal graphs 6, 55 cliff 149, 151, 152 cographs 6, 55, 57, 80 bunch set 62, 69, 73, 74 line set 66, 69,75 representative of a bunch set 62,69 representative of a line set 66, 69 COMPRESS operation 18,23 construction error 102 construction sequence 130 cost function 11 cotree 59, 80,159 decomposable algebraic tree computation 27 defining leaf 133 distribution by sampling 39 divide-and-conquer 40,54 e-approximation of the sequence 100 e-merging 100 e-sorted sequence 99,100 elementary shift of weight 97 error of a tree 85 Euler tour technique 17,25, 46 feasible extension of a sequence 96 flexible element of a sequence 96,97 full botom-up algebraic tree computation 27 gap 35, 109 General Construction Scheme (YJto) 101 graphs grammars 6, 56 Index page 171 Halin graphs 6 head of a sequnce 92, 113, 114 heavy element 101,103 hidden sequence 44, 47, 51, 52 horizontal neighbors 50 horizontal visibility 42 Huffman algorithm 84, 86, 87, 128, 157 Huffman tree 7, 84, 86, 87, 89 k-trees 56 level interval 132 level of a level interval 133 level tree 130, 132, 135 level-by-level tree construction 7, 82, 83, 124 light element 101, 103 list ranking 15, 25 load function 135, 137, 138 main subsequence 92 merging 42 minimax tree 127 alphabetic minimax tree 128 non-alphabetic t-ary tree 148 t-ary alphabetic rrnnirnax tree 128 compaction 144 minimax trees with real weights 153 t-ary alphabetic minimax trees 142 NC class 4 optimal binary search trees 82 optimal speedup 4 order of a subsequence 116 origin of a sequene 34 outerplanar graphs 6 parallel dynamic expression evaluation 18, 159 parallel dynamic programming 6, 84, 129, 156 parity graphs 57,78 parity graphs 6 partial k-trees 6 path compaction 146,155 pipelining 154, 158 pointer jumping technique 16 polygonal line 42 polylogarithmic running time 4 P R A M 2, 3, 4 CRCW 2, 16, 41 ARBITRARY 3 COMMON 2 PRIORITY 3 CREW 2, 4, 16, 41 EREW 2, 3, 16, 17 prefix sum computation 14, 14, 73, 74 processor allocation problem 13, 38 Prune 21, 23 R A K E operation 18, 23 real element 105,106,107 sampling element 32, 34, 38, 105, 106, 107 sampling step 34, 37, 38, 105 series-parallel graph 56 skipped element 107 slope 151 source element 34,107 stair 150, 151 subtree 10 T-C algorithm 127, 154, 157, 160 tail of a sequence 92,95,113,115 top-down Algebraic Tree Computations 31 total work 4 tread 149,150 long tread 149,150 Index page 172 short tread 149 tree 9 almost balanced binary tree 10 alphabetic 10 child 9 depth of a node in a tree 9 descendant 9 height 9 internal node 9 leaf 9 level 9 optimal with respect to a cost function 11 ordered tree 10 parent 9 rooted 9 siblings 9, 61 strong siblings 61 weak siblings 61 t-ary tree 9 full t-ary tree 9 weighted 10,153 tree contraction 18, 19, 20, 323, 53, 55, 138 tree expansion 5, 55, 80 tree synthesis 5, 6, 7, 82, 83, 127 tree with optimal weighted path length 83 truncation error 102 valley filling 7, 157 valley filling step 127, 131, 154 valley sequence 127,131 level of the valley 131 maximal element 131 visibility sequnce 43,44, 47, 50 visibility tree 42 50 weight function 10,84,127 

Cite

Citation Scheme:

        

Citations by CSL (citeproc-js)

Usage Statistics

Share

Embed

Customize your widget with the following options, then copy and paste the code below into the HTML of your page to embed this item in your website.
                        
                            <div id="ubcOpenCollectionsWidgetDisplay">
                            <script id="ubcOpenCollectionsWidget"
                            src="{[{embed.src}]}"
                            data-item="{[{embed.item}]}"
                            data-collection="{[{embed.collection}]}"
                            data-metadata="{[{embed.showMetadata}]}"
                            data-width="{[{embed.width}]}"
                            async >
                            </script>
                            </div>
                        
                    
IIIF logo Our image viewer uses the IIIF 2.0 standard. To load this item in other compatible viewers, use this url:
https://iiif.library.ubc.ca/presentation/dsp.831.1-0302108/manifest

Comment

Related Items