Question: Problem 2 (Closest element) You are given as an input two arrays of n distinct natural numbers A = (01, 02, ..., an) and B
Problem 2 (Closest element) You are given as an input two arrays of n distinct natural numbers A = (01, 02, ..., 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 min lai - bil = lai - bil- 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 ay = 6 is b2 = 3, the closest to a2 = 1 is bj = 1 and the closest to a3 = 12 is b3 = 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). Design an algorithm to find C. Describe your algorithm with words and state and analyze its running time. Problem 2 (Closest element) You are given as an input two arrays of n distinct natural numbers A = (01, 02, ..., 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 min lai - bil = lai - bil- 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 ay = 6 is b2 = 3, the closest to a2 = 1 is bj = 1 and the closest to a3 = 12 is b3 = 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). 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
Get step-by-step solutions from verified subject matter experts
