Programming and Data Structures · Programming in C · 2 marks · Multiple choice
The following erroneous C program attempts binary search in Y[10]:
f(int Y[10],int x) {
int i,j,k;
i=0;j=9;
do {
k=(i+j)/2;
if(Y[k]<x) i=k; else j=k;
} while((Y[k]!=x)&&(i<j));
if(Y[k]==x) printf("x is in the array");
else printf("x is not in the array");
}
On which input does it fail?
Y=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], x<10
Y=[1, 3, 5, 7, 9, 11, 13, 15, 17, 19], x<1
Y=[2, 2, 2, 2, 2, 2, 2, 2, 2, 2], x>2
Y=[2, 4, 6, 8, 10, 12, 14, 16, 18, 20], 2<x<20 and x even
We are sorry we couldn't write detailed soluition for this, we are working on it!, please consider asking your own AI, its just 2-3 clicks with very minimum effort
More Programming in C questions
GATE 2008 CS Q85– The following erroneous C program attempts binary search in Y[10]: Which correction makes…
GATE 2026 CS (CS1) Q34– Consider the following program in C: The output of the program is . (answer in integer)
GATE 2026 CS (CS2) Q17– In the C runtime environment, which one of the following is stored in the heap?
GATE 2026 CS (CS2) Q19– Consider the following three ANSI C programs, P1, P2, and P3. Which one of the following…
GATE 2026 CS (CS2) Q60– Consider the following ANSI C program. The output of this program is . (answer in integer)…