Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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! image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions

Question

What are the- three basic functions of every accounting -system?

Answered: 1 week ago