• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

GATE-CS-2006

Question 51

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? (GATE CS 2006) (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

  • only (i)

  • only (ii)

  • either (i) or (ii) but not both

  • neither (i) nor (ii)

Question 52

Consider these two functions and two statements S1 and S2 about them C
int work1(int *a, int i, int j)
{
    int x = a[i+2];
    a[j] = x+1;
    return a[i+2]  3;
}

int work2(int *a, int i, int j)
{
    int t1 = i+2;
    int t2 = a[t1];
    a[j] = t2+1;
    return t2  3;
}
S1: The transformation form work1 to work2 is valid, i.e., for any program state and input arguments, work2 will compute the same output and have the same effect on program state as work1 S2: All the transformations applied to work1 to get work2 will always improve the performance (i.e reduce CPU time) of work2 compared to work1
  • S1 is false and S2 is false
  • S1 is false and S2 is true
  • S1 is true and S2 is false
  • S1 is true and S2 is true

Question 53

Consider the following code written in a pass-by-reference language like FORTRAN and these statements about the code.
subroutine swap(ix,iy)
     it = ix
L1 : ix = iy
L2 : iy = it
end
  ia = 3
  ib = 8
  call swap (ia, 1b+5)
  print *, ia, ib
end 
S1: The compiler will generate code to allocate a temporary nameless cell, initialize it to 13, and pass the address of the cell swap S2: On execution the code will generate a runtime error on line L1 S3: On execution the code will generate a runtime error on line L2 S4: The program will print 13 and 8 S5: The program will print 13 and -2 Exactly the following set of statement(s) is correct:
  • S1 and S2
  • S1 and S4
  • S3
  • S1 and S5

Question 54

Consider this C code to swap two integers and these five statements after it: C
void swap(int *px, int *py) 
{ 
   *px = *px - *py; 
   *py = *px + *py; 
   *px = *py - *px; 
}
S1: will generate a compilation error S2: may generate a segmentation fault at runtime depending on the arguments passed S3: correctly implements the swap procedure for all input pointers referring to integers stored in memory locations accessible to the process S4: implements the swap procedure correctly for some but not all valid input pointers S5: may add or subtract integers and pointers.
  • S1
  • S2 and S3
  • S2 and S4
  • S2 and S5

Question 55

Consider the following grammar:
S → FR
R → S | ε
F → id
In the predictive parser table, M, of the grammar the entries M[S, id] and M[R, $] respectively.
  • {S → FR} and {R → ε }
  • {S → FR} and { }
  • {S → FR} and {R → *S}
  • {F → id} and {R → ε}

Question 56

Consider the following translation scheme. S → ER R → *E{print("*");}R | ε E → F + E {print("+");} | F F → (S) | id {print(id.value);} Here id is a token that represents an integer and id.value represents the corresponding integer value. For an input \'2 * 3 + 4\', this translation scheme prints
  • 2 * 3 + 4
  • 2 * +3 4
  • 2 3 * 4 +
  • 2 3 4+*

Question 57

Consider the following C code segment. 

for (i = 0, i<n; i++)
{
   for (j=0; j<n; j++)
   {
       if (i%2)
       {
           x += (4*j + 5*i);
           y += (7 + 4*j);
       }
   }
}

Which one of the following is false?

  • The code contains loop invariant computation

  • There is scope of common sub-expression elimination in this code

  • There is scope of strength reduction in this code

  • There is scope of dead code elimination in this code

Question 58

The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and fetches the old value of x n y without allowing any intervening access to the memory location x. consider the following implementation of P and V functions on a binary semaphore S.
void P (binary_semaphore *s)
{
    unsigned y;
    unsigned *x = &(s->value);
    do
    {
        fetch-and-set x, y;
    }
    while (y);
}
void V (binary_semaphore *s)
{
    S->value = 0;
} 
Which one of the following is true?
  • The implementation may not work if context switching is disabled in P
  • Instead of using fetch-and –set, a pair of normal load/store can be used
  • The implementation of V is wrong
  • The code does not implement a binary semaphore

Question 59

A CPU generates 32-bit virtual addresses. The page size is 4 KB. The processor has a translation look-aside buffer (TLB) which can hold a total of 128 page table entries and is 4-way set associative. The minimum size of the TLB tag is:
  • 11 bits
  • 13 bits
  • 15 bits
  • 20 bits

Question 60

A computer system supports 32-bit virtual addresses as well as 32-bit physical addresses. Since the virtual address space is of the same size as the physical address space, the operating system designers decide to get rid of the virtual memory entirely. Which one of the following is true?
  • Efficient implementation of multi-user support is no longer possible
  • The processor cache organization can be made more efficient now
  • Hardware support for memory management is no longer needed
  • CPU scheduling can be made more efficient now

There are 84 questions to complete.

Last Updated :
Take a part in the ongoing discussion