Pram Algorithms: Merging and Graph Coloring
Pram Algorithms: Merging and Graph Coloring
http://cse.iitkgp.ac.in/~debdeep/courses_iitkgp/PAlgo/index.htm
PRAM ALGORITHMS:
MERGING AND GRAPH COLORING
2
20082015
AN OPTIMAL MERGING
We have seen a parallel merging in the last class which takes O(log n)
time with n processors.
What would be a cost-optimal algorithm to perform the merging?
The technique is based on a general strategy which is called
partitioning.
As opposed to Divide and Conquer, the crux lies here in suitably partitioning the
problem which helps combining to get the result easy.
OPTIMAL MERGE-PARTITIONING
b1blogm
blogm+1b2logm
a1aj(1)
aj(1)+1aj(2)
bilogm+1b(i+1)logm
aj(i)+1aj(i+1)
20082015
EXAMPLE
Let A=(4,6,7,10,12,15,18,20), B=(3,9,16,21)
m=4, k(m)=4/log4=2.
B=((3,9),(16,21))
rank(9,A)=3.
Thus A=((4,6,7),(10,12,15,18,20))
Note each element of A1 and B1 is larger than each element in A0 or
B0.
Hence, we can merge A and B by merging separately the pairs (A0,B0)
and (A1,B1).
5
PROOF
Let rank(bilogm:A)=j(i)
Thus we have: aj(i)<bilogm<aj(i)+1.
This result implies that:
bilogm+1>bilogm>aj(i) (thus each element of Bi is larger than each
element of Ai-1)
Likewise, aj(i)+1>bilogm (thus each element of Ai is larger than each
element of Bi-1)
20082015
TIMING ANALYSIS
The finding of j(i)s takes O(n) time, since the binary search is applied
to all the elements of A in parallel.
Thus the total number of operations required to execute this step (of
doing the binary search and partitioning) is
O((logn)xm/log(m))=O(m+n)
Consider the merging of two arrays each of length n.
After the partitioning step we end up with an independent set of
merging sub-problems.
This outcome is the essence of partitioning.
We would like to handle each merging subproblem in O(logn) time, st the algorithm
stays cost optimal.