Javatpoint Logo
Javatpoint Logo

GATE 2016 CS Set 2

49) The given diagram shows the flowchart for a recursive function A(n). Assume that all statements, except for the recursive calls, have O(1) time complexity. If the worst case time complexity of this function is O(nα), then the least possible value (accurate up to two decimal positions) of α is ______________.

GATE 2016 CS Set 2
  1. 2.2 to 2.4
  2. 2.1
  3. 3.2 to 3.4
  4. 3

Answer: A

Explanation:

The worst case condition occurs when non-returning paths are taking the longest root. Here, by calling A(n), we get A(n/2) 5 times so that the recurrence relation will be

A(n) = 5A(n/2) + O(1)

Hence, Solving this recurrence relation by applying masters theorem, we get

Case 1 : a > bk
        a = 5, b = 2, f(n) = O(1), nlogba = nlog25
        A(n) = nlogba = nlog25 = 2.32

Therefore option (A) is the right answer.


50) The number of ways in which the numbers 1, 2, 3, 4, 5, 6, 7 can be inserted in an empty binary search tree, such that the resulting tree has height 6, is ______________.

Note: The height of a tree with a single node is 0.

  1. 32
  2. 64
  3. 16
  4. 8

Answer: B

Explanation:

According to the question, we need the height of BST tree is 6, and we have seven distinct number that can be inserted in BST. To get height 6, we have to put either 1 or 7 at the root. Other than root, we have two options at each level either node is left node or a right node only.

Hence, the total number of BST = 1 * 26 = 64

Therefore option (B) is the right answer.


51) In an adjacency list representation of an undirected simple graph G = (V, E), each edge (u, v) has two adjacency list entries: [v] in the adjacency list of u, and [u] in the adjacency list of v. These are called twins of each other. A twin pointer is a pointer from an adjacency list entry to its twin. If |E| = m and |V | = n, and the memory size is not a constraint, what is the time complexity of the most efficient algorithm to set the twin pointer in each entry in each adjacency list?

  1. ?(n2)
  2. ?(n + m)
  3. ?(m2)
  4. ?(n4)

Answer: B

Explanation:

To represent a graph, if we use matrix, then the time complexity of the most efficient algorithm to set the twin pointer will be O(n2). Now, if we use the Adjacency list, it will be:

2(Edges + Vertices) = 2(m+n) = O(m+n).

Therefore option (B) is the right answer.


52) Consider the following two statements:

I. If all states of an NFA are accepting states then the language accepted by the NFA is Σ ∗.
II. There exists a regular language A such that for all languages B, A ∩ B is regular.

Which one of the following is CORRECT?

  1. Only I is true
  2. Only II is true
  3. Both I and II are true
  4. Both I and II are false

Answer: B

Explanation:

Statement I is False Since there is no mention of transition between states. In NFA, it can not be defined that all states have transitions for all symbols.

Statement II is True Since we know that an empty language ( A = Φ ) is regular, so its intersection with any other language is Φ. Thus A ∩ B is regular.

Therefore option (B) is the right answer.


53) Consider the following languages:

L1 = {an bm cn+m : m, n ≥ 1}
L2 = {an bn c2n : n ≥ 1}

Which one of the following is TRUE?

  1. Both L1 and L2 are context-free.
  2. L1 is context-free while L2 is not context-free.
  3. L2 is context-free while L1 is not context-free.
  4. Neither L1 nor L2 is context-free.

Answer: B

Explanation:

Given,

L1 = {an bm cn+m : m, n ≥ 1}
L2 = {an bn c2n : n ≥ 1}

L1 is context-free. The PDA can be designed in such a way that push a's into the stack, then push b's into the stack and

pop a's, b's for every c. When no c's is left in the input, and the stack is empty, then the language will be accepted.

L2 is not context-free. It is context sensitive language

{an bn: n ≥ 1} is also context-free. But when we check the equality of a's and b's with c's, then it is not possible with the stack memory of PDA.

Therefore option (B) is the right answer.


54) Consider the following languages.

L1 = {M | M takes at least 2016 steps on some input},
L2 = {M | M takes at least 2016 steps on all inputs} and
L3 = {M | M accepts ε},

where for each Turing machine M, hMi denotes a specific encoding of M. Which one of the following is TRUE?

  1. L1 is recursive and L2, L3 are not recursive
  2. L2 is recursive and L1, L3 are not recursive
  3. L1, L2 are recursive and L3 is not recursive
  4. L1, L2, L3 are recursive

Answer: C

Explanation:

L1 = { | M takes at least 2016 steps on some input}: In L1, we can stop giving input in any string once we find the string which is accepted in less than 2016 steps.

L2 = {M | M takes at least 2016 steps on all inputs}: In L2, we need to check all possible inputs whose length is less than 2016 and this string is a finite set of string.

From above it is clear that for both L1 and L2 machine is surely going to halt. Thus both L1 and L2 are recursive.

L3 = {M | M accepts ε}: L3 is undecidable because M accepts ε. So L3 is not recursive.

Therefore option (C) is the right answer.


55) Which one of the following grammars is free from left recursion?

  1. S → AB
    A → Aa | b
    B → c
  2. S→ Ab | Bb | c
    A → Bd | ε
    B → e
  3. S→ Aa | B
    A → Bb | Sc | ε
    B → d
  4. S → Aa | Bb | c
    A → Bd | ε
    B → Ae | ε

Answer: B

Explanation:

Option A has immediate left recursion because of the production rule: A->Aa.

Option C has indirect left recursion because of the production rules: S-> Aa and A->Sc

Option D has indirect left recursion as: A-> Bd and B-> Ae

Option B doesn't have any recursion (neither direct nor indirect left recursion).

Therefore option (B) is the right answer.


56) A student wrote two context-free grammars G1 and G2 for generating a single C-like array declaration. The dimension of the array is at least one. For example,

The grammars use D as the start symbol, and use six terminal symbols int ; id [ ] num.

GATE 2016 CS Set 2

Which of the grammars correctly generate the declaration mentioned above?

  1. Both G1 and G2
  2. Only G1
  3. Only G2
  4. Neither G1 nor G2

Answer: A

Explanation:

GATE 2016 CS Set 2

Therefore option (A) will be the right answer.


GATE 2016 CS Set 2-1
GATE 2016 CS Set 2-2
GATE 2016 CS Set 2-3
GATE 2016 CS Set 2-4
GATE 2016 CS Set 2-5
GATE 2016 CS Set 2-6
GATE 2016 CS Set 2-8






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA