分治法求数组最大值

int set_max(int a[],int low,int high)//分治法求数组最大值
{
    if(low==high)
        return a[low];
    else
    {
        int mid=(low+high)/2;
        int left_max=set_max(a,low,mid);
        int right_max=set_max(a,mid+1,high);
        if(left_max>right_max)
            return left_max;
        else return right_max;
    }
}

时间复杂度为O(n);

你可能感兴趣的:(分治法求数组最大值)