edited by
12,384 views
49 votes
49 votes

Consider the following C function in which size is the number of elements in the array E

int MyX(int *E, unsigned int size) 
{ 
   int Y = 0; 
   int Z; 
   int i, j, k; 

   for(i = 0; i< size; i++) 
          Y = Y + E[i]; 
          
    for(i=0; i < size; i++) 
        for(j = i; j < size; j++)
        {
            Z = 0; 
            for(k = i; k <= j; k++) 
               Z = Z + E[k];
            if(Z > Y) 
               Y = Z; 
        } 
   return Y; 
} 

The value returned by the function MyX is the

  1. maximum possible sum of elements in any sub-array of array E.
  2. maximum element in any sub-array of array E.
  3. sum of the maximum elements in all possible sub-arrays of array E.
  4. the sum of all the elements in the array E.
edited by

5 Answers

0 votes
0 votes
sum of subarray can never be greater than sum of all elements of an array .therefore ans is D
Answer:

Related questions

89 votes
89 votes
16 answers
2
go_editor asked Sep 28, 2014
53,625 views
The minimum number of comparisons required to find the minimum and the maximum of $100$ numbers is ________
34 votes
34 votes
4 answers
4
go_editor asked Sep 26, 2014
12,116 views
Let $G$ be a graph with $n$ vertices and $m$ edges. What is the tightest upper bound on the running time of Depth First Search on $G$, when $G$ is represented as an adjac...