java random matches. Write a BinarySearch client that takes an int value T as a command-line argument and runs T trials of the following experiment for N = 103, 104, 105, and 106: generate two arrays of N randomly generated positive six-digit int values, and find the number of values that appear in both arrays. Print a table giving the average value of this quantity over the T trials for each value of N.
java
random matches. Write a BinarySearch client that takes an int value T as
a command-line argument and runs T trials of the following experiment for N = 103, 104,
105, and 106: generate two arrays of N randomly generated positive six-digit int values,
and find the number of values that appear in both arrays. Print a table giving the average
value of this quantity over the T trials for each value of N.
The experiment aims to study the number of overlaps between two randomly generated integer arrays for varying sizes. Specifically, for each array size , we generate two arrays of random six-digit integers and count the number of integers that appear in both arrays. By repeating this experiment times, we can derive an average number of overlaps for each array size .
Algorithm:
- Parse the command-line argument to get the value of .
- Initialize a list of array sizes .
- For each size in the list, execute the following steps:
- Initialize a variable to zero.
- Repeat times:
- Generate two random arrays of size .
- Sort the first array.
- For each element in the second array, perform a binary search on the sorted first array to check for its existence.
- Increment the totalMatches by the number of elements found.
- Compute the average number of overlaps for as .
- Print the average number for .
Step by step
Solved in 5 steps with 3 images