Question: You are given three arrays A[1 : n], B[1 : n], and C[1 : n] of positive integers. The goal is to decide whether or
You are given three arrays A[1 : n], B[1 : n], and C[1 : n] of positive integers. The goal is to decide whether or not there are indices i, j, k [1 : n] such that A[i] B[j] = C[k]; in other words, is it the case that there are numbers in A and B whose multiplication belongs to C. Examples: When n = 3, and A = [1, 3, 4], B = [2, 3, 5], and C = [1, 3, 5], the answer is Yes, because for instance we have A[1] B[3] = C[3] or A[1] B[2] = C[2]. When n = 3 and A = [1, 3, 4], B = [2, 4, 6], and C = [7, 9, 11], the answer is No. (a) Suppose all the numbers in C belong to the set 1, 2, . . . , n2 . Design and analyze an algorithm with worst-case runtime of O(n 2 ) for the problem in this case. (b) Now suppose C can be any arbitrary array of n integers. Design and analyze a randomized algorithm with expected worst-case runtime of O(n 2 ) for the problem in this case. Note: Actually, this problem also has a deterministic algorithm that runs in worst-case O(n 2 ) time. But you do not need to design such an algorithm for this problem (although if you do, you will receive the full credit for both parts (a) and (b)).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
