What is the minimum number of pairwise comparisons required to find the maximum and maximum number in a list of 128 numbers?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Complexity of this algorithm is n + l o g 2 ( n ) − 2
....... and so on till you reach to 4
the above steps requires 64 + 32 + 16 +8 +4 + 2 = 126 comparisons to get the maximum, = n − 1
To get the second maximum number, you need to check only those elements which were compared with the maximum number in the above part. So to find the 2nd maximum you need l o g 2 ( n ) − 1
total = n + l o g 2 ( n ) − 2