Languages-and-Grammars
Question 1 |
(a) Given a set
S = {x| there is an x-block of 5's in the decimal expansion of π}
(Note: x-block is a maximal block of x successive 5’s)
Which of the following statements is true with respect to S? No reasons need to be given for the answer.
- (i) S is regular
(ii) S is recursively enumerable
(iii) S is not recursively enumerable
(iv) S is recursive
(b) Given that a language L1 is regular and that the language L1 ∪ L2 is regular, is the language L2 always regular? Prove your answer.
Theory Explanation. |
Question 2 |
Consider the following languages.
- L1 = {wxyx | w,x,y ∈ (0 + 1)+}
L2 = {xy | x,y ∈ (a + b)*, |x| = |y|, x ≠ y}
Which one of the following is TRUE?
L1 is context-free but not regular and L2 is context-free. | |
Neither L1 nor L2 is context-free.
| |
L1 is regular and L2 is context-free.
| |
L1 is context-free but L2 is not context-free. |
Question 2 Explanation:
L1 is regular. y can be expanded and w can also expanded. So x can be either "a" or "b".
So it is equivalent to
(a+b)+ a (a+b)+ a + (a+b)+ b (a+b)+ b
L2 is CFL since it is equivalent to complement of L=ww.
Complement of L=ww is CFL.
So it is equivalent to
(a+b)+ a (a+b)+ a + (a+b)+ b (a+b)+ b
L2 is CFL since it is equivalent to complement of L=ww.
Complement of L=ww is CFL.
Question 3 |
Consider the language L = {an| n≥0} ∪ {anbn| n≥0} and the following statements.
- I. L is deterministic context-free.
II. L is context-free but not deterministic context-free.
III. L is not LL(k) for any k.
Which of the above statements is/are TRUE?
II only | |
III only | |
I only | |
I and III only |
Question 3 Explanation:
L is DCFL.
We can make DPDA for this.
L is not LL(k) for any “k” look aheads. The reason is the language is a union of two languages which have common prefixes. For example strings {aa, aabb, aaa, aaabbb,….} present in language. Hence the LL(k) parser cannot parse it by using any lookahead “k” symbols.
We can make DPDA for this.
L is not LL(k) for any “k” look aheads. The reason is the language is a union of two languages which have common prefixes. For example strings {aa, aabb, aaa, aaabbb,….} present in language. Hence the LL(k) parser cannot parse it by using any lookahead “k” symbols.
Question 4 |
Which of the following statements is/are TRUE?
Every subset of a recursively enumerable language is recursive.
| |
If a language L and its complement L' are both recursively enumerable, then L must be recursive. | |
Complement of a context-free language must be recursive. | |
If L1 and L2 are regular, then L1 ∩ L2 must be deterministic context-free |
Question 4 Explanation:
Every subset of recursively enumerable need not be recursive. For example (a+b)* is a universal language and regular. Every language over alphabet {a,b} is subset of (a+b)*. This language is regular so it is recursively enumerable also and so many languages are known to be non-recursive which are definitely subset of (a+b)*. Thus every subset of recursively enumerable need not be recursive.
If L and L(complement) both are recursively enumerable then L must be recursive. It is a theorem.
Every CFL is CSL and CSL is closed under complement so complement of CFL must be CSL and every CSL is recursive. Thus the complement of CFL must be CSL, hence it must be recursive also.
If L1 and L2 are regular then their intersection must be regular, as regular languages are closed under intersection, so L1 intersection L2 must be regular, hence it must be DCFL, since every regular is also a DCFL.
If L and L(complement) both are recursively enumerable then L must be recursive. It is a theorem.
Every CFL is CSL and CSL is closed under complement so complement of CFL must be CSL and every CSL is recursive. Thus the complement of CFL must be CSL, hence it must be recursive also.
If L1 and L2 are regular then their intersection must be regular, as regular languages are closed under intersection, so L1 intersection L2 must be regular, hence it must be DCFL, since every regular is also a DCFL.
Question 5 |
Which of the following statements is/are CORRECT?
The intersection of two regular languages is regular. | |
The intersection of two context-free languages is context-free. | |
The intersection of two recursive languages is recursive. | |
The intersection of two recursively enumerable languages is recursively enumerable. |
Question 6 |
Consider the context-free grammar below (s denotes the empty string, alphabet is {a, b}):
S → ε|aSb|bSa|SS.
What language does it generate?
S → ε|aSb|bSa|SS.
What language does it generate?
(ab)∗ + (ba)∗ | |
(abba)∗ +(baab)∗ | |
(aabb)∗ + (bbaa)∗ | |
Strings of the form anbn or bnan, n any positive integer | |
Strings with equal numbers of a and b |
Question 7 |
Consider the following statements.
1. The intersection of two context-free languages is always context-free.
2. The super-set of a context-free language is never regular.
3. The subset of a decidable language is always decidable.
4. Let Σ ≡ {a, b, c} . Let L ⊆ Σ be the language of all strings in which either the number of occurrences of a is the same as the number of occurrences of b OR the number of occurrences of b is the same as the number of occurrences of c. Then, L is not context-free.
Which of the above statements are true?
1. The intersection of two context-free languages is always context-free.
2. The super-set of a context-free language is never regular.
3. The subset of a decidable language is always decidable.
4. Let Σ ≡ {a, b, c} . Let L ⊆ Σ be the language of all strings in which either the number of occurrences of a is the same as the number of occurrences of b OR the number of occurrences of b is the same as the number of occurrences of c. Then, L is not context-free.
Which of the above statements are true?
Only (1) | |
Only (1) and (2) | |
Only (1),(2) and (3) | |
Only (4) | |
None of (1), (2), (3), (4) are true |
Question 8 |
Consider the language L={n>2} on Σ={a,b}. Which ch one of the following generates the language L?
S →aA |a,A → aAb |b | |
S → aaA |λ, A → aAb|λ | |
S → aaaA |a, A → aAb|λ | |
S → aaaA |λ, A → aAb|λ |
Question 8 Explanation:
Option1 is incorrect because it can generate “a” where n=1. so given condition(n>2) is violated.
Option 2 is incorrect because it can generate “null string”. so given condition(n>2) is violated.
Option3 is incorrect because it can generate “a” where n=1. so given condition(n>2) is violated.
Option4 is correct because it can generate strings “ab,aaa, aaaab…...” where nn>2. so it is the correct option.
Question 9 |
Consider the following language families :
L1 = The context – free language
L2 = The context – sensitive language
L3 = The recursively enumerable language
L4 = The recursive language
Which one of the following options is correct?
L1 ⊆ L2 ⊆ L3 ⊆ L4 | |
L2 ⊆ L1 ⊆ L3 ⊆ L4 | |
L1 ⊆ L2 ⊆ L4 ⊆ L3 | |
L2 ⊆ L1 ⊆ L4 ⊆ L3 |
Question 9 Explanation:
Question 10 |
Consider the following grammars :
Which of the following is correct w.r.t. the above grammars?
G1 and G3 are equivalent | |
G2 and G3 are equivalent | |
G2 and G4 are equivalent | |
G3 and G4 are equivalent |
Question 11 |
Consider the following grammar :
S→0A|0BB
A→00A| λ
B→1B|11C
C→B
Which language does this grammar generate?
S→0A|0BB
A→00A| λ
B→1B|11C
C→B
Which language does this grammar generate?
L(00) * 0+(11)*1) | |
L(0(11)* + 1(00)*) | |
L((00)*0) | |
L(0(11) *1) |
Question 11 Explanation:
Option 1 is incorrect because every string generated by given grammar will contain only 0's and given option is generating string containing 1's also.
Option 2 is incorrect because it can't generate "000".
Option 3 is correct because it generates string same as given grammar do.
Option 4 is incorrect because every string generated by given grammar will contain only 0's and given option is generating string containing 1's also.
Question 12 |
Which of the following represents the language over the set A={a,b} consisting of all words beginning with one or more a’s and followed by the same number of b’s?
L= {a,ab,ab2,...} | |
L= {ambn:m,m>0,n>0} | |
L= {ambm:m>0} | |
L= {bmabn:m0,n0} |
Question 12 Explanation:
→In the option C, ambm:m>0, For a given “m” value always it generates one or more “a” s followed by Same number of “b” s.
→Example :
m=1 ⇒ ab
m=2⇒ aabb and so on.
→Example :
m=1 ⇒ ab
m=2⇒ aabb and so on.
Question 13 |
If every production is of the form where or of the form , then the grammer is said to be of:
Type 3
| |
Type 1 | |
Type 0 | |
Type 2 |
Question 14 |
What is the highest type number which can be applied to the following grammar?
S→Aa, A→Ba, B→abc
Type 0 | |
Type 1 | |
Type 2 | |
Type 3 |
Question 14 Explanation:
The given grammar is left linear grammar which is also a regular grammar. Hence the highest type number which can be applied to the following grammar is Type 3 which is notation for regular grammar.
Question 15 |
The number of productions of the following grammar is
E → E+T | T T → T*F | F F → E| id
5 | |
3 | |
6 | |
4 |
Question 15 Explanation:
Total 6 productions are there.
E->E+T
E->T
T->T*F
T->F
F->(E)
F->id
E->E+T
E->T
T->T*F
T->F
F->(E)
F->id
Question 16 |
A grammar is defined as
A→ BC
B→ x | Bx
C→ B | D
D→ y | Ey
E→ z
The non-terminal alphabet of the grammar is
A→ BC
B→ x | Bx
C→ B | D
D→ y | Ey
E→ z
The non-terminal alphabet of the grammar is
{A,B,C,D,E} | |
{B,C,D,E} | |
{A,B,C,D,E,x,y,z} | |
{x,y,z} |
Question 16 Explanation:
Since A,B,C,D,E all derive something in grammar so {A,B,C,D,E} all are non terminals, also by default we represent non terminal with capital letters.
Question 17 |
The language which is generated by the grammar S aSa | bSb | a | b over the alphabet {a,b} is the set of
Strings that begin and end with the same symbol | |
All odd and even length palindromes | |
All odd length palindromes | |
All even length palindromes |
Question 17 Explanation:
The grammar generates {a, b, aaa, aba, bab, bbb, aaaaa, aabaa, …}
So the grammar generate odd length palindrome.
So the grammar generate odd length palindrome.
Question 18 |
Which of the following statements is false?
Every context-sensitive language is recursive. | |
The set of all languages that are not recursively enumerable is countable. | |
The family of recursively enumerable languages is closed under union. | |
The families of recursively enumerable and recursive languages are closed under reversal. |
Question 18 Explanation:
Option(A) : it is correct option because L= {an bn cn} is a context sensitive language and it can also be accepted by the turing machine. Hence every CSL also recursive language.
Option(B): It is incorrect option.
Option(C): Yes it is true that recursively enumerable languages are closed under union.
Option(D): It is a correct option because recursively enumerable and recursive languages are closed under reversal.
NOTE: The difference between recursive and recursively enumerable language is that if a language is recursive then there will be definitely a turing machine which will halt and will say whether the string is accepted or not. But if a language is recursively enumerable then the turing machine will halt if the string is accepted but it is not necessary that the turing machine will halt to indicate that the string is not accepted. in this case the user might end up in infinite wait by thinking that turing machine will halt string acceptance process is still in progress.
Option(B): It is incorrect option.
Option(C): Yes it is true that recursively enumerable languages are closed under union.
Option(D): It is a correct option because recursively enumerable and recursive languages are closed under reversal.
NOTE: The difference between recursive and recursively enumerable language is that if a language is recursive then there will be definitely a turing machine which will halt and will say whether the string is accepted or not. But if a language is recursively enumerable then the turing machine will halt if the string is accepted but it is not necessary that the turing machine will halt to indicate that the string is not accepted. in this case the user might end up in infinite wait by thinking that turing machine will halt string acceptance process is still in progress.
Question 19 |
Consider the languages L1 = φ and L2 = {1}. Which one of the following represents L1* ∪ L1*L2* ?
{∈} | |
{∈, 1} | |
ϕ | |
1* |
Question 19 Explanation:
As we know, for any regular expression R,
Rϕ = ϕR=ϕ
So L1 L2 * = ϕ
and L1 * = {ϕ}* = {ϵ}
So L1L2* ∪ L1* = {ϵ}
Rϕ = ϕR=ϕ
So L1 L2 * = ϕ
and L1 * = {ϕ}* = {ϵ}
So L1L2* ∪ L1* = {ϵ}
Question 20 |
The language L={0i21i | i≥0 } over the alphabet {0.1, 2} is:
Not recursive | |
Is recursive and is a deterministic CFL | |
Is a regular language | |
Is not a deterministic CFL but a CFL |
Question 20 Explanation:
The given language is DCFL and hence recursive. First we will push 0’s in the stack and when we will see 2 then just read it and then pop 0’s corresponding to one 1.
Question 21 |
Which of the following is true for the language {ap] p is a prime]
It is not accepted by a Turing Machine | |
It is regular but not context-free | |
It is context-free but not regular | |
It is neither regular nor context-free, bt accepted by Turing machine |
Question 21 Explanation:
The sequence of p is not in arithmetice progression form due to which it not context and not regular but can be accepted by turing machine.