Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. Consider the following C-function in which a[n] and b[m] are two sorted integer arrays and c[n + m] be another array. void xyz (int a [], int b [], int c [])
    {
    int i, j, k;
    i = j = k = 0;
    while ((i < n) && (j < m))
      if (a [i] < b [j] c [k++] = a[i++];
      else c[k++] = b[j++];
    }
    Which of the following conditions 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. only (i)
    2. only (ii)
    3. either (i) or (ii) but not both
    4. neither (i) nor (ii)
Correct Option: C

The condition (i) is true if the last inserted element in c[] is from a[] and condition (ii) is true if the last inserted element is from b[].



Your comments will be displayed only after manual approval.