Skip to content

Beta · Data may be lost.Your data may be reset or lost.

GateBrew
← GATE CSE 2014 Set 3
Questions

Q42

MCQ2 marks, −0.67Data structuresEasy

Consider the C function given below. Assume that the array listAlistA contains n(>0)n (>0) elements, sorted in ascending order.

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 ProcessArrayProcessArray is CORRECT?

Sign in to save attempts.

Solutions and discussion are hidden while you attempt this question. They open once you check or show the answer.