Look at the two functions Merge-and-Count & Sort-and-Count. You are also given an array-
Awesome_Array= 3 7 10 14 18 19 2 11
Merge-and-Count (A, B){
curA = 0; curB = 0;
count = 0;
mergedList = empty list
while (not at end of A && not at end of B){
a = A[curA];
b = B[curB];
if (a <>
append a to mergedList;
curA++;
else
append b to mergedList;
curB++;
count = count + number of elements left in A
}
if (at end of A)
append rest of B to mergedList;
else
append rest of A to mergedList;
return (count, mergedList);
}
Sort-and-Count(L){
if list L has one element
return (0, L)
Divide the list into two halves A and B
(rA, A) ← Sort-and-Count(A)
(rB, B) ← Sort-and-Count(B)
(rC, L) ← Merge-and-Count(A, B)
total_count = rA + rB + rC
return (total_count, L)
}
Now, answer the questions:
Write down the output values: (total_count & L) for Sort-and-Count(Awesome_Array).
What do you think the returned value of total_count represents? Why?