Question: 1. In Java declare and initialize two arrays (different array names please) with 100,000 integers each. The integers should be consecutive. In one of the
1. In Java declare and initialize two arrays (different array names please) with 100,000 integers each. The integers should be consecutive. In one of the arrays, change two of the integers at indexes of your choice.
2. Now compare the two arrays using the code (nested loops) given in the .pdf file. How long did this operation take? Record the time in milliseconds or nanoseconds.
3. Double the size of each array and time the comparison of the two (using the nested loops, of course). How long did this operation take? Is it true that the Number of operations = (size of input)^2 ?
public int countDuplicates(int items1[], int items2[]) {
int count = 0;
for (int i = 0; i < items1.length; i++) {
for (int j = 0; j < items2.length; j++)
{
if (items1[i] == items2[j]) {
count++;
}
}
} return count;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
