Question

In: Computer Science

Give an O(lg n)-time EREW algorithm to perform the prefix computation on an array x[1. ....

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.

Solutions

Expert Solution

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:

  1. Exclusive read exclusive write (EREW)—every memory cell can be read or written to by only one processor at a time
  2. Concurrent read exclusive write (CREW)—multiple processors can read a memory cell but only one can write at a time
  3. Exclusive read concurrent write (ERCW)—never considered
  4. Concurrent read concurrent write (CRCW)—multiple processors can read and write. A CRCW PRAM is sometimes called a concurrent random-access machine.

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.


Related Solutions

Algorithm1 prefixAverages1(X, n) Input array X of n integers Output array A of prefix averages of...
Algorithm1 prefixAverages1(X, n) Input array X of n integers Output array A of prefix averages of X A ← new array of n integers for i ← 0 to n − 1 do s ← X[0] for j ← 1 to i do s ← s + X[j] A[i] ← s / (i + 1) return A ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Algorithm2 prefixAverages2(X, n) Input array X of n integers Output array A of prefix averages of X A ← new array of...
20. Give the values of x for which x > 500 lg x. Note: lg is...
20. Give the values of x for which x > 500 lg x. Note: lg is log base 2 (not ln).
give an algorithm where given as input an array A[1...n] withthe following property. There exists...
give an algorithm where given as input an array A[1...n] with the following property. There exists an index I such that if we append A[1...i−1] after A[i...n], we get an array in sorted increasing order. For simplicity you can assume that n is a power of 2.Give an efficient algorithm that returns the smallest element in A. Analyze the time complexity of your algorithm.Hint: you may want to compare A[1] and A[n/2].
algorithm binarySearch input bottom, top: a number    a: array a[0] to a[n-1] of numbers    x: a...
algorithm binarySearch input bottom, top: a number    a: array a[0] to a[n-1] of numbers    x: a number output result: true if x in a false otherwise Sideeffect NA Plan if (top < bottom) result := false else // get the middle of the array (refining) middle := (top - bottom)/2 + bottom (refining by +1 or -1 or integer division …) // example what is midpoint between 6 and 8 // (8-6)/2 = 1 we need to add 6 to...
Consider the problem of sorting an array A[1, ..., n] of integers. We presented an O(n...
Consider the problem of sorting an array A[1, ..., n] of integers. We presented an O(n log n)-time algorithm in class and, also, proved a lower bound of Ω(n log n) for any comparison-based algorithm. 2. Give an efficient sorting algorithm for an array C[1, ..., n] whose elements are taken from the set {1, 2, 3, 4, 5}.
Describe an O(n)-time algorithm that checks if brackets in a given arithmetic expression is properly placed,...
Describe an O(n)-time algorithm that checks if brackets in a given arithmetic expression is properly placed, i.e., all left brackets are matched with their right counterparts and there are no unmatched brackets between any pair of matched brackets. Note that there are generally more than one types of brackets and only those of the same type can match against each other. For simplicity, you can assume that all operands are represented as ‘a’ and addition, +, is the only available...
Suppose that we performed the algorithm SELECT whose running time is O(n) on 133 elements, and...
Suppose that we performed the algorithm SELECT whose running time is O(n) on 133 elements, and found the median of medians x by making groups of 5 elements. What is the maximum number of elements which are guaranteed to be greater than equals to x (without counting x, itself)?
(15 pts) Describe an O(n)-time algorithm that partitions a doubly linked list L into two doubly...
(15 pts) Describe an O(n)-time algorithm that partitions a doubly linked list L into two doubly linked lists L1 and L2, where L1 contains the odd-number-th elements in L and L2 contains the even-number-th elements in L. Elements in both L1 and L2 should appear in the same order as they appear in L. For example, if L contains the numbers 4, 7, 9, 1, and -3, in that order, then the output L1 should contain 4, 9, and -3,...
Present an O(n) algorithm that sorts n positive integer numbers a1, a2, . . . ,...
Present an O(n) algorithm that sorts n positive integer numbers a1, a2, . . . , an which are known to be bounded by n 2 (so ai ≤ n 2 , for every i = 1, . . . , n. Use the idea of Radix Sort (discussed in class and presented in Section 8.3 in the textbook). Illustrate your algorithm by showing on paper similar to Fig. 8.3, page 198 in the textbook (make sure you indicate clearly...
Pseudocode and algorithm of finding median of unordered array in linear time.
Pseudocode and algorithm of finding median of unordered array in linear time.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT