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 15:10
Two flowing streams of argon gas are adiabatically mixed to form a single flow/stream. one stream is 1.5 kg/s at 400 kpa and 200 c while the second stream is 2kg/s at 500 kpa and 100 ? . it is stated that the exit state of the mixed single flow of argon gas is 150 c and 300 kpa. assuming there is no work output or input during the mixing process, does this process violate either the first or the second law or both? explain and state all your assumptions.
Answers: 1
question
Engineering, 04.07.2019 12:10
On a average work day more than work place firs are reorted
Answers: 1
question
Engineering, 04.07.2019 18:10
Aflywheel accelerates for 5 seconds at 2 rad/s2 from a speed of 20 rpm. determine the total number of revolutions of the flywheel during the period of its acceleration. a.5.65 b.8.43 c. 723 d.6.86
Answers: 2
question
Engineering, 04.07.2019 18:10
Water at 70°f and streams enter the mixing chamber at the same mass flow rate, determine the temperature and the quality of the exiting stream. 0 psia is heated in a chamber by mixing it with saturated water vapor at 20 psia. if both streams enters the mixing chamber at the same mass flow rate, determine the temperature and the quality of the existing system.
Answers: 2
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
question
Social Studies, 20.09.2019 14:20
Questions on the website: 13722362