In: Computer Science
Give an O(lg n)-time EREW algorithm to perform the prefix computation on an array x[1. . n]. Do not use pointers, but perform index computations directly.
EREW:
It is Exclusive Read Exclusive Write (EREW) algorithm in which every memory cell can be read or written to by only one processor at a time.
A parallel random-access machine (PRAM) is a shared-memory abstract machine. As its name indicates, the PRAM was intended as the parallel-computing analogy to the random-access machine .
PRAM Models:
EREW is a PRAM model.
We can perform prefix sum by using EREW algorithm in O(logn) complexity.
SIMPLIFIED ALGORITHM:
Definition (Prefix Problem)
Input: an array A of n elements ai .
Output: All terms a1 × a2 × · · · × ak for k = 1, . . . , n.
× may be any associative operation.
Straightforward serial implementation:
P r e f i x ( A: Array [ 1 . . n ] ) {
/ / in−pla ce computation :
for i from 2 to n do {
A[ i ] := A[ i −1]∗A[ i ] ;
}
This takes O(logn) time to perform prefix computation by using EREW algorithm.