PREVIOUS YEAR SOLVED PAPERS - GATE 2017 Shift 1

36. Consider the following C program.
#include
#include
void printlength (char *s, char *t)
{
unsigned int c = 0;
int len = ((strlen (s) - strlen (t)) > c) ? strlen (s) : strlen (t);
printf("%d\n", 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

  • Option : C
  • Explanation : ((strlen(s) – strlen(t)) > c) ? strlen (s) : strlen (t)
    = (3 – 5 > 0)
    = (-2 > 0)
    Important point here is while comparing -2 with c, result will be a positive number as c is unsigned. So, out of these two, strlen (s) will be printed. Therefore, option c is correct
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 *


37. Consider the following languages over the alphabet ∑= {a,b,c}. Let L1 = {an bncm | m, n >= 0 } and L2 = {ambncn| m, n >= 0}.
Which of the following are context-free languages ?
I. L1 ∪ L2 
II. L1 ∩ L2

  • Option : A
  • Explanation :
    Union of context free language is also context free language.
    L1 = { an bn cm| m >= 0 and n >= 0 } and
    L2 = { am bncn| n >= 0 and m >= 0 }
    L3 = L1 ∪ L2 = { anbncm∪ ambncn| n >= 0, m >= 0 } is also context free.
    L1 says number of a’s should be equal to number of b’s and L2 says number of b’s should be equal to number of c’s. Their union says either of two conditions to be true. So it is also context free language.
    Intersection of CFG may or may not be CFG.
    L3 = L1 ∩ L2 = { anbncn| n >= 0 } need not be context free
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 *


38. Let u and v be two vectors in whose Euclidean norms satisfy What is the value of such that bisects the angle between u and v?

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 *


39. Consider the following grammar:
stmt → if exp r then else exp r ;stmt 0
exp r → termrelop term term
term → id | number
if → a | b | c
number → [0...9]
where relop is a relational operate (e.g <, >,...) ---O refers to the empty statement, and if, then, else are terminals.
Consider a program P following the above grammar containing ten if terminals. The number of control flows paths in P is _____. For example the program
if e1 then e2 else e3
has 2 controls flow paths e1→ e2 and e1 → e3

  • Option : C
  • Explanation :
    For 2 “if statements”, 22 = 4 control flow paths are possible:

    So for 10 “If statements”, control flow paths will be there.
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 *


40. In a database system, unique time stamps are assigned to each transaction using Lamport’s logical clock. Let TS(T1) and TS(T2) be the timestamps of transactions T1 and T2 respectively. Besides, T1 holds a lock on the resource R, and T2 has requested a conflicting lock on the same resource R. The following algorithm is used to prevent deadlocks in the database system assuming that a killed transaction is restarted with the same timestamp.
if TS(T2) < TS(T1) then
T1 is killed
else T2 waits.
Assume any transactions that is not killed terminates eventually. Which of the following is TRUE about the database system that uses the above algorithm to prevent deadlocks?

  • Option : A
  • Explanation :
    Given,
    if TS(T2) <TS(T1) then
    T1 is killed
    else T2 waits.
    - T1 holds a lock on the resource R
    - T2 has requested a conflicting lock on the same resource R
    According to algo, TS(T2) <TS(T1) then T1 is killed else T2 will wait. So in both cases neither deadlock will happen nor starvation.
    Therefore, option A is correct
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 2017 Shift 1