[Solved]3 20 Pts Recall Mergesort Algorithm Sorting Algorithm Takes O N Log N Time N Space Problem Q37189504




3. (20 pts) Recall that the MergeSort algorithm is a sorting algorithm that takes O(n log n) time and Θ(n) space. In this problem, you will implement and instrument Mergesort, then perform a numerical experiment that verifies this asymptotic analysis. There are two functions and one experiment to do this (i) MergeSort (A,n) takes as input an unordered array A, of length n, and returns both an in-place sorted version of A and a countt of the number of atomic operations performed by MergeSort. (ii) randomArray (n) takes as input an integer n and returns an array A such that for each 0 i< n, Al is a uniformly random integer between 1 and n. (It is okay if A is a random permutation of the first n positive integers.) (a) (10 pts total) From scratch, implement the functions MergeSort and randomArray You may not use any library functions that make their implementation trivia You may use a library function that implements a pseudorandom number gener- ator in order to implement randomArray Submit a paragraph that explains how you instrumented MergeSort, i.e., explain which operations you counted and why these are the correct ones to count. (a) (10 pts total) From scratch, implement the functions MergeSort and randomArray You may not use any library functions that make their implementation trivia You may use a library function that implements a pseudorandom number gener- ator in order to implement randomArray Submit a paragraph that explains how you instrumented MergeSort, i.e., explain which operations you counted and why these are the correct ones to count. (b) (10 pts total) For each of n (2,2522, 227), run MergeSort (randomArray (n) ,n) fives times and record the tuple (n, (t)), where (t) is the average number of oper- ations your function counted over the five repetitions. Use whatever software you like to make a ine plot of these 24 data points; overlay on your data a function of the form T(n) = An logn, where you choose the constant A so that the function is close to your data To increase the aesthetics, use a log-log plot. Hint 2: Make sure that your MergeSort implementation uses only two arrays of length n to do its work. (For instance, don’t do recursion with pass-by-value.) Show transcribed image text 3. (20 pts) Recall that the MergeSort algorithm is a sorting algorithm that takes O(n log n) time and Θ(n) space. In this problem, you will implement and instrument Mergesort, then perform a numerical experiment that verifies this asymptotic analysis. There are two functions and one experiment to do this (i) MergeSort (A,n) takes as input an unordered array A, of length n, and returns both an in-place sorted version of A and a countt of the number of atomic operations performed by MergeSort. (ii) randomArray (n) takes as input an integer n and returns an array A such that for each 0 i
Expert Answer
Answer to 3. (20 pts) Recall that the MergeSort algorithm is a sorting algorithm that takes O(n log n) time and Θ(n) space. In th… . . .
OR

