Question: Write an efficient algorithm for the problem below, describe why it is a correct algorithm, and analyze the time complexity. If you cannot find any
Write an efficient algorithm for the problem below, 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 smaller than 4 nor larger than 9.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
