GATE 2016 (Session 2)
65 questions
MCQ 38 · NAT 271-mark 30 · 2-mark 35
Questions 51–55 of 65
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)
Memory is free, so use lists and arrays freely.
Pass 1. For every vertex and every entry in the list of , add a record "(u, pointer to this entry)" to a bucket list . This visits each of the entries once, so it takes . After it, has one record for each neighbour of , where is the entry stored in the list of .
Pass 2. For each vertex , first scan its own list and set to the entry in it. Then, for each record in , set the twins . The twin of is the entry in the list of . Every that is read was just written for this (the graph is simple), so needs no clearing. The work for is , so pass 2 takes .
Any algorithm must at least visit all entries (and the lists), so is needed. The total is .
Answer: (B)
Pass 1. For every vertex and every entry in the list of , add a record "(u, pointer to this entry)" to a bucket list . This visits each of the entries once, so it takes . After it, has one record for each neighbour of , where is the entry stored in the list of .
Pass 2. For each vertex , first scan its own list and set to the entry in it. Then, for each record in , set the twins . The twin of is the entry in the list of . Every that is read was just written for this (the graph is simple), so needs no clearing. The work for is , so pass 2 takes .
Any algorithm must at least visit all entries (and the lists), so is needed. The total is .
Answer: (B)
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, AB is regular.
Which one of the following is CORRECT?
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, AB is regular.
Which one of the following is CORRECT?
Answer: (B)
Let us check each statement.
- I: An NFA can have no transition on some symbol from a state. Then some strings have no path and the NFA rejects them, even when every state is accepting so the statement is FALSE.
- II: Choose . Then is regular for every language B so the statement is TRUE.
Answer: Only II is true
- I: An NFA can have no transition on some symbol from a state. Then some strings have no path and the NFA rejects them, even when every state is accepting so the statement is FALSE.
- II: Choose . Then is regular for every language B so the statement is TRUE.
Answer: Only II is true
Consider the following languages:
Which one of the following is TRUE?
Which one of the following is TRUE?
Answer: (B)
- : push a symbol for each a and each b, then pop one for each c, and accept when the stack is empty at the end. As a grammar: . So is context-free.
- : use the pumping lemma on . The pumped part has length at most p, so it cannot touch both the a's and the c's. If it misses the a's, the a's stay p, so b would have to stay p and c stay 2p, but pumping changes at least one of them. If it misses the c's, they stay 2p, so a and b would have to stay p, again impossible. So is not context-free.
Answer: (B)
- : use the pumping lemma on . The pumped part has length at most p, so it cannot touch both the a's and the c's. If it misses the a's, the a's stay p, so b would have to stay p and c stay 2p, but pumping changes at least one of them. If it misses the c's, they stay 2p, so a and b would have to stay p, again impossible. So is not context-free.
Answer: (B)
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, M denotes a specific encoding of M. Which one of the following is TRUE?
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, M denotes a specific encoding of M. Which one of the following is TRUE?
Answer: (C)
In t steps a TM can read at most the first t cells of the input. So for the first 2016 steps, M behaves on a long input exactly as it does on the prefix of that input of length 2016. If M takes at least 2016 steps on some (or every) input, the same holds for the prefixes. So only the finitely many inputs of length up to 2016 need to be checked.
L1: simulate M for 2016 steps on each such input; accept if any of them has not halted. L2: do the same, and accept only if all of them have not halted. Both procedures always stop, so L1 and L2 are recursive.
L3 (M accepts ) is a non-trivial property of L(M): some machines accept and some do not. By Rice's theorem it is undecidable, so L3 is not recursive.
Answer: (C)
L1: simulate M for 2016 steps on each such input; accept if any of them has not halted. L2: do the same, and accept only if all of them have not halted. Both procedures always stop, so L1 and L2 are recursive.
L3 (M accepts ) is a non-trivial property of L(M): some machines accept and some do not. By Rice's theorem it is undecidable, so L3 is not recursive.
Answer: (C)
Which one of the following grammars is free from left recursion?
Answer: (B)
Check each option:
- Option 1: is directly left recursive.
- Option 2: S, A and B never begin with themselves, directly or indirectly. True
- Option 3: with gives (indirect).
- Option 4: with gives (indirect).
Answer: Option 2
- Option 1: is directly left recursive.
- Option 2: S, A and B never begin with themselves, directly or indirectly. True
- Option 3: with gives (indirect).
- Option 4: with gives (indirect).
Answer: Option 2