I need help at the following:
How can we find the minimum and the maximum of a set of $N$ numbers using $1.5N $ comparisons?
I need help at the following:
How can we find the minimum and the maximum of a set of $N$ numbers using $1.5N $ comparisons?
For simplicity, let's assume that $N$ is even:
After obtaining $\dfrac{N}{2}$ minimum values and $\dfrac{N}{2}$ maximum values:
Altogether, we've performed $\dfrac{N}{2}+(\dfrac{N}{2}-1)+(\dfrac{N}{2}-1)=\dfrac{3}{2}N-2$ comparisons.
If $N$ is odd, then at most $2$ additional comparisons (of the last element in the set, with the minimum value and with the maximum value) will be required in order to ensure the result.