GATE 2007
184 questions
MCQ 1841-mark 184
Questions 106–110 of 184
In an unweighted, undirected connected graph, the shortest path from a node S to every other node is computed most efficiently, in terms of time complexity, by
Answer: (D)
Dijkstra's algorithm and Floyd-Warshall (Warshall's) also work on an unweighted graph (treat every edge weight as 1), but they are slower.
- BFS from visits vertices in order of their number of edges from , so it gives all shortest paths in time.
- Dijkstra with a heap takes .
- Warshall's algorithm finds all pairs and takes .
- DFS does not give shortest paths. It may reach a vertex by a long path first.
BFS is the fastest of these.
Answer: (D)
- BFS from visits vertices in order of their number of edges from , so it gives all shortest paths in time.
- Dijkstra with a heap takes .
- Warshall's algorithm finds all pairs and takes .
- DFS does not give shortest paths. It may reach a vertex by a long path first.
BFS is the fastest of these.
Answer: (D)
Consider the regular expression
Which one of the regular expressions given below defines the same language as defined by the regular expression R ?
Which one of the regular expressions given below defines the same language as defined by the regular expression R ?
Answer: (C)
is the set of strings that contain or .
We have the following NFA and its equivalent DFA. In the DFA, means the last symbol was a, means the last symbol was b, and means a double letter was seen.
Now remove and by state elimination. Their edges are not just deleted, they are written into the labels of the other edges:
- reads , so gets a self-loop . In the same way reads , so gets a self-loop .
- reaches by or by reading . reaches by or by reading .
So has the label , and loops on . The equivalent regular expression is , which is option (C).
The other options are wrong:
- (A) accepts (from then ), which has no or .
- (B) accepts every string, since and are both in .
- (D) needs at least one more symbol after the first double letter, so it rejects .
Answer: (C)
We have the following NFA and its equivalent DFA. In the DFA, means the last symbol was a, means the last symbol was b, and means a double letter was seen.
Now remove and by state elimination. Their edges are not just deleted, they are written into the labels of the other edges:
- reads , so gets a self-loop . In the same way reads , so gets a self-loop .
- reaches by or by reading . reaches by or by reading .
So has the label , and loops on . The equivalent regular expression is , which is option (C).
The other options are wrong:
- (A) accepts (from then ), which has no or .
- (B) accepts every string, since and are both in .
- (D) needs at least one more symbol after the first double letter, so it rejects .
Answer: (C)
Consider the regular expression
Which deterministic finite automaton accepts the language represented by the regular expression R?
Which deterministic finite automaton accepts the language represented by the regular expression R?
Answer: (A)
R is the set of strings over {a, b} that contain aa or bb.
Option A. From : a goes to , b goes to . Before any repeat, means the last symbol was a, and means it was b: goes to on b, and goes to on a. A repeat leaves this part: on a goes to (aa), and on b goes to (bb). From and , every move (a or b) goes to or , which are both final. So once aa or bb has appeared, the string is accepted whatever follows. A string with no aa and no bb alternates, ends in or , and is rejected. So A accepts exactly R. ( and behave the same, so they can be merged.)
Why the others fail:
- (B) is not a DFA: has two moves on a and none on b, and has two moves on b and none on a.
- (C) and (D) have the start state as a final state, so they accept the empty string, which has neither aa nor bb.
Note: in the paper's figure all four states of option (C) are labelled S3. They are four different states (the start state, the upper and lower states, and the final trap state).
Answer: (A)
Option A. From : a goes to , b goes to . Before any repeat, means the last symbol was a, and means it was b: goes to on b, and goes to on a. A repeat leaves this part: on a goes to (aa), and on b goes to (bb). From and , every move (a or b) goes to or , which are both final. So once aa or bb has appeared, the string is accepted whatever follows. A string with no aa and no bb alternates, ends in or , and is rejected. So A accepts exactly R. ( and behave the same, so they can be merged.)
Why the others fail:
- (B) is not a DFA: has two moves on a and none on b, and has two moves on b and none on a.
- (C) and (D) have the start state as a final state, so they accept the empty string, which has neither aa nor bb.
Note: in the paper's figure all four states of option (C) are labelled S3. They are four different states (the start state, the upper and lower states, and the final trap state).
Answer: (A)
Consider the regular expression
Which of the following non-deterministic finite automata recognizes the language defined by the regular expression R? Edges labeled denote transitions on the empty string.
Which of the following non-deterministic finite automata recognizes the language defined by the regular expression R? Edges labeled denote transitions on the empty string.
Answer: (A)
R is the set of strings with aa or bb somewhere.
Option A. The loop on skips any prefix. Then a goes to or b goes to . is entered only on a and only on b. The only way into the final state is a from (so a just after a: aa) or b from (bb). Moving between and (b from , a from ) only alternates the symbols. Once in , the loop on a, b accepts any rest. So A accepts exactly the strings that contain aa or bb.
Why the others fail: in B, C and D, has a loop on a, b. The string "aba" has neither aa nor bb, but each of these NFAs accepts it: goes to on a, loops on b at , then goes to on a.
Answer: (A)
Option A. The loop on skips any prefix. Then a goes to or b goes to . is entered only on a and only on b. The only way into the final state is a from (so a just after a: aa) or b from (bb). Moving between and (b from , a from ) only alternates the symbols. Once in , the loop on a, b accepts any rest. So A accepts exactly the strings that contain aa or bb.
Why the others fail: in B, C and D, has a loop on a, b. The string "aba" has neither aa nor bb, but each of these NFAs accepts it: goes to on a, loops on b at , then goes to on a.
Answer: (A)
Consider the following finite automata P and Q over the alphabet {a, b, c}. The start states are indicated by a double arrow and final states are indicated by a double circle. Let the languages recognized by them be denoted by L(P) and L(Q) respectively.
The automation which recognizes the language L(P)L(Q) is :
The automation which recognizes the language L(P)L(Q) is :
Answer: (A)
The language is accepted by the product automaton. A state is a pair , and on a symbol it moves to . If either machine has no move on that symbol, the pair has no move. Since every state of P and of Q is final, every reachable pair is final.
From : a goes to , b goes to , c has no move.
From : a goes to , b goes to .
From : a goes to . On b, P goes to but has no b-move, so there is none.
From : c goes to . On a or b, P has no move.
This is the automaton drawn in (A). To make it a full DFA, add a dead state for the missing moves.
Answer: (A)
From : a goes to , b goes to , c has no move.
From : a goes to , b goes to .
From : a goes to . On b, P goes to but has no b-move, so there is none.
From : c goes to . On a or b, P has no move.
This is the automaton drawn in (A). To make it a full DFA, add a dead state for the missing moves.
Answer: (A)