Description
You are to write a program name search.java that will do the following:
- You are to create 3 arrays – prompt the user for a number that is greater than 100 that will serve as the size for the arrays (all 3 arrays will have the same user input size).
- Generate this amount of random numbers to fill these arrays – the random numbers must range from 1 to 99.
- Write 1 sequential search voided function (method) name Seq_search() that accepts two parameters – 1 array and a target value to search for. Call this method 3 times à once with a target value of 1, next with a target value of 50 and next with a target value of 100. Each time you call this method, you must invoke a clock to see how long it takes to execute and print out the time with an appropriate message.
- Write 1 binary search voided function (method) using Loop only, name Bin_search() that accepts two parameters – 1 array and a target value to search for. In the main program first sort one of the arrays and time it to see how long it took to sort. Now pass this sorted array as a parameter to this method calling it 3 times à once with a target value of 1, next with a target value of 50 and next with a target value of 100. Each time you call this method, you must invoke a clock to see how long it takes to execute and add the time it took to sort the array to this time and print out the time with an appropriate message.
- Write 1 binary search voided function (method) that uses recursion only, name BinRe_search() that accepts two parameters – 1 array and a target value to search for. In the main program first sort the last array and time it to see how long it took to sort. Now pass this sorted array as a parameter to this method calling it 3 times à once with a target value of 1, next with a target value of 50 and next with a target value of 100. Each time you call this method, you must invoke a clock to see how long it takes to execute and add the time it took to sort the array to this time and print out the time with an appropriate message.
- After you get the time, give an analysis as to which you think is a better algorithm to use and under what circumstance it is better to be used.
What to turn in:
Turn in:
- A disk (flash drive) with the files java and search.class or search.jar
- A printout of the java file.
- Make sure your name is clearly written on both the disk and the print out.