Setting up the array: 2. Write a method that generates an array of random integers (search array)
between 0 and 5000. The size of this array (n) should be a random number between 1000 and
1,000,000.
3. Generate a separate array (elements array) that contains 99 distinct random numbers
between 0 and 5000, and add 5001 as the 100th element.
Implementing Sequential Search: 4. Implement the sequential search method. This method will
take as input both your search array and the elements array, and sequentially look for each element
from the elements array in the search array.
5. Use Java's System.nanoTime() method to measure the time taken to complete the sequential
search for all elements from the elements array in the search array. Remember to calculate
the time taken for the search only, not including the array generation time.
Implementing Binary Search: 6. Sort your search array. You can use any sorting algorithm you like
for this. You can use built-in methods in Java, or write your own sorting method.
7. Implement the binary search method. This method will also take as input both your search
array and the elements array and use binary search to find each element from the elements
array in the search array.
8. Again, use System.nanoTime() method to measure the time taken to complete the binary search
for all elements from the elements array in the search array. Don't include the time taken to
sort the array in this measurement.
Plotting the Results: 9. Repeat the sequential and binary search tests for different sizes of the
search array from 1000 up to 1,000,000.
10. After each test, record the time taken, and dispose of the current search array by setting it to
null, before generating a new search array for the next test.
11. Plot the recorded times (in nanoseconds) against the respective search array sizes. Use a
separate line or symbol for the times taken by sequential search and binary search.
Cleaning up: 12. After completing each test, be sure to dispose of the current search array by setting
it to null, which makes it eligible for garbage collection in Java. This step is necessary to ensure that
your program doesn't use up too much memory.
Remember, for accurate measurements, ensure that you're always searching the same elements
array, and that you are using the same search array for both the sequential search and binary search
in each test.