a) Write an algorithm that finds both the smallest and largest numbers in a list of n numbers
and calculate its complexity T(n).:-/

b) Write an algorithm that finds both the smallest and largest numbers in a list of n numbers
and with complexity T(n) is at most about (1.5)n comparisons.:?:

Recommended Answers

All 2 Replies

No. Gently caress you. Do your own homework.

I think this will work. Let's change it up a bit. Say I put some numbers in a paper bag, gave you the paper bag and said take the numbers and tell me what the biggest and smallest number in the bag was. One way you could do it is to sort the numbers (however you wanted to do that) and report the extremes. But can you think of another way you could determine the largest and smallest without sorting the numbers first? If so, try adapting that approach to your problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.