Suppose now that we change the model by having processors with a shared memory. That is, we use a parallel RAM (PRAM) model. Can we speed up binary search? First, we have to define how the memory is accessed in a concurrent way. The most used model is concurrent read but exclusive write (CREW) (otherwise it is difficult to know the final value of a memory cell after a writing operation).
In a CREW PRAM, we can use the following simple parallel binary search. We divide the sorted set into segments (then, there are internal segment boundaries). Processor compares the key to the element stored in the th boundary and writes in a variable a 0, if it is greater or a if it is smaller (in case of equality, the search ends). All the processors do this in parallel. After this step, there is an index such that and (we assume that and , which indicates in which segment the key should be. Then, processor compares and and if they are different writes the new boundaries where the search continues recursively (see figure ). This step is also done in parallel (processor and take care of the extreme cases). When the segment is of size or less, each processor compares one element and the search ends. Then, the worst-case number of parallel key comparisons is given by
for , which gives . That is, . Note that for , we obtain the binary search result, as expected. It is possible to prove that it is not possible to do it better. In the PRAM model, the optimal speedup is when the work done by p processors is times the work of the optimal sequential algorithm. In this case, the total work is , which is larger than . In other words, searching in a sorted set cannot be solved with optimal speedup. If we restrict the PRAM model also to exclusive reads (EREW), then , which is even worse. This is because, at every recursive step, if all the processors cannot read the new segment concurrently, we slow down all the processes.