GATE 2007
184 questions
MCQ 1841-mark 184
Questions 116–120 of 184
Which of the following languages is regular?
Answer: (C)
(C) A string starts and ends with the first symbol of , and has length at least 3. Conversely, any string of length at least 3 that starts and ends with the same symbol is with . So the language is . Regular.
(A) is the set of even palindromes. The prefixes are pairwise distinguishable: the suffix gives , which is in the language, but with is not. Not regular.
(B) is the set of strings with an even-length palindrome as a proper prefix. Take the prefixes with odd . The string (, odd) is in the language only when , because the only even palindrome prefix then is , centred at . So these prefixes are pairwise distinguishable. Not regular.
(D) is the reverse of (B), because . Regular languages are closed under reversal, so it is not regular either.
Answer: (C)
(A) is the set of even palindromes. The prefixes are pairwise distinguishable: the suffix gives , which is in the language, but with is not. Not regular.
(B) is the set of strings with an even-length palindrome as a proper prefix. Take the prefixes with odd . The string (, odd) is in the language only when , because the only even palindrome prefix then is , centred at . So these prefixes are pairwise distinguishable. Not regular.
(D) is the reverse of (B), because . Regular languages are closed under reversal, so it is not regular either.
Answer: (C)
The two grammars given below generate a language over the alphabet
G1 :
G2 :
Which one of the following choices describes the properties satisfied by the strings in these languages?
G1 :
G2 :
Which one of the following choices describes the properties satisfied by the strings in these languages?
Answer: (A)
Read each grammar as a regular expression.
G1: builds a string of x's and z's, which stops with the last x or z, or is followed by . B gives , so . After the first y only y and z can appear, so no x comes after a y, that is, no y appears before any x. A y can come after an x, for example xyy, so "No y appears after any x" is wrong.
G2: gives y's and z's, and the only way to get an x is with . So each x is immediately followed by a y, and then the string goes on as S or ends: . So every x is followed by at least one y. "No x appears before any y" is wrong (xy is in the language), and "Every y is followed by at least one x" is wrong (y alone is in the language).
Answer: (A)
G1: builds a string of x's and z's, which stops with the last x or z, or is followed by . B gives , so . After the first y only y and z can appear, so no x comes after a y, that is, no y appears before any x. A y can come after an x, for example xyy, so "No y appears after any x" is wrong.
G2: gives y's and z's, and the only way to get an x is with . So each x is immediately followed by a y, and then the string goes on as S or ends: . So every x is followed by at least one y. "No x appears before any y" is wrong (xy is in the language), and "Every y is followed by at least one x" is wrong (y alone is in the language).
Answer: (A)
The language over the alphabet {0,1,2} is:
Answer: (B)
Deterministic CFL. A DPDA pushes a 0 for each 0 it reads. The symbol 2 marks the middle, so it switches state on 2 without guessing, pops one 0 for each 1, and accepts if the stack is empty at the end. So is a DCFL.
Recursive. Every CFL is recursive (a decider that always halts exists), so is recursive.
Not regular. By the pumping lemma on , the pumped part lies inside the 0s, and pumping it gives with , which is not in . So (C) is false. (A) is false because is recursive, and (D) is false because is deterministic.
Answer: (B)
Recursive. Every CFL is recursive (a decider that always halts exists), so is recursive.
Not regular. By the pumping lemma on , the pumped part lies inside the 0s, and pumping it gives with , which is not in . So (C) is false. (A) is false because is recursive, and (D) is false because is deterministic.
Answer: (B)
Which of the following problems is undecidable?
Answer: (B)
Ambiguity of CFGs (undecidable). There is no algorithm that decides whether a given context-free grammar is ambiguous. This is shown by reducing the Post Correspondence Problem (PCP), which is undecidable, to it.
Membership for CFGs (decidable). An algorithm such as CYK decides whether a string is in the language in about time.
Finiteness for FSAs (decidable). The language is infinite exactly when there is a cycle on some path from the start state to an accepting state. This can be checked on the state graph.
Equivalence for FSAs (decidable). exactly when the two sets and are both empty. FSAs are closed under complement and intersection, and emptiness is checked by looking for a reachable accepting state.
Answer: (B)
Membership for CFGs (decidable). An algorithm such as CYK decides whether a string is in the language in about time.
Finiteness for FSAs (decidable). The language is infinite exactly when there is a cycle on some path from the start state to an accepting state. This can be checked on the state graph.
Equivalence for FSAs (decidable). exactly when the two sets and are both empty. FSAs are closed under complement and intersection, and emptiness is checked by looking for a reachable accepting state.
Answer: (B)
Consider the following grammars. Names representing terminals have been specified in capital letters.
Which one of the following statements is true?
Which one of the following statements is true?
Answer: (D)
A regular grammar must be right linear (each production is or , with x a string of terminals) or left linear ( or ).
The languages are regular. For there is a right linear grammar (w = WHILE, o = OTHER):
For , add and to it.
But the grammars as given are not regular grammars. In , the production has non-terminals in the middle and at the end, so it is neither right nor left linear. In , has a non-terminal at both ends. Both grammars are context-free but not regular.
Answer: (D)
The languages are regular. For there is a right linear grammar (w = WHILE, o = OTHER):
For , add and to it.
But the grammars as given are not regular grammars. In , the production has non-terminals in the middle and at the end, so it is neither right nor left linear. In , has a non-terminal at both ends. Both grammars are context-free but not regular.
Answer: (D)