GATEverse Practice, past papers & mock tests
GATE 2014 · session-3
AlgorithmsDivide and ConquermediumMCQ2 marks
Consider the C function given below. Assume that the array listA contains n (>0) elements, sorted in ascending order.
c
int ProcessArray(int *listA, int x, int n)
{
    int i, j, k;
    i = 0;
    j = n-1;
    do {
        k = (i+j)/2;
        if (x <= listA[k])
            j = k-1;
        if (listA[k] <= x)
            i = k+1;
    } while (i <= j);

    if (listA[k] == x)
        return(k);
    else
        return -1;
}
Which one of the following statements about the function ProcessArray is CORRECT?
Save your progress

Related Algorithms PYQs