Question: Please include steps and justification. Thanks! Problem 1. We would like to take into account memory hierarchies when analyzing Insertion Sort. Assume that your machine

Please include steps and justification. Thanks! Please include steps and justification. Thanks! Problem 1. We would like to

Problem 1. We would like to take into account memory hierarchies when analyzing Insertion Sort. Assume that your machine takes time f(i) to access memory location i, for some nondecreasing function f(i). Most of the time, when doing algorithmic analysis, we assume f(i) is a constant. In reality it is a slow growing function. For this problem, to keep things simple, we will assume that f) grows linearly, which is pretty drastic. Also, to keep things simple, we will count the time for comparisons. To compare two elements in locations i and j it takes time, i + j. We will modify Insertion Sort to take the memory access cost into account. The array to be sorted is in A1,...,n]. To insert the ith element of A into its proper location, put it into AO), where it is cheap to access. Then compare the elements of A to this value starting at location 1 and going up, rather than starting at location i - 1 and going down. (Note that if we were going to be really efficient, we could move an element into location 1 before comparing it to the element being inserted, so the cost would be just 0 +1 = 1. This is not in the spirit of the problem. If you must do this, then, to be fair, you should also keep track of the cost of moving items.) (a) Write the pseudo-code for this modified version of Insertion Sort. Do not use a sentinel. (b) What input gives the best-case cost? (c) Analyze the exact best-case cost. Show your work. (d) What input gives the worst case cost? (e) Analyze the exact worst-case cost. Show your work. (f) Analyze the average-case cost for n = 3 (assume distinct values). Show your work

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 Databases Questions!