edited by
178 views
0 votes
0 votes

Consider the following code, in which $\textsf{A}$ is an array indexed from $\textsf{0}$ and $\textsf{n}$ is the number of elements in $\textsf{A}$.

function foo (A, n) {
    L = 0;
    R = n – 1;

    while (L <= R) {
        i = ceil ((L + R) / 2);
        
        if (A [i] , i) {
            L = i + 1 ;
        } else {
            if (A [i] > i) {
                R = i – 1 ; 
            } else {
                 return (i);
            }
        }
    }
    return (– 1);
}

Here, $\textsf{ceil(x)}$ returns the smallest integer bigger than or equal to the number $\textsf{x}.$

If $\textsf{A = [ – 5, – 4, – 3, – 2, – 1, 4, 6, 8, 10, 12]},$ what will $\textsf{foo (A, 10)}$ return?

  1. $ – 5$
  2. $ – 1$
  3. $4$
  4. $6$
edited by

Please log in or register to answer this question.

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
0 answers
2
admin asked Jul 23, 2022
162 views
Which of the following statements is/are true?For any real number $r$ with $|r|>1, \displaystyle{}\lim _{n \rightarrow \infty} \sum_{i=1}^{n} 17 r^{n}=\frac{17}{1-r}$.Let...
0 votes
0 votes
0 answers
3
0 votes
0 votes
0 answers
4
admin asked Jul 23, 2022
220 views
Let $A, B$ be $n \times n$ invertible matrices of real numbers. Let $C=I+A A^{T}, D=I+B A A^{T} B^{T}$. We can conclude that$(A B)^{-1}=\left(I+B^{-1} A^{-1}\right)$$(A B...