Question: Algorithm OddEvenMerge ( A , B , C ) : Input: Two sorted arrays, A = [ a 1 , a 2 , . .

Algorithm OddEvenMerge(A, B, C):
Input: Two sorted arrays, A =[a1,a2,...,an] and B =[b1,b2,...,bn], and an
empty array, C, of size 2n
Output: C, containing the elements from A and B in sorted order
Let O1[a1,a3,a5,...,an1]
Let O2[b1,b3,b5,...,bn1]
Let E1[a2,a4,a6,...,an]
Let E2[b2,b4,b6,...,bn]
Call OddEvenMerge(O1, O2, O), where O =[o1, o2,..., on] Call OddEvenMerge(E1, E2, E), where E =[e1, e2,..., en] Let C [o1,e1,o2,e2,...,on,en]
for i 1 to n do
Do a compare-exchange of C[2i 1] and C[2i]
return C
Algorithm 8.13: Odd-even merge.
are out of order, as an atomic action called a compare-exchange. For example, she could use bubble-sort (Algorithm 5.20) to sort A, since this algorithms is data-oblivious when implemented using the compare-exchange primitive. But this would require O(n2) time, which is quite inefficient for solving the sorting problem. An alternative is to use the odd-even merge-sort algorithm, which is the same as the merge-sort algorithm given above, except that the merge step is replaced with the merge method shown in Algorithm 8.13. Argue why the odd- even merge-sort algorithm is data-oblivious, and analyze the running time of the resulting sorting algorithm.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!