Consider the following C-function in which a[n] and b[m] are two sorted…

GATE · 2006 · CS

Consider the following C-function in which a[n] and b[m] are two sorted integer arrays and c[n + m] be another integer array. 

C

void xyz(int a[], int b [], int c[])
{
  int i, j, k;
  i = j = k = O;
  while ((i<n) && (j<m))
     if (a[i] < b[j]) c[k++] = a[i++];
     else c[k++] = b[j++];
}

Which of the following condition(s) hold(s) after the termination of the while loop?

(i) j < m, k = n+j-1, and a[n-1] < b[j] if i = n

(ii) i < n, k = m+i-1, and b[m-1] <= a[i] if j = m

  1. A.

    only (i)

  2. B.

    only (ii)

  3. C.

    either (i) or (ii) but not both

  4. D.

    neither (i) nor (ii)

Attempted by 73 students.

Sign up free to check your answer

Sign up free

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…