Question: The following code computes the intersection (the number of elements in common) of two arrays. It assumes that neither array has duplicates. It computes

The following code computes the intersection (the number of elements in common) of two arrays. It assumes that neither array has duplicates. It computes the intersection by sorting one array (array b) and then iterating through array "a" checking (via binary search) if each value is in b. What is its runtime? Note: the time complexity of merge sort of n elements is nlogn. int intersection(int[] a, int[] b) { mergesort(b); int intersect = 0; for (int x a) { if (binarySearch (b, x) >= 0) { } intersect++; } } return intersect;
Step by Step Solution
There are 3 Steps involved in it
Introduction The code is designed to compute the intersection of two integer arrays a and b The intersection refers to the number of elements that are ... View full answer
Get step-by-step solutions from verified subject matter experts
