Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

code can be written in python, java, C, or C++ 1. (2.5+2.5+2.5+2.5 marks) Write two algorithms to find both the smallest and largest numbers in

code can be written in python, java, C, or C++ image text in transcribed
1. (2.5+2.5+2.5+2.5 marks) 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions