Question: Problem 2 (Closest element) You are given as an input two arrays of n distinct natural numbers A = [a1, a2, ..., an] and B

 Problem 2 (Closest element) You are given as an input two

Problem 2 (Closest element) You are given as an input two arrays of n distinct natural numbers A = [a1, a2, ..., an] and B = [b1, b2, ..., bn]. For each element a; of A, you want to output the element b; of B that is closest to ai, more precisely you want to find b; such that %3D min |a; br| = |a; b;|. 1kn You will output a new array C storing b; at position i. For example, for A = [6,1, 12] and B = [1,3, 10], we have C = [3, 1, 10] since the closest ele- ment of B to a1 = 6 is b2 = 3, the closest to a2 = 1 is b1 = 1 and the closest to az = 12 is bz = 10. Note that C could have repeated entries, for example for A = [6, 1, 12] and B = [1,0, 8] we have C = [8, 1,8). %3D %3D Design an algorithm to find C. Describe your algorithm with words and state and analyze its running time

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!