1,265 views
0 votes
0 votes
What is the total number of comparisons needed in the best case to find minimum and maximum of $300 $ elements?

3 Answers

2 votes
2 votes
Let n = 300,

1. Compare each pair, you'll get 150 numbers which are minimum in their respective pairs

2. Repeat above step now on remaining 150 numbers

3. Finally you'll get minimum number in n-1 comparisons. i.e 299 comparisons

4. After first step we got 150 numbers which were minimum in their respective pairs. At the same time we got 150 numbers that were maximum in their respective pairs. Our maximum number can only belong to this remaining 150 numbers

5. So now applying same algorithm for 150 numbers to find the maximum number

6. This will require n/2 - 1 comparisons i.e 149 comparisons

7. In total, No. Of comparisons to find maximum and minimum with best case complexity is

((n - 1) + (n/2 - 1)) = 3n/2 - 2 = 448

Related questions

1 votes
1 votes
1 answer
1
0 votes
0 votes
2 answers
2
dhruba asked Jun 5, 2023
1,167 views
Binary search is performed on a sorted array of n elements. The search key is not in the array and falls between the elements at positions m and m+1 (where 1 ≤ m < n). ...
5 votes
5 votes
1 answer
3
shaurya vardhan asked Nov 4, 2017
8,174 views
You are given an array of 64 elements, minimum number of comparisons required to find out second largest element among all will be _______.
2 votes
2 votes
1 answer
4
yes asked Oct 6, 2015
1,398 views
for example array contain a[1 2 3 3 3 3 3 4 5] then retun(1)