CSC235 Data Structures - Recursion Worksheet II


Given the following recursive function:
   int max(int arr[],int size)
   {
      int maxtop,maxbot;
      if (size == 1)
         return arr[0];
      else
      {
         maxbot = max(arr,size/2);
         maxtop = max(arr+size/2,size-size/2);
         if (maxbot > maxtop)
            return maxbot;
         else
            return maxtop;
      }
   }

Trace the following call to max, and tell what is printed:
   int arr[5] = {60,20,80,40,30};
   cout << "Max is: " << max(arr,5);


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page