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, 04.07.2019 18:20
Atank with constant volume contains 2.27 kg of a mixture of water phases (liquid-vapor). in the initial state the temperature and the quality are 127 °c and 0.6, respectively. the mixture is heated until the temperature of 160 oc is reached. illustrate the process in a t-v diagram. then, determine (1) the mass of the vapor in kg at the initial state, (2) the final pressure in kpa.
Answers: 3
question
Engineering, 04.07.2019 18:20
For each of the following process: a) sketch the p-v diagram, b)sketch t-s diagram, c) sketch t-v diagram, d) sketch the boundary work on one of the diagrams (a, b or c) and e) sketch the reversible heat transfer on one of the diagrams (a, b or c): 1- isobaric process from compressed liquid to superheated vapor 2- isothermal process from compressed liquid to superheated vapor 3- isentropic process from compressed liquid to superheated vapor
Answers: 3
question
Engineering, 04.07.2019 19:10
Which of the following is the most important advantage of a large field of view? a. allows larger areas to be examined b. relieves eyestrain c. minimizes parallax errors. d. increases precision in proportion to the in- crease in field of view
Answers: 2
question
Engineering, 04.07.2019 19:20
Apure substance is a)-mixture of various chemical elements or compounds b)-substance that has a fixed chemical composition throughout c)-mixture that is homogeneous (such as air) d)-all the answers
Answers: 3
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
Mathematics, 25.11.2021 06:20
question
English, 25.11.2021 06:20
Questions on the website: 13722361