CS and IT GATE 2017 Set-1 Questions with Answer

Ques 14 Automata


If G is grammar with productions

S → SaS | aSb | bSa | SS | ∈


where S is the start variable, then which one of the following is not generated by G?

A

abab

B

aaab

C

abbaa

D

babba


Ques 15 Automata


Consider the following grammar over the alphabet {a,b,c} given below, S and T are non-terminals.

G1: S-->aSb|T
T--> cT|∈
G2: S-->bSa|T
T--> cT|∈

The language L1(G1) ∩ L2(G2).

A

Finite

B

Non-finite but regular

C

Context-free but not regular

D

Recursive but not context-free


Ques 16 Automata


Consider the following context-free grammar over the alphabet ∑ = {a, b, c} with S as the start symbol:

S → abScT | abcT
T → bT | b


Which of the following represents the language generated by the above grammar?

A

{(ab)n(cb)n | n >= 1 }

B

{(abncbm1cbm2...cbmn | n, m1, m2, ....., mn >= 1 }

C

{(ab)n(cbm)n | n >= 1 }

D

{(ab)n(cbn)m | m, n >= 1 }


Ques 17 Automata


Consider the following grammar

P→xQRS
Q→yz|z
R→ w|∈
S→y

Which is FOLLOW(Q)?

A

{R}

B

{w}

C

{w, y}

D

{w, ∉}


Ques 18 C Programming


The output of executing the following C program is ________.

# include<stdio.h>
int total(int v)
{
    static int count = 0;
    while (v) {
    count += v & 1;
    v >>= 1;
    }
    return count;
}
void main()
{
    static int x = 0;
    int i = 5;
    for (; i> 0; i--) {
        x = x + total(i);
    }
    printf (“%dn”, x) ;
}

a is the correct answer.


Ques 19 C Programming


Consider the following C program.

#include<stdio.h>
#include<string.h>
void printlength (char *s, char *t)
{
    unsigned int c = 0;
    int len = ((strlen (s) - strlen (t)) > c) ? strlen (s) : strlen (t);
    printf("%dn", len);
}

void main()
{
    char *x = "abc";
    char *y = "defgh";
    printlength(x, y);
}


Recall that strlen is defined in string.h as returning a value of type size_t, which is an unsigned int . The output of the program is _________.

3 is the correct answer.


Ques 20 C Programming


Consider the following two functions
void fun1(int n){
    if(n == 0) return;
      printf(“%d”, n);
    fun2(n-2);
    printf(“%d”, n);
}

void fun2(int n){
    if(n == 0) return;
      printf(“%d”, n);
      fun1(++n);
      printf(“%d”, n);
}

The output printed when fun1 (5) is called is

A

53423122233445

B

53423120112233

C

53423122132435

D

53423120213243


Ques 21 C Programming


Consider the C functions foo and bar given below:

int foo(int val)
{
    int x = 0;
    while (val > 0)
    {
        x = x + foo(val--);
    }
    return val;
}
int bar(int val)
{
    int x = 0;
    while (val > 0)
    {
        x = x + bar(val-1);
        return val;
}
}


Invocations of foo(3) and bar(3) will result in:

A

Return of 6 and 6 respectively.

B

Infinite loop and abnormal termination respectively.

C

Abnomal termination and infinite loop respectively.

D

Both terminating abnormally.


Ques 22 C Programming


Consider the C code fragment given below.

typedef struct node
{
    int data;
    node* next ;
} node;
void join(node* m, node* n)
{
    node* p = n;
    while (p->next != NULL)
    {
        p = p->next;
    }
    p–>next = m;
}

Assuming that m and n point to valid NULL- terminated linked lists, invocation of join will

A

append list m to the end of list n for all inputs

B

either cause a null pointer dereference or append list m to the end of list n

C

cause a null pointer dereference for all inputs.

D

append list n to the end of list m for all inputs.


Ques 23 C Programming


Consider the C code fragment given below.

typedef struct node
{
    int data;
    node* next ;
} node;
void join(node* m, node* n)
{
    node* p = n;
    while (p->next != NULL)
    {
        p = p->next;
    }
    p–>next = m;
}

Assuming that m and n point to valid NULL- terminated linked lists, invocation of join will

A

append list m to the end of list n for all inputs

B

either cause a null pointer dereference or append list m to the end of list n

C

cause a null pointer dereference for all inputs.

D

append list n to the end of list m for all inputs.


Ques 24 C Programming


Consider the following C code:

#include<stdio.h>
int * assignval (int *x, int val)
{
    *x = val;
    return x;
}
int main()
{
    int *x = malloc(sizeof(int));
    if (NULL == x) return;
    x = assignval(x, 0);
    if(x)
    {
        x = (int*) malloc(sizeof (int));
        if (NULL == x) return;
        x = assignval (x, 10);
    }
    printf("%dn", *x);
    free(x);
}


The code suffers from which one of the following problems:

A

compiler error as the return of malloc is not typecast appropriately.

B

compiler error because the comparison should be made as x==NULL and not as shown.

C

compiles successfully but execution may result in dangling pointer.

D

compiles successfully but execution may result in memory leak.


Ques 25 C Programming


Consider the C struct defines below:

struct data {
    int marks [100] ;
    char grade;
    int cnumber;
};
struct data student;


The base address of student is available in register R1. The field student grade can be accessed efficiently using

A

Post-increment addressing mode. (R1)+

B

Pre-decrement addressing mode, -(R1)

C

Register direct addressing mode, R1

D

Index addressing mode, X(R1), where X is an offset represented in 2’s complement 16-bit representation.


Ques 26 COA


Instruction execution in a processor is divided into 5 stages.
Instruction Fetch(IF), Instruction Decode (ID), Operand Fetch(OF), Execute(EX), and Write Back(WB),
These stages take 5,4,20, 10 and 3 nanoseconds (ns) respectively. A pipelined implementation of the processor requires buffering between each pair of consecutive stages with a delay of 2 ns. Two pipelined implementations of the processor are contemplated:

(i) a naïve pipeline implementation (NP) with 5 stages and
(ii) an efficient pipeline (EP) where the OF stage id divided into stages OF1 and OF2 with execution times of 12 ns and 8 ns respectively.


The speedup (correct to two decimals places) achieved by EP over NP in executing 20 independent instructions with no hazards is ________________.

1.50-1.51 is the correct answer.


Unique Visitor Count

Total Unique Visitors

Loading......