An array of n numbers is given, where n is an even number. The maximum as well as the minimum of these n numbers needs to be determined.I need to know the comparisions needed?
It can be done using 3*n/2-2
comparisons.
For n == 2
, simply compare the two numbers.
Now suppose we have minimum and maximum for the first n-2
numbers. Compare the remaining two numbers, then compare the bigger one to the previous maximum and the smaller to the previous minimum.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With