Algorithm for calculating max and min value from an
array:
Algorithm
maxmin(int low, int high, int max, int min)
//low, high are used as index
//max, min are used as max & min value
{
if(low == high) then
min: = arr[low];
max: = arr[high];
else if((high -1 ) == low) then
if(arr[low] < arr[high]) then
max: = arr[high];
min: = arr[low];
else
min: = arr[high];
max: = arr[low];
else
mid: = (low + high)/2;
maxmin(low, mid, max, min);
maxmin(mid+1, high, max1, min1);
if(max < max1) then
max: = max1;
if (min>min1) then
min: = min1;
}
Total time required for finding max and min value
using divide and Conquer method:
So,
in the
asymptotic notation the time complexity of this algorithm is represented by O(n).