CS GATE 2017 PAPER 01 - Online Test

Q1. 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?
Answer : Option D
Explaination / Solution:
No Explaination.


Q2. Consider the following languages over the alphabet ∑= {a, b,c}

Which of the following are context-free languages ? 
I. L∪ L2                  II. L1 ∩ L2
Answer : Option A
Explaination / Solution:



Q3. Let A and B be infinite alphabets and let # be a symbol outside both A and B. Let f be a total functional from A* to B* . We say f is computable if there exists a Turning machine M which given an input x in A* , always halts with f(x) on its tape. Let Lf denote the language {x#f(x)|x∈A*}. Which of the following statements is true:
Answer : Option A
Explaination / Solution:

A TM is recursive iff it halts for every input string (either in accept or reject state). Here, a computable function is defined in a similar way.

Q4. Consider the context-free grammars over the alphabet {a,b,c} given below. S and T are nonterminals
G1 : S → aSb|T,T → cT|∈ 
G2 : S → bSa|T,T → cT|∈
The language L(G1) ∩ L(G2) is
Answer : Option B
Explaination / Solution:

The Context free grammar given over alphabets Σ ={ a, b, c} with S and T as non terminals are:


Q5. Threads of a process share
Answer : Option D
Explaination / Solution:

Threads of a process can share all resources except stack and register set.

Q6. 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 
Answer : Option B
Explaination / Solution:

While loop in Join Procedure moves the pointer ‘p’ to the last node of the list “n”. And at the last statement, we are initializing the next of the last node of list n to start of list “m”. But in some cases it may dereference to null pointer.

Q7. Consider the C struct defined 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  
Answer : Option D
Explaination / Solution:

Direct access is possible with only index addressing mode.

Q8. Let T be a binary search tree with 15 nodes. The minimum and maximum possible heights of T are : 
Note: The height of a tree with a single node is 0.
Answer : Option B
Explaination / Solution:



Q9.  Consider the following C code:
# include <stdio.h>
int * assignval (int *x, int val) {
*x = val;
return x;
}
void 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(“%d\n”, *x);
free (x);
The code suffers from which one of the following problems: 
Answer : Option D
Explaination / Solution:

(A) is wrong. We don’t need to cast the result as void * is automatically and safely promoted to any other pointer type in this case. (B) It is discarded for obvious reason. (C) is wrong, because dangling pointer is nothing but the pointer which is pointing to non- existing memory (deallocated or deleted memory) which is not happening here. (D) is the answer. When you are calling malloc second time, new location is assigned to x and previous memory location is lost and now we don’t have no reference to that location resulting in memory leak.

Q10. Recall that Belady’s anomaly is that the pages-fault rate may increase as the number of allocated frames increases. Now consider the following statements: 
S1: Random page replacement algorithm (where a page chosen at random is replaced) suffers from Belady’s anomaly
S2: LRU page replacement algorithm suffers from Belady’s anomaly 
Which of the following is CORRECT ? 
Answer : Option B
Explaination / Solution:

Statement 1 is “TRUE”. Because there can be a case when page selected to be replaced is by FIFO policy. Statement 2 is “FALSE”. Because LRU page replacement algorithm does not suffers from Belady’s Anomaly. Only FIFO page replacement algorithm suffers from Belady’s Anomaly.