Look at the two functions Merge-and-Count & Sort-and-Count. You are also given an array- Awesome_Array = XXXXXXXXXX11 Merge-and-Count (A, B) { curA = 0; curB = 0; count = 0; mergedList = empty list...


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:




  1. Write down the output values: (total_count & L) for Sort-and-Count(Awesome_Array).


  2. What do you think the returned value of total_count represents? Why?



Jun 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here