patternMinor
Parallel algorithm for finding the maximum in $\log n$ time using $n / \log n$ processors
Viewed 0 times
themaximumlogprocessorstimealgorithmparallelforusingfinding
Problem
We were presented in class with an algorithm for finding the maximum in an array in parallel in $O(1)$ time complexity with $n^2$ computers.
The algorithm was:
Given an array A of length n:
The lecturer teased us it could be done with $\frac{n}{\log n}$ computers and with $\log n$ time complexity.
After a lot of thinking I couldn't figure out how to do it.
Any idea?
The algorithm was:
Given an array A of length n:
- Make a flag array B of length n and initialize it with zeroes with $n$ computers.
- Compare every 2 elements and write 1 in B at the index of the minimum with $n^2$ computers.
- Find the index with the 0 in A with $n$ computers.
The lecturer teased us it could be done with $\frac{n}{\log n}$ computers and with $\log n$ time complexity.
After a lot of thinking I couldn't figure out how to do it.
Any idea?
Solution
Divide your original array into $n/\log n$ blocks of length $\log n$. Put each processor in charge of each block, and find the maximum using the usual algorithm in time $\log n$. We now need to compute the maximum of an array of length $n/\log n$. Pair up the elements and compute the pairwise maxima to reduce the size of the array by a half. Repeat it $\log n$ times to find the maximum of the entire array.
The same idea also shows that you can compute the maximum in parallel in constant time using $n^{1+\epsilon}$ computers for every $\epsilon > 0$. (Exercise.)
The same idea also shows that you can compute the maximum in parallel in constant time using $n^{1+\epsilon}$ computers for every $\epsilon > 0$. (Exercise.)
Context
StackExchange Computer Science Q#21910, answer score: 9
Revisions (0)
No revisions yet.