How to find max. and min. in array using minimum comparisons?
Problem : Given an array of integers find the max. and min. using minimum comparisons.
Solution
Method 1 (Naive) - Iterate through the array, and update min and max pointers
1\. Iterate through the array, select element a 2\. Update min by comparing (min, a) 3\. Update max by comparing (max, a) Number of comparison here will be ~2N, if N is number of element.
Time complexity will be O(n) though.
[Read More]