0% found this document useful (0 votes)
22 views

ToC -Sheet 5-

Uploaded by

mariemanwar3503
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

ToC -Sheet 5-

Uploaded by

mariemanwar3503
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

First Term, Academic Year 2020/2021

Helwan University M 416 - Theory of Computation


Faculty of since
Math. Department
Sheet 5
Context free Grammar

St. Name:

First: Choose the correct answer (1 mark)


1. The entity which accepts Language is termed as:
a) Automata
b) Tokens
c) Grammar
d) Data

2. The entity which generate Language is termed as:


a) Automata
b) Tokens
c) Grammar
d) Data

3. The Grammar can be defined as: G=(V, ∑, p, S)


In the given definition, what does S represents?
a) Accepting State
b) Starting Variable
c) Sensitive Grammar
d) None of these

4. There exists no finite automaton to accept the language?


a) L is a set of numbers divisible by 2
b) L is a set of binary complement
c) L is a set of string with odd number of 0
d) L is a set of anbn

5. It could be proved by the pumping lemma that the language --- is not regular ?
a) L is a set of numbers divisible by 2
b) L is a set of binary complement
c) L is a set of string with odd number of 0
d) L is a set of 0n1n

6. Which among the following cannot be accepted by a regular grammar?


a) L is a set of numbers divisible by 2
b) L is a set of binary complement

1
c) L is a set of string with odd number of 0
d) L is a set of 0n1n

7. Which of the expression is appropriate?


For production p: a->b where a∈V and b∈_______
a) V
b) S
c) (V+∑)*
d) V+ ∑

8. For S->0S1|e for ∑={0,1}*, which of the following is wrong for the language produced?
a) Non regular language
b) 0n1n | n>=0
c) 0n1n | n>=1
d) None of the mentioned

9. The minimum number of productions required to produce a language consisting of palindrome


strings over ∑={a,b} is
a) 3
b) 7
c) 5
d) 6

10. Which of the following statement is correct?


a) All Regular grammar are context free but not vice versa
b) All context free grammar are regular grammar but not vice versa
c) Regular grammar and context free grammar are the same entity
d) None of the mentioned

11. Are ambiguous grammar context free?


a) Yes
b) No

12. Every grammar in Chomsky Normal Form is:


a) regular
b) context sensitive
c) context free
d) all of the mentioned

13. Which of the production rule can be accepted by Chomsky grammar?


a) A->BC
b) A->a
c) S->e
d) All of the mentioned

14. Given grammar G:


(1)S->AS

2
(2)S->AAS
(3)A->SA
(4)A->aa
Which of the following productions denies the format of Chomsky Normal Form?
a) 2,4
b) 1,3
c) 1, 2, 3, 4
d) 2, 3, 4

15. Which of the following grammars are in Chomsky Normal Form:


a) S->AB|BC|CD, A->0, B->1, C->2, D->3
b) S->AB, S->BCA|0|1|2|3
c) S->ABa, A->aab, B->Ac
d) All of the mentioned

16. With reference to the process of conversion of a context free grammar to CNF, the number of
variables to be introduced for the terminals are:
S->ABa
A->aab
B->Ac
a) 3
b) 4
c) 2
d) 5

17. In which of the following, does the CNF conversion find its use?
a) CYK Algorithm
b) Bottom up parsing
c) Preprocessing step in some algorithms
d) All of the mentioned

18. Let G be a grammar: S->AB|e, A->a, B->b


Is the given grammar in CNF?
a) Yes
b) No

19. Let G be a grammar: S->AB|SA|e, A->a, B->b


Is the given grammar in CNF?
a) Yes
b) No

Second : Answer the following (2 mark)


1- Let the context-free grammar be given whose rules are
S→SbS | ScS | a.
Give all the parse trees that generate string abaca.
Furthermore, give the leftmost derivation corresponding to each of these parse trees.

3
2- Let languages L1 and L2 be generated by context-free grammars G1 =(V1,Σ,P1,S1) and G2 =
(V2,Σ,P2,S2), respectively. Give a context-free grammar that generates the language L1 ∪ L2 in
terms of G1 and G2.

3- Let (w1w2 · · ·wn)R = wn · · ·w2w1 for string w1w2 · · ·wn of length n. Give a
context-free grammar that generates {w ∈ {a, b}∗ | w = wR}.

4- Let wR be defined as in Problem 4.3. Answer the following questions.


(2) Give a context-free grammar that generates {w ∈ {a, b}∗ | w ≠ wR}.

5- Give context-free grammars that generate the following languages.


(1) {w ∈ {a, b, c, d}∗ | w = ε or w = x1 · · · xmy1 · · · ym with xi ∈ {a, b}, yi =
{c, d} for 1 ≤ i ≤ m}

(2) {w ∈ {a, b, c}∗ | w = aibj ci for i ≥ 0, j ≥ 0}

(3) {w ∈ {a, b, c, d}∗ | w = aibj cj di for i ≥ 0, j ≥ 0}

(4)∗ {aibj | 0 ≤ i ≤ j }

(5)∗ {aibj | 0 ≤ i ≤ j ≤ 2i}

(6)∗∗ {aibj ck | i, j, k are nonnegative integers that satisfy j = i +k}

6- Answer the following questions for the context-free grammar G given by the
following rules: S→aSa | aSb | bSa | bSb | ε.

(1) Give informal English descriptions of the language L(G) which the grammar generates.

(2) The language L(G) turns out to be a regular language. Give a regular grammar that
generates L(G).

7- Answer the following questions for the context-free grammar G given by the following rules:
S→aS | Sb | a | b | .
(1) Give informal English descriptions of the language L(G) which the grammar generates.

(2) Give a regular grammar that generates L(G).

4
8- Answer the following questions for the context-free grammar G given by the following rules:
S →aB | bA | ε,
A→aS | bAA,
B →bS | aBB.
(1) Give informal English descriptions of the language L(G).

9- Answer the following.


(1) Give a context-free grammar G that generates the language L = {w ∈ {a, b}∗ |
Na(w) = Nb(w)} and has the start symbol S as the only nonterminal.

10- Give a context-free grammar that generates


{w ∈ {a, b}∗ | Na(w) = 2Nb(w)},
where Nx(w) denotes the number of x’s that appear in w ∗∗.

11- Transform a context-free grammar given by the following rules to an equivalent


one in Chomsky normal form
S →aB | bA,
A→a | aS | bbA,
B →b | bS | aBB.

12- Answer the following questions for context-free languages.

(2) Give a context-free grammar that generates the language given by


{a, b}∗ − {ww | w ∈ {a, b}∗}.

You might also like