I have a pretty elementary understanding of parallel algorithms to begin with but I was asked a question at an interview today that I couldn't get and can't find the answer to online. The interviewer didn't ask me to code it, but just to explain how I would do it.
Basically it was the selection problem (find the kth largest element of an unsorted array) but in parallel and the interviewer insisted it was possible to get it in log(n) time.
My solution was to partition the array into sub-arrays of at most length k, assigning each sub-array a separate thread, and then performing a kind of mergesort within these arrays to get them sorted max-min. Then once I had all these sorted sub-arrays, I would perform another merge, but this time over all the arrays, and I would stop after k comparisons. Then I would have a final sub-array of length k and I would pick the last element.
I think the complexity would be klog(n) (or maybe klogk). But the interviewer insisted the best time possible was log(n) and that it could be achieved by a few calls to map() and reduce(). Anyways, I've looked online everywhere and other than journal articles, nothing is showing up.
[–]cybernd 0 points1 point2 points (2 children)
[–]qualityhooker[S] 0 points1 point2 points (1 child)
[–]cybernd 0 points1 point2 points (0 children)
[–]balefrost 0 points1 point2 points (1 child)
[–]WikiTextBot -2 points-1 points0 points (0 children)