in Algorithms retagged by
227 views
2 votes
2 votes
what should be the minimum number of comparisons required to find the minimum and maximum of 100 numbers ?
in Algorithms retagged by
227 views

1 Answer

0 votes
0 votes

The minimum number of comparisons to find min and max is (3n/2)-3

(300/2) -3 = 150 -3 = 147

ANS =147

4 Comments

You have to subtract 2 rather than 3 because of minimum and maximum element. Answer would be 148.
0
0
yes!! that should be (3n/2) - 2
0
0
Does it vary based on even and odd or is it always (3n/2) - 2??
0
0
edited by
for even numbers, it's (3n/2)-2

for odd numbers... it depends

let we have n numbers (n  is odd)

then find the minimum and maximum number out of first n-1 numbers (n-1 is even), then compare the last number with the maximum number if it is larger than maximum then the total comparisons are (3n/2)-2+1=(3n/2)-1  otherswise have to compare with minimum(to find whether the last element is minimum or not) then total comparisons are (3n/2)-2+2 = 3n/2.
1
1
Answer:

Related questions