Question 8575 – Data-Structures
April 17, 2024
Question 8576 – Data-Structures
April 17, 2024
Question 8575 – Data-Structures
April 17, 2024
Question 8576 – Data-Structures
April 17, 2024

Question 8573 – Data-Structures

Consider the following C function in which size is the number of elements in the array E: The value returned by the function MyX is the

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;
}

Correct Answer: A

Question 42 Explanation: 
Y=0
for (i=0; i<size; i++)=""
Y=Y+E[i] // E is an array, this statement calculates the sum of elements of the array E and stores it in Y.
for (i=0; i<size; i++)=""
for(j=i; j<size; j++)=""
{
Z=0;
for(k=i; k<=j; k++)
Z=Z+E[k];
// It calculates the sum of all possible subarrays starting from 0 i.e., the loop will iterate for all the elements of array E and for every element, calculate sum of all sub arrays starting with E[i].
Store the current sum in Z.
If Z is greater than Y then update Y and return Y. So it returns the maximum possible sum of elements in any sub array of given array E.
A
maximum possible sum of elements in any sub-array of array E.
B
maximum element in any sub-array of array E.
C
sum of the maximum elements in all possible sub-arrays of array E.
D
the sum of all the elements in the array E.

Leave a Reply

Your email address will not be published. Required fields are marked *