Question

In: Computer Science

Prove that the following language is context-free: L = { ω#x | ωR is a substring...

Prove that the following language is context-free: L = { ω#x | ωR is a substring of x and x, w ∈ {0,1}* } where ωR is ω reversed.

Solutions

Expert Solution

QUESTION:

Prove that the following language is context-free: L = { ω#x | ωR is a substring of x and x, w ∈ {0,1}* } where ωR is ω reversed.

ANSWER:

Definition - A context-free grammar (CFG) consisting of a finite set of grammar rules is a quadruple (V, T, P, S) where

  • V is a final set of non-terminal symbols.

  • T is a set of terminals where N ∩ T = NULL.

  • P is a set of rules or productions, P: N → (N ∪ T)*, i.e., the left-hand side of the production rule P does have any right context or left context.

  • S is the start symbol.

Coming to the question, Given language L = { ω # x | ωR is a substring of x and x, w ∈ {0,1}* }. [ where ωR is ω reversed ]

Here x in ω # x contains ωR as a substring in it so we can write x as a ωR b  where ω, a, b ∈ {0,1}*.

All the strings in this language share the property that they start with a string ω followed by #,
followed by anything (0,1)* , followed by ωR, followed by anything (0,1)* . So we want strings of the form : ω # a ωR b where ω, a, b ∈ {0,1}* and ωR is ω reversed .

more general form after eliminating a, b∈ {0,1}* would be ω # (0,1)* ωR (0,1)* where ωR is ω reversed.

Now for proving the given language is Context-free, we try to construct CFG productions....

Let A generate the ω # (0,1)* ωR  part, and let B generate final (0,1)*  part.Thus we want derivations that proceed as follows:

S =>* AB =>* ω A ωR =>* ω # (0,1)* ωR (0,1)*

Starting with grammer for (0,1):

C → 0 | 1 Generates (0,1)

generate the language (0,1)*:

B → CB | ε Generates (0,1)*

C → 0 | 1 Generates (0,1)

to generate the language ω # (0,1)* ωR

as we can see A → ω # B ωR [ since B Generates (0,1)* ]

so taking A → #B, gives A → ω A ωR |  #B

for example, take languages - 1 #B 1, 01 #B 10, 101 #B 101.... 000101 #B 101000 (here 000101R= 101000), etc

As we can see here the production A → 0A0 | 1A1 | #B will produce languages given in above example. Since the recursion with non-terminal A ends only when the transition A → #B, A must generate a string whose beginning and end are mirror images. Hence the non-terminal A generates all strings of the form ω # (0,1)* ωR

Finally we generate the concatenation of the two languages by adding the production S → AB

The final grammar has start symbol S, auxilliary variables A, B, C and  productions:

S → AB   Generates ω # (0,1)* ωR (0,1)*
A → 0A0 | 1A1 | #B Generates ω # (0,1)* ωR
B → CB | ε Generates (0,1)*
C → 0 | 1 Generates (0,1)

Note that this also covers the case where ω = ε. Since A is followed by B in the transition for the top-level nonterminal S, the grammar generates all strings of the form ω # (0,1)* ωR (0,1)*

Hence, we have build the CGF's for Grammer L = { ω#x | ωR is a substring of x and x, w ∈ {0,1}* } where ωR is ω reversed, it proves that the following grammer is Context-free....


Related Solutions

Is the following language a regular language? ( Prove with pumping Lenma ) L = {...
Is the following language a regular language? ( Prove with pumping Lenma ) L = { o^n 1^n 2^n | n => 0} Define CFL pumping lemma
Prove the following Closure Properties with respect to Context Free Languages. 1. Show that Context Free...
Prove the following Closure Properties with respect to Context Free Languages. 1. Show that Context Free Languages are Closed under union(∪), concatenation(·), kleene star(*). (Hint: If L1 and L2 are Context Free languages then write Context Free grammar equivalent to L1 ∪ L2, L1 · L2, L∗ 1 ) 2. Show that if L1 and L2 are Context Free Languages, then L1 ∩ L2 is not necessarily Context Free. (Hint: Use Proof by Counter Example)
Use Context-Free Pumping Lemma to prove that that following languages over the alphabet {'x', 'y', 'z'}...
Use Context-Free Pumping Lemma to prove that that following languages over the alphabet {'x', 'y', 'z'} are NOT context-free (a) {xjy2jzj : j > 0} (b) { xmynzk : m, n, k ≥ 0 and k = min(m,n) }
Show that {xx^R | x,y ∈ {0,1}*} is a context-free language. Note that x^R is the...
Show that {xx^R | x,y ∈ {0,1}*} is a context-free language. Note that x^R is the reversal of x. Show all work. Question is for Discrete Math Structures
1. Prove the language L is not regular, over the alphabet Σ = {a, b}. L...
1. Prove the language L is not regular, over the alphabet Σ = {a, b}. L = { aib2i : i > 0} 2) Prove the language M is not regular, over the alphabet Σ = {a, b}. M = { wwR : w is an element of Σ* i.e. w is any string, and wR means the string w written in reverse}. In other words, language M is even-length palindromes.
Consider two languages A and B where A is a context free language and B is...
Consider two languages A and B where A is a context free language and B is a regular language. Show that the set difference, A-B, must also be context free. Also show that B-A may not be context free
Prove that if G is a context-free grammar in which every variable occurs on the left...
Prove that if G is a context-free grammar in which every variable occurs on the left side of at most one production, then G is unambiguous.
Regular => Context-Free Give a proof by induction on regular expressions that: For any language A,...
Regular => Context-Free Give a proof by induction on regular expressions that: For any language A, if A is regular, then A is also context-free. You may assume that the statements from the previous Closure under Context-Free Languages problem are proved. R is a regular expression if RR is: a for some a∈alphabet Σ, the empty string ε, the empty set ∅, R​1​​∪R​2​​, sometimes written R​1​​∣R​2​​, where R​1​​ and R​2​​ are regular expressions, R​1​​∘R​2​​, sometimes written R​1​​R​2​​, where R​1​​ and...
L ={x^a y^b z^c | c=a+b} a) Prove that L is not regular. b)Prove by giving...
L ={x^a y^b z^c | c=a+b} a) Prove that L is not regular. b)Prove by giving a context-free grammar that the L is context free. c)Give a regular expression of the complement L'.
L ={x^a y^b z^c | c=a+b} a) Prove that L is not regular. b)Prove by giving...
L ={x^a y^b z^c | c=a+b} a) Prove that L is not regular. b)Prove by giving a context-free grammar that the L is context free. c)Give a regular expression of the complement L'.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT