Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions