Question: Write pseudocode for an algorithm that solves this problem in O(n) time. Consider the following problem: Input: an array A with n distinct numbers (no
Write pseudocode for an algorithm that solves this problem in O(n) time.

Consider the following problem: Input: an array A with n distinct numbers (no duplicates), and an array B with the same n numbers in a different order. The numbers in A and B can be positive or negative. Output: the goal is find the number whose position in A is most similar to its position in B. Formally, say that a pair (i, j) is related if A[i] = B[j]; we want to find the related pair that minimizes lj i, where lj i| denotes the absolute value. If there multiple pairs that minimize lj i, you only have to return one of them. So for example if A 1, 3, 9, 7, 2, -8,6 and B = 2,6, -8,1,9, 3, 7 then the closest related pair is (2, 4) because A[2] = B[4] = 9 and 12 41 = 2; it is easy to check to for every other related pair (i, j) we have lj il > 3. Write pseudocode for an algorithm that solves this problem in O(n) time. No need for a justification; just pseudocode is enough
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
