Elsevier

Parallel Computing

Volume 31, Issues 8–9, August–September 2005, Pages 948-955
Parallel Computing

Short communication
Parallel generation of binary trees in A-order

https://doi.org/10.1016/j.parco.2005.06.002Get rights and content

Abstract

We present a new parallel algorithm for generating binary trees; it generates trees in A-order using A-sequences representation. This algorithm is adaptive and cost-optimal and is executed on a shared memory multiprocessor. We know of no other parallel algorithm in the literature that generates trees in A-order. This parallel algorithm is designed based on a presented sequential generation algorithm for A-sequences, with O(1) average time complexity.

Introduction

There are considerable algorithms for generating binary trees [1], [6], [9], [16]. In most of these algorithms, the trees are encoded as integer sequences. The length of encoding and the order of generation are essential consideration in the design of tree encoding schemes. Two such orderings were considered by Zaks [16], which he called A-order and B-order. A-order has been referred to as the most natural ordering on the set of binary trees, and few sequential algorithms generate trees in A-order [5], [7], [9], [10].

In addition to the sequential algorithms, few parallel generating algorithms for combinatorial objects and trees have recently been published [3], [4], [8], [12], [13], [14], [15]. These known parallel generation algorithms generate trees in B-order. Up to our knowledge there is no parallel algorithm that generates trees in A-order. In this paper, we present an adaptive and cost-optimal parallel algorithm that generates A-sequences in lexicographic order and their corresponding binary trees are in A-order. The computational model is a shared memory Single Instruction Stream, Multiple Data Stream (SM SIMD) model [2]. This algorithm is a parallel version of a new sequential generation algorithm that generates binary trees with A-sequence encoding. A-sequences first introduced by the authors [1] are integer sequences characterizing binary trees. The average constant time of our sequential algorithm is O(1), and the rank and unrank algorithms with O(n) and O(n log n) time complexity are also presented.

This paper is organized as follows. In Section 2, the sequential generation algorithm with ranking and unranking algorithms are discussed. Our adaptive and cost-optimal parallel algorithm is presented in Section 3. Finally, some concluding remarks are offered in Section 4.

Section snippets

Sequential algorithms

In this section, first we review the concepts introduced in [1] about A-sequences, that we need further, later a new sequential algorithm with ranking and unranking algorithms for A-sequences are discussed.

Definition 1

Given a binary tree T with n nodes, the A-sequence of T, A = (a1, a2,  , an-1), is obtained by labeling each node of tree with the number of nodes in its left subtree, and these labels are then listed in pre-order as a sequence, and the last zero is discarded.

For example, the 7-node binary tree

Parallel generation algorithm

Our cost-optimal and adaptive parallel algorithm, illustrated in Fig. 5, is a parallel version of the procedure Next presented in Section 2. Its computational model is Exclusive-Read, Concurrent-Write (ERCW) SM SIMD with N processors p1, p2,  , pN where 1  N  n  1. To begin, the value of n must be made known to all processors. This can be done using procedure broadcast in O(log N) time. The sequence A is subdivided into N subsequences of length m = n/N⌉each, and processor pi is assigned {a(i-1)×m+1, a(

Conclusion

An adaptive and cost-optimal parallel algorithm is presented to generate binary trees in A-order. Binary trees are encoded with A-sequences which are generated in lexicographic order. This algorithm is implemented on a ERCW SM SIMD machine. The authors have implemented and tested the algorithm in MPI on a 8 nodes Linux cluster system, and for different values of n the cost-optimality is obtained experimentally.

Acknowledgment

The authors would like to thank the anonymous referees for their helpful suggestions.

References (16)

There are more references available in the full text version of this article.

Cited by (0)

This research was in part supported by a grant from IPM (No. CS1382-4-01).

View full text