GATE 2016 CS Set 249) 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 ______________.
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 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.
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?
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 Σ ∗. Which one of the following is CORRECT?
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} Which one of the following is TRUE?
Answer: B Explanation: Given, L1 = {an bm cn+m : m, 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}, where for each Turing machine M, hMi denotes a specific encoding of M. Which one of the following is TRUE?
Answer: C Explanation: L1 = { 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?
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. Which of the grammars correctly generate the declaration mentioned above?
Answer: A Explanation: 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
Next TopicGATE 2016 CS Set 2-8
|