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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started