Question: please code a function in c++ that gets an array A of length n of int, and an integer k, such that 0 2/log 2

please code a function in c++ that gets an array A of length n of int, and an integer k, such that 0 2/log2n . The function needs to permute the elements of A so that 2 () the first k elements of A are the smallest numbers sorted in the non-decreasing order. The running time must be O(n) and extra space used should be O(1). For example, on input A =[3,1,8,2,6,11,4,12,5,7,10,9] and k=6 the resulting array A needs to have [1,2,3,4,5,6] as its first six elements, and the rest can be any permutation of the remaining elements. For example [1,2,3,4,5,6,12,7,9,8,10,11] The order of the elements after in the last n-k positions is not important.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!