Computer Sciences > GATE 2014 SET-3 > Binary Search
Consider the C function given below. Assume that the array listA contains 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 ProcessArray is CORRECT?
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?
Correct : b
Similar Questions
What is the worst-case number of arithmetic operations performed by recursive binary search on a sorted array of size n?
A palindrome is a word that reads the same forwards and backwards. In a game
of words, a player has the following two plates painted with letters.
From...
Which number does not belong in the series below?
2, 5, 10, 17, 26, 37, 50, 64
Total Unique Visitors
Loading......