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 |
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 8 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 9 |
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 9 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 10 |
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 10 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 11 |
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 12 |
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 12 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 13 |
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 13 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.
Question 14 |
Let Σ = {a, b} and language L = {aa, bb}. Then, the complement of L is
{λ, a, b, ab, ba} ∪ {w∈{a, b}* | |w| > 3} | |
{a, b, ab, ba} ∪ {w∈{a, b}* | |w| > 3} | |
{w ∈ { a, b}* | |w| > 3} ∪ {a, b, ab, ba} | |
{λ, a, b, ab, ba} ∪ {w ∈ {a, b}* | |w| ≥ 3} |
Question 14 Explanation:
Complement of a language L means the complement form of given language L will contain all String except the strings that L contains.
Here L= {aa,bb}
It means complement of L can contain { λ, a, b, ab, ba, aaa, aab, aba, bba,..................}
Hence Option (D) is correct.
Here L= {aa,bb}
It means complement of L can contain { λ, a, b, ab, ba, aaa, aab, aba, bba,..................}
Hence Option (D) is correct.
Question 15 |
Which of the following statements is FALSE?
For every Non-deterministic PDA there exists an equivalent DPDA
| |
For every Non-deterministic TM there exists an equivalent deterministic TM | |
For every regular expression there exists an equivalent NFA | |
For every NFA there exists an equivalent DFA |
Question 15 Explanation:
A) False because NPDA is more powerful than DPDA.
B) True because Non deterministic TM has the same power as Deterministic TM.
C) True because regular expressions have the same power as NFA.
D) True because NFA and DFA are equivalent in power.
B) True because Non deterministic TM has the same power as Deterministic TM.
C) True because regular expressions have the same power as NFA.
D) True because NFA and DFA are equivalent in power.
Question 16 |
Which of the following statement is false?
Every regular language is also a context free language
| |
Every non deterministic turing machine can be converted to an equivalent deterministic Turing machine
| |
Every subset of recursively enumerable set is recursive | |
Every NFA can b converted into equivalent DFA
|
Question 16 Explanation:
A is true.
B is true because non deterministic Turing machines and deterministic Turing machines are equal in power.
C is false, because there are some recursively enumerable sets which are not recursive.
D is true, because NFA and DFA are equal in power.
B is true because non deterministic Turing machines and deterministic Turing machines are equal in power.
C is false, because there are some recursively enumerable sets which are not recursive.
D is true, because NFA and DFA are equal in power.
Question 17 |
The language generated by following grammar is:
S --> aSa | bSb | ε
Even length palindrome | |
a^m b^n n>=0, m>=0
| |
Odd length palindrome
| |
a^n b^m n>=1, m>=1 |
Question 17 Explanation:
The strings generated by the grammar is
{ε,aa,bb,abba,baab,aaaa,bbbb,aaaaaa,bbbbbb,aabbaa,abbbba,baaaab,bbaabb,........}.
So the given grammar generates all even length palindromes.
{ε,aa,bb,abba,baab,aaaa,bbbb,aaaaaa,bbbbbb,aabbaa,abbbba,baaaab,bbaabb,........}.
So the given grammar generates all even length palindromes.
Question 18 |
The language {am bn cm+n | m, n>=1} is:
Regular
| |
Type 0 but context sensitive
| |
Context free but not regular | |
Context sensitive but not context free
|
Question 18 Explanation:
The given language is not regular because there are infinite dependencies between a, b and c.
But the given language is context free, because the given language can be identified using stack. First push a’s in the stack, then push b,s in the stack, now on looking c’s pop b,s and then on looking c’s pop a’s. If nothing is left on the stack and c’s are finished then the string is accepted else not accepted.
But the given language is context free, because the given language can be identified using stack. First push a’s in the stack, then push b,s in the stack, now on looking c’s pop b,s and then on looking c’s pop a’s. If nothing is left on the stack and c’s are finished then the string is accepted else not accepted.
Question 19 |
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 19 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 20 |
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 20 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 21 |
Consider L=L1 ∩ L2
where L1 = {0m 1m 20n 1n | m,n ≥0}
L2 = {0m 1n 2k | m,n,k ≥0}
Then, the language L is
recursively enumerable but not context free
| |
regular | |
Context free but not regular | |
Not recursive
|
Question 21 Explanation:
L1 will first contain 0’s followed by an equal number of 1’s. After that there will be a single 2 which will again be followed by 0’s and equal number of 1’s. I.e. L1 ={ 2, 012, 00112, 20011, 01201, 0011201, 0120011, 001120011,........}
L2 = { epsilon, 0,1,2,01,12, 012, 00112, 20011, 01201, 0011201, 0120011, 001120011,........}
L=L1 ∩ L2 = { 2, 012. 00112, 0001112,.......}
L1 ∩ L2 = { 0m1m2 | m>=0}, which is a context free language but not regular language. Hence option 3 is correct.
L2 = { epsilon, 0,1,2,01,12, 012, 00112, 20011, 01201, 0011201, 0120011, 001120011,........}
L=L1 ∩ L2 = { 2, 012. 00112, 0001112,.......}
L1 ∩ L2 = { 0m1m2 | m>=0}, which is a context free language but not regular language. Hence option 3 is correct.