Open In App
Related Articles

GATE | GATE-CS-2014-(Set-1) | Question 65

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
The minimum number of comparisons required to find the minimum and the maximum of 100 numbers is ______________. (A) 148 (B) 147 (C) 146 (D) 140

Answer: (A)

Explanation: Steps to find minimum and maximum element out of n numbers:
1. Pick 2 elements(a, b), compare them. (say a > b)
2. Update min by comparing (min, b)
3. Update max by comparing (max, a)
Therefore, we need 3 comparisons for each 2 elements, so total number of required comparisons will be (3n)/2 – 2, because we do not need to update min or max in the very first step. Recurrence relation will be:
T(n) = T(⌈n/2⌉)+T(⌊n/2⌋)+2 = 2T(n/2)+2 = ⌈3n/2⌉-2
By putting the value n=100, (3*100/2)-2 = 148 which is answer.  

Quiz of this Question

Last Updated : 10 Apr, 2018
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads