Menu

[Solved] 20 Pts Recall Merge Sort Algorithm Sorting Algorithm Takes N Log N Time N Space Problem Im Q37247774

(20 pts ) Recall that the Merge Sort algorithm is a sorting algorithm that takes Θ(n log n time and Θ(n) space. In this probl226227, (10pts total) For each of n=(24.25 fives times and record the tuple (n,〈t), where 〈t) is the average number of oper-

(20 pts ) Recall that the Merge Sort algorithm is a sorting algorithm that takes Θ(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 count t 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 〈、〈 n, Ali] is a uniformly random integer between 1 and n. (It is okay if A is a random permutation of the first n positive integers.) 3 226227, (10pts total) For each of n=(24.25 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 line plot of these 24 data points; overlay on your data a function of the form T(n)- An log n, where you choose the constant A so that the function is close to your data Hint 1: 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.) (b) ,2°,… ,220,22″1, run MergeSort (randomArray (n) ,n) mnHergesort (randomArray (n),n) Show transcribed image text (20 pts ) Recall that the Merge Sort algorithm is a sorting algorithm that takes Θ(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 count t 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 〈、〈 n, Ali] is a uniformly random integer between 1 and n. (It is okay if A is a random permutation of the first n positive integers.) 3
226227, (10pts total) For each of n=(24.25 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 line plot of these 24 data points; overlay on your data a function of the form T(n)- An log n, where you choose the constant A so that the function is close to your data Hint 1: 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.) (b) ,2°,… ,220,22″1, run MergeSort (randomArray (n) ,n) mnHergesort (randomArray (n),n)

Expert Answer


Answer to (20 pts ) Recall that the Merge Sort algorithm is a sorting algorithm that takes Θ(n log n time and Θ(n) space. In thi… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *