Question: Write an efficient algorithm for the following problem, briefly describe why it is a correct algorithm, and analyze the time complexity. If you cannot find

Write an efficient algorithm for the following problem, briefly describe why it is a correct algorithm, and analyze the time complexity. If you cannot find any polynomial-time algorithm, then give a backtracking algorithm. Problem: Find Array Core Input: An array A[1...n] of positive integers, and an integer k where k < n. No integer is repeated in A. Output: Two numbers p and q of A such that there are exactly k other elements in A which are neither smaller than p and nor larger than q. Example: Input: A = [4,7,5,3,9,1], k = 2. Output: p = 4, q = 9 (because there are exactly two numbers 7 and 5 (other than 4 and 9) which are neither samaller than 4 nor larger than 9.)

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 Databases Questions!