Question
The minimum number of comparisons required to find the minimum and the maximum of 100 numbers is _________________.
Official answer and solution
- Accepted answers
- 147.1 to 148.1
- From
- Official GATE 2014 answer key
Solution
Use the optimal pairwise comparison method to find both minimum and maximum of an array simultaneously.
For finding both the minimum and maximum of numbers, the standard divide-and-conquer / pairwise comparison algorithm proceeds as follows:
- Pair up the elements into pairs.
- Compare elements in each pair: this requires comparisons.
- The 50 winners are candidates for the maximum.
- The 50 losers are candidates for the minimum.
- Find the maximum among the 50 maximum candidates: this requires comparisons.
- Find the minimum among the 50 minimum candidates: this requires comparisons.
Total number of comparisons:
In general, for even , the optimal number of comparisons is:
148
Finding minimum first in comparisons and maximum separately in comparisons, totaling comparisons, which is not minimal.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2014 Computer Science and Information Technology (CS) Session 1
- Question
- 49 of 65, printed as CS Q.39
- 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.