Write two algorithms to find both the smallest and largest numbers in a list of n...

60.1K

Verified Solution

Question

Programming

Write two algorithms to find both the smallest and largestnumbers in a list of n numbers.

In first algorithm, you simply write one loop to find the minimumand maximum. So there will be 2(n - 1) comparisons.

In second algorithm, you try to find a method that does at most1.5n comparisons of array items.

Determine the largest list size (i.e., n) that Algorithm 1 canprocess and still compute the answer within 60 seconds. Report howlong it takes Algorithm 2 to compute this answer.

Answer & Explanation Solved by verified expert
3.7 Ratings (396 Votes)
Algorithm 1 max A0 min A0 for each i in A if Aimax then max Ai if Ai a1 currmax A0    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students