edited by
189 views
0 votes
0 votes

Consider the following code, in which $\text{A}$ and $\text{B}$ are arrays indexed from $0$ and $\textsf{lenA}$ and $\textsf{lenB}$ are the numbers of elements in $\text{A}$ and $\text{B}$, respectively. 

function foo (A, B, lenA, lenB) {
    sum = lenA + lenB;
    i = 0 ;
    j = 0 ;

    for t = 0 to (sum – 1)  {
        if (A[i] < B[j] )  {
            i = i + 1;
        }  else  {
            if (A[i] > B[j] )  {
                j = j + 1 ;
            }  else  {
                return A[i];
            }
        }
    }    
    return ( – 1) ;
}

Let $\text{A} = [2, 4, 6, 7, 8, 9, 10]$ and $\text{B} = [1, 3, 5, 7, 9, 11, 13]$. What does $\textsf{foo(A, B, 7, 7)}$ return?

edited by

Please log in or register to answer this question.

Related questions

0 votes
0 votes
0 answers
1
admin asked Jul 23, 2022
221 views
Which of the following expressions take integral values for all integers $n>100?$ $\frac{3^{n}-1}{2}$$\frac{4^{n}-1}{2}$$\frac{4^{n}-1}{3}$$\frac{5^{n}-1}{2}$