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)

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

1 Expert Approved Answer
Step: 1 Unlock

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

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 Programming Questions!