PREVIOUS YEAR SOLVED PAPERS - GATE 2018

26. Consider the following languages:
I {ambncpdq | m + p = n + q, where m, n, p, q ≥ 0}
II {ambncpdq | m = n and p = q, where m, n, p, q ≥ 0}
III {ambncpdq | m = n = p and p ≠ q, where m, n, p, q ≥ 0}
IV {ambncpdq | mn = p + q, where m, n, p, q ≥ 0}
Which of the language above are context-free?

  • Option : B
  • Explanation :
    I {ambncpdq | m + p = n + q} is clearly CFL since, we can rearrange the equation as m - n + p - q = 0 which can be done by push, pop, and pop and check if stack is empty at end.
    II {ambncpdq | m = n and p = q} is clearly CFL since, one comparison at a time can be done by pda
    III {ambncpdq | m = n = p and p ≠ q} is not CFL since m = n = p is a double comparison which cannot be done by PDA.
    IV {ambncpdq | mn = p + q} is not a CFL, since mn involves multiplying number of a’s and number b’s which cannot be done by a PDA.
    So, only I and II are CFL’s.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


27. Consider the following C code. Assume that unsigned long int type length is 64 bits.
Unsigned long int fun (unsigned long int n)
{
unsigned long int i, j = 0, sum = 0;
for (I = n; I > 1; I = i/2) j++;
for (; j > 1; j = j/2) sum++;
return (sum);
}
The value returned when we call fun with the input 240 is

  • Option : B
  • Explanation :
    // n takes 2^40
    unsigned long int fun(unsigned long int n) {
    // initialized sum = 0
    unsigned long int i, j, sum = 0;
    //First it takes i = n = 2^40,
    //then it divides i by 2 and incremented once j
    //each time, that's will make makes j = 40,
    for( i=n; i>1; i=i/2) j++;
    //Now the value of j = 40,
    //it divides j by 2 and incremented once sum
    //each time, that's will make makes sum = 5,
    for( ; j>1; j=j/2) sum++;
    //returns sum = 5
    return sum;
    }
    So, answer is 5.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


28. Consider the relations r(A, B) and s(B, C), where s.B is a primary key and r.B is a foreign key referencing s.B. Consider the query Q: r⋈(σB<5(s)) Let LOJ denote the natural left outer-join operation. Assume that r and s contain no null values.

  • Option : C
  • Explanation :

    Given query: r ⋈ ( σB<5(s))
    ABC
    a12c1
    a24c1
    a34c1

    A: σB<5(r ⋈ s)
    ABC
    a12c1
    a24c1
    a34c1

    B:  σB<5(r ⋈ s)
    ABC
    a12c1
    a24c1
    a34c1

    C: r ⋈ (σB<5(s))
    ABC
    a12c1
    a24c1
    a34c1
    a46Null
    a56Null

    D: σ;B<5 (r) ⋈  s
    ABC
    a12c1
    a24c1
    a34c1

    Option “C” query result not equal to given query.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


29. In a system, there are three types of resources: E, F and G. Four processes P0, P1, P2 and P3 execute concurrently. At the outset, the processes have declared their maximum resource requirements using a matrix named Max as given below. For example, Max[P2, F] is the maximum number of instances of F that P2 would require. The number of instances of the resources allocated to the various processes at any given state is given by a matrix named Allocation. Consider a state of the system with the Allocation matrix as shown below, and in which 3 instances of E and 3 instances of F are the only resources available.

Allocation Max
 EFG  EFG
P0101 P0431
P1112 P1214
P2103 P2133
P3200 P3541
From the perspective of deadlock avoidance, which one of the following is true?

  • Option : A
  • Explanation :
    Max needCurrent allocationCurrent availableRemaining need
     EFGEFGE(3)F(3)G(0)EFG
    P0431101431330
    P1214112534102
    P2133103646030
    P3541200846341

    Safe sequence : P0, P2, P1, P3
    Safe state
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


30. Assume that multiplying a matrix G1 of dimension p×q with another matrix G2 of dimension q×r requires pqr scalar multiplications. Computing the product of n matrices G1G2G3 ….. Gn can be done by parenthesizing in different ways. Define GiGi+1 as an explicitly computed pair for a given paranthesization if they are directly multiplied. For example, in the matrix multiplication chain G1G2G3G4G5G6 using parenthesization (G1(G2G3))(G4(G5G6)), G2G3 and G5G6 are only explicitly computed pairs.
Consider a matrix multiplication chain F1F2F3F4F5, where matrices F1,F2,F3,F4 and F5 are of dimensions 2×25,25×3,3×16,16×1 and 1×1000, respectively. In the parenthesization of F1F2F3F4F5 that minimizes the total number of scalar multiplications, the explicitly computed pairs is/are

  • Option : C
  • Explanation :
    Total number of scalar multiplications are 48 + 75 + 50 + 2000 = 2173 and optimal parenthesis is ((F1(F2(F3 F4))) F5). As concluded, F3, F4 are explicitly computed pairs.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


Related Quiz.
GATE 2018