subject
Engineering, 27.11.2019 07:31 lataviabaker4608

You are working a job where you need to constantly sort lists. your manager says you need to sort one more for you to be done for the day, so you want to pick an array that’s as close to sorted as possible. you define the term k-close to sorted. for the purposes of this problem, we will say that a list of integers is k-close to sorted if every integer is at most k indices away from the index it would be in in a sorted list.

once you know this information, sorting is significantly easier than before. in this problem, you will write a program that takes in a list of integers that is

k-close to sorted and outputs the sorted list. ("sorted" refers to being sorted in ascending order for this problem.)

input will be given as an integer k on its own line, followed by a space separated list of integers. your program should output the sorted list. for example, if you are given the following input:

2

3 2 1 6 4 5 7 9 8 12 10 11

then you should print:

1 2 3 4 5 6 7 8 9 10 11 12

the code for reading input and writing output has been provided in the main class; your job is to implement the sort() method.

restrictions:

• in this problem, your program must have a runtime in o (nlog( where n

is the length of the list and k is the maximum distance between a number’s original position and its position in the sorted list. less efficient answers will receive at most 1/2 credit for this

problem. in particular, algorithms with a runtime in θ(nlog(n)) do not take full advantage of the fact that the list is k-close to sorted. and thus do not represent a complete solution to this problem.

• any data structures and/or algorithms you implement must be implemented by you; you may not, for example, use java’s priorityqueue class or any library sorting methods. answers that use any of java’s data structures other than arrays will not receive credit for this problem.

hint: you might consider using your newfound knowledge of heaps.

ansver
Answers: 2

Another question on Engineering

question
Engineering, 03.07.2019 14:10
Amass of 1.5 kg of air at 120 kpa and 24°c is contained in a gas-tight, frictionless piston-cylinder device. the air is now compressed to a final pressure of 720 kpa. during the process, heat is transferred from the air such that the temperature inside the cylinder remains constant. calculate the boundary work input during this process.
Answers: 2
question
Engineering, 03.07.2019 15:10
Apiston-cylinder with a volume of 0.25 m3 holds 1 kg of air (r 0.287 k/kgk) at a temperature of 100 c. heat transfer to the cylinder causes an isothermal expansion of the piston until the volume triples. how much heat is added to the piston-cylinder?
Answers: 3
question
Engineering, 04.07.2019 08:10
Which of the following is an easy way to remember the modified “x” tire rotation? a. nondrive wheels straight, cross the drive wheels b. drive wheels straight, cross the nondrive wheels c. drive wheels crossed, nondrive wheels straight d. drive wheels crossed, nondrive wheels crossed
Answers: 1
question
Engineering, 04.07.2019 18:10
Apump is used to circulate hot water in a home heating system. water enters the well-insulated pump operating at steady state at a rate of 0.42 gal/min. the inlet pressure and temperature are 14.7 lbf/in.2, and 180°f, respectively; at the exit the pressure is 60 lbf/in.2 the pump requires 1/15 hp of power input. water can be modeled as an incompressible substance with constant density of 60.58 lb/ft3 and constant specific heat of 1 btu/lb or. neglecting kinetic and potential energy effects, determine the temperature change, in °r, as the water flows through the pump.
Answers: 1
You know the right answer?
You are working a job where you need to constantly sort lists. your manager says you need to sort on...
Questions