Algorithm or Pseudocode and time complexity analysis for calculating maximum and minimum value from an array using divide and conqure method





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).


 

5 comments:

  1. Thank you so much for this nice information. Hope so many people will get aware of this and useful as well. And please keep update like this.

    Text Analytics Tool

    Data Analytics Solutions

    ReplyDelete
  2. This information is impressive; I am inspired how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic
    Mazeevents
    best event management company in chennai
    event management companies in chennai

    ReplyDelete