Question: Write two algorithms to find both the smallest and largest numbers in a list of n numbers. In first algorithm (i.e., Algo. 1), you simply

Write two algorithms to find both the smallest and largest numbers in a list of n numbers. In first algorithm (i.e., Algo. 1), you simply write one loop to find the minimum and maximum. So there will be 2(n 1) comparisons. In second algorithm (i.e., Algo. 2), you try to find a method that does at most 1.5n comparisons of array items. (Hints: You can reduce the number of comparisons by comparing pairs of numbers; that is find max(a, b) and min(a, b) in one comparison. Then you need only 2 more comparisons to update the overall min and max, for a total of 3 comparisons for each pair of numbers. The total number of comparisons would be 3n/2 = 1.5n.) Implement both algorithms (i.e., Algo. 1 and Algo. 2). Determine the largest list size (i.e., n) that Algo. 1 can process and still compute the answer within 60 seconds. Report how long it takes Algo. 2 to compute this answer. You can randomly populate the list.

Please write in java

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!