Question
Let be an array containing integers. Let be the lowest upper bound on the number of comparisons of the array elements, required to find the minimum and maximum values in an arbitrary array of elements. Which one of the following choices is correct?
Official answer and solution
- Official answer
- C
- From
- Official GATE 2021 answer key
Solution
Recall the optimal tournament/pairing comparison bounds for finding simultaneous minimum and maximum.
Finding the minimum alone in an arbitrary unsorted array of elements requires comparisons. Finding both minimum and maximum simultaneously cannot be done in fewer than comparisons.
By pairing elements up initially (costing comparisons) and then comparing winners for maximum and losers for minimum, the total number of comparisons is:
For any , this optimal bound satisfies and , matching option C.
C
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2021 Computer Science and Information Technology (CS, Set-1)
- Question
- 12 of 65, printed as CS Q.2
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.