2 votes 2 votes closed as a duplicate of: GATE CSE 2014 Set 1 | Question: 39 what should be the minimum number of comparisons required to find the minimum and maximum of 100 numbers ? Algorithms maximum-minimum normal numerical-answers + – Diksha Aswal asked Sep 18, 2017 • closed Dec 16, 2023 by Hira Thakur Diksha Aswal 402 views comment Share Follow See all 0 reply Please log in or register to add a comment.
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 A_i_$_h answered Sep 18, 2017 A_i_$_h comment Share Follow See all 4 Comments See all 4 4 Comments reply saxena0612 commented Sep 18, 2017 reply Follow Share You have to subtract 2 rather than 3 because of minimum and maximum element. Answer would be 148. 0 votes 0 votes Diksha Aswal commented Sep 21, 2017 reply Follow Share yes!! that should be (3n/2) - 2 0 votes 0 votes A_i_$_h commented Sep 21, 2017 reply Follow Share Does it vary based on even and odd or is it always (3n/2) - 2?? 0 votes 0 votes Diksha Aswal commented Sep 21, 2017 i edited by Diksha Aswal Nov 13, 2017 reply Follow Share 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 votes 1 votes Please log in or register to add a comment.