Information Processing Letters 17 (1993) X7-259 Elsevier 8 October 1993 A string-matching algorithm for the CREW PRAM Nalvo F. de Almeida Jr * Deparramento de Computaqio e Esraristica. UFMS, Caixa Postal 649, 79070-970 Campo Grande, MS. Brazil Valmir C. Barbosa IBM Rio Scientific Center, Cairo Postal 4624, 20001-970 Rio de Janeiro, RI, Bra:11 Communicated by S.G. Akl Received 5 May 1993 Abstract De Almeida Jr, N.F. and V.C. Barbosa. A string-matching algorithm for the CREW PRAM, Information Processing Letters 47 (1993) 25-l-259. We present an algorithm for the CREW PRAM to find all occurrences of a pattern of size m in a text of size n. For a futed alphabet and m = 0(log2 n), the algorithm runs in O(log m) time on O(n/log m) processors. Under these restrictions, it is optimal and improves on the time complexity of previously known string-matching algorithms for the CREW PRAM. Keywords: Parallel algorithms; algorithms for the CREW PRAM; string matching; pattern matching 1. Introduction The string-matching problem for a pattern pat =pat, .* . pat,,, of size m and a text text = text, . 1- text, of size n > m asks for all occurrences in text of pat. In general, the elements of both pat and tat can be assumed to be members of an alphabet Z: c (0,. . . , n - 11, and the output of an algorithm can be thought of as being given in the form of a sequence of booleans match,, . . . , match._,+, in which l’s mark the beginnings of occurrences of pat and O’s fill the remaining entries. Optimal string-matching algorithms require O(n) basic operations, and in general comprise Correspondence to: V.C. Barbosa, IBM Rio Scientific Center, Caixa Postal 4624, 20001-970 Rio de Janeiro, RJ, Brazil. * Supported by a scholarship from CAPES, Ministry of Edu- cation, Brazil. two distinct phases, known as pattern analysis and text analysis (at the end of the latter, the booleans match,, . . . , match,_,+, have been de- termined). We show in Table 1 a list of the string-matching algorithms that have been pro- posed for the PRAM. For each of these algo- rithms, Table 1 contains the time spent on a CRCW PRAM with pattern analysis and text analysis, the resulting total time, and the number of processors used. Of these algorithms, the last two are not optimal (unless in [8] one considers the pattern-analysis and text-analysis phases sep- arately, and in [3] one does not take into account the time to perform the pattern analysis), while the first one comes with the additional require- ment that C must be fixed. The algorithms of Table 1 were all proposed for the CRCW PRAM, and can be run on the CREW PRAM with an increase by a factor of OOZO-0190/93/$06.00 0 1993 - Elsevier Science Publishers B.V. All rights reserved 2.57