Consider a special case of the sorting problem where each element in an array A[1..n] of...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Consider a special case of the sorting problem where each element in an array A[1..n] of elements is within k of its position in the sorted array (there was a question in class on Oct 10 asking about exactly this issue). 1. (2 points) Describe briefly how insertion sort can do this quickly and state and justify informally the resultant running time. 2. (8 points) A better solution is to use heaps. This solution is given on many web sites, but try to not look at those solutions. You can put the first (k+1) items in a min-heap, and then keep extracting the minimum and adding to the heap the next element in the array, until there are no more elements left in A. After this simply go on extracting the minimum until the heap is empty. Write the above algorithm in pseudocode and prove its correctness. You can assume that Heap methods discussed in class (Build-Heap, Heapify, Extract-min) are correct. Also state and justify informally the running time of this algorithm. Consider a special case of the sorting problem where each element in an array A[1..n] of elements is within k of its position in the sorted array (there was a question in class on Oct 10 asking about exactly this issue). 1. (2 points) Describe briefly how insertion sort can do this quickly and state and justify informally the resultant running time. 2. (8 points) A better solution is to use heaps. This solution is given on many web sites, but try to not look at those solutions. You can put the first (k+1) items in a min-heap, and then keep extracting the minimum and adding to the heap the next element in the array, until there are no more elements left in A. After this simply go on extracting the minimum until the heap is empty. Write the above algorithm in pseudocode and prove its correctness. You can assume that Heap methods discussed in class (Build-Heap, Heapify, Extract-min) are correct. Also state and justify informally the running time of this algorithm.
Expert Answer:
Answer rating: 100% (QA)
1 Insertion Sort Insertion sort can handle this special case efficiently because it works by iterati... View the full answer
Related Book For
Practical Introduction To Data Structures And Algorithm Analysis Java Edition
ISBN: 9780136609117
1st Edition
Authors: Clifford A. Shaffer
Posted Date:
Students also viewed these programming questions
-
Briefly describe ASCII and Unicode and draw attention to any relationship between them. [3 marks] (b) Briefly explain what a Reader is in the context of reading characters from data. [3 marks] A...
-
(i) Write down the linear program relaxation for the vertex cover problem and solve the linear program. [6 marks] (ii) Based on the solution of the linear program in (b)(i), derive an integer...
-
In Exercises use the differential equation and the specified initial condition to find y. dy dx || 1 4 - x y(0) = -
-
An X-ray tube operates at 95 kV with a current of 25 mA and nearly all the electron energy goes into heat. If the specific heat of the 0.065-kg anode plate is 0.11 kcal/ kg C, what will be the...
-
Table 4E.11 contains the data from a patient satisfaction survey for a group of 25 randomly selected patients at a hospital. In addition to satisfaction, data were collected on patient age and an...
-
A Sampling Distribution for Gender in the Rock and Roll Hall of Fame Exercise 3.37 tells us that 47 of the 303 inductees to the Rock and Roll Hall of Fame have been female or have included female...
-
The inventory records of Kuffel Co. reflected the following information for the year ended December 31, 2010: Required: a. Assume that Kuffel Co. uses a periodic inventory system. Calculate cost of...
-
Hyrdo Billboard Company entered into an angreement to display billboard advertising for Adele Incorporated for 1 0 months for a $ 6 4 , 0 0 0 fixe fee. The agreement also includes a potential $ 6 , 5...
-
Restful Sleep Mattress Company is planning to expand into selling bedroom furniture. This expansion will require a loan from the bank. The bank has requested financial information. Discuss, in a...
-
s1-2x , O 2x-1 , 2 dynamie system and tent mop T: [0,1]0] T(x)= 2-2x,
-
Determine the business's or organization's requirements through interviews, forms, surveys, JAD, and the like, and create the appropriate models and studies for the Web site. Don't forget to consider...
-
Should the courts and state legislatures relax their treatment of duress in homicide cases? Why or why not? Review Questions
-
What, in your opinion, is the appropriate age that a person should be tried in adult court?
-
Compare and contrast three means by which assistance is provided in the complicity context.
-
What is your opinion of the appellate courts decision in the New Hampshire trespassingillegal immigration case?
-
A raindrop of mass mo, starting from rest, falls under the influence of gravity. Assume that as the raindrop travels through the clouds, it gains mass at a rate proportional to the momentum of the...
-
How does the organizational structure of an MNC influence its strategy implementation?
-
For a database application, assume it takes 10 ms to read a block from disk, 1 ms to search for a record in a block stored in memory, and that there is room in memory for a buffer pool of 5 blocks....
-
(a) Find a growth rate that squares the run time when we double the input size. That is, if \(T(n) = X\), then \(T(2n) = X^2\) (b) Find a growth rate that cubes the run time when we double the input...
-
Write the complete algorithm for the merge insert sort sketched out in Section 15.7. Data From Section 15.7: We will use binary insert to place the losers. However, we are free to choose the best...
-
The two surfaces of a double convex, thin lens made of plastic each have an absolute value of radius of curvature of \(1.8 \mathrm{~mm}\). If the focal length of the lens is \(4.5 \mathrm{~mm}\),...
-
The radius of curvature of one surface of a glass lens \((n=1.45)\) is \(1.50 \mathrm{~m}\). If sunlight is focused at a point \(0.300 \mathrm{~m}\) away from the lens, what is the radius of...
-
You have a thin lens that is convex on both surfaces. The material of which the lens is made has index of refraction \(n=1.40\), and the radii of curvature are \(\left|R_{1} ight|=300 \mathrm{~mm}\)...
Study smarter with the SolutionInn App