Question: 3.(20 points)LetA[1. . . n] be an array of n elements andB[1. . . m] another array of m elements, with mn. Note that neither
3.(20 points)LetA[1. . . n] be an array of n elements andB[1. . . m] another array of m elements, with mn. Note that neither A nor Bi s sorted. The problem is to compute the number of elements of A that are smaller thanB[i] for each elementB[i] with 1im.For simplicity, we assume that no two elements of Aa re equal and no two elements of B are equal.For example, letAbe{30,20,100,60,90,10,40,50,80,70}of ten elements. Let B be{60,35,73} of three elements. Then, your answer should be the following: for 60, return 5 (because there5 numbers in A smaller than 60); for 35, return 3; for 73, return 7.Design anO(n log m) time algorithm for the problem.Hint:Use the divide-and-conquer technique. Since mn, you cannot sort the array A because that would takeO(n log n) time, which is notO(n logm) as m may be much smaller than n. However, it would be fine to sortB, because that would takeO(m log m) time, which is still bounded byO(n log m).Note:You must describe the main idea of your algorithm (you may also give the
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
