Question: java. please write ALL the classes for thumbs up. This will be a linear search program that is implemented in three different ways. Each approach
java. please write ALL the classes for thumbs up.
This will be a linear search program that is implemented in three different ways. Each approach will be a separate class with a helper class to run the three classes.
Class #1: For the single-threaded search, you will perform a basic linear search. When you find the value, you should return the index (-1 if not found) and then print out the amount of time that elapsed.
Class #2: For the multi-threaded search, you need to split the array into smaller sub-arrays. Instead of creating new arrays of smaller size, you should pass the start and end indexes into your threads constructor and only search the specified subarray in the thread. Start off with splitting the array into 4 subarrays, and then instantiate a new thread for each subarray where you will do a linear search. If you find the value, return the index and print out the amount of time that elapsed. Note that your other threads will probably still be running, but we dont care about the time for all the threads to complete we only care about the time it takes to find the random number. If you didnt find the number, then print out the total time for all the threads to complete.
Class #3: For the parallel search, you will split the array into smaller subarrays similarly to what you did in the multi-threaded approach. Each parallel thread will also need the start index, end index, target number, and start time. Start off again with 4 threads. When you find the value, return the index and print out the amount of time that elapsed. Again, print out the time as soon as you find the number we dont care if all the threads are finished. We only care about all the threads finishing if the number is not in the array.
Class #4: Now lets create the help class. In the helper class, instantiate an array with 100,000,000 unique integers (One way to come up with unique integers is to make the values be equivalent to the indexes initially, then shuffle the array). Generate a random integer between 0 and 100,000,000-1, which will be your first target number. Create another integer that is NOT in the array to be your second target number. Use the three classes above to find your target numbers and check if they have all returned the same index by printing them out. Make sure you are using the same array, so that we can compare the run times. Do not modify the array since we want to compare the running times on the same array.
After you get the program working for all three searches, modifying the number of threads that are used in the multi-threaded search and the parallel search to see if you can get the code to execute faster.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
