Docsity

pumping lemma questions, Quizzes of Computer Science

Toggle sidebar
bg1
1 Pumping lemma for context-free languages
The pumping lemma for context-free languages (Bar-Hillel lemma):
Let Lbe a CFL, then there exists p > 0 such that if z∈Land |z| ≥ p, then z
can be written as uvwxy where
1. |vwx| ≤ p
2. vx 6=ε
3. uvkwxky∈L∀k≥0
Pumping Lemma for CFL can be used to prove that some languages are not
context free.
Exercise 1:
Σ = {a, b, c}
L={anbncn|n≥0}
Exercise 2:
Σ = {a, b, c}
L={anbmcn|n≥m}
Exercise 3:
Σ = {a, b, c}
L={aibjck|i≤j≤k}
Exercise 4:
Σ = {a, b}
L={ww |w∈ {a, b}∗}
Exercise 5:
Σ = {a, b}
L={ap|pprime }
1
pf3

Partial preview of the text

Download pumping lemma questions and more Quizzes Computer Science in PDF only on Docsity!

1 Pumping lemma for context-free languages

The pumping lemma for context-free languages (Bar-Hillel lemma): Let L be a CFL, then there exists p > 0 such that if z ∈ L and |z| ≥ p, then z can be written as uvwxy where

  1. |vwx| ≤ p
  2. vx 6 = ε
  3. uvkwxky ∈ L ∀k ≥ 0

Pumping Lemma for CFL can be used to prove that some languages are not context free.

Exercise 1: Σ = {a, b, c} L = {anbncn^ | n ≥ 0 }

Exercise 2: Σ = {a, b, c} L = {anbmcn^ | n ≥ m}

Exercise 3: Σ = {a, b, c} L = {aibj^ ck^ | i ≤ j ≤ k}

Exercise 4: Σ = {a, b} L = {ww | w ∈ {a, b}∗}

Exercise 5: Σ = {a, b} L = {ap^ | p prime }

2 Testing membership in a CFL

We can decide the if a string w is the member of a context free language L. An efficient way to do this is the dynamic-programming (table filling) CYK (Cocke-Younger-Kasami) Algorithm. How can we decide if string w = a 1 a 2 a 3 a 4 a 5 is in L? We need the CNF grammar for L to do this, and fill out the following table.

x 15 x 14 x 25 x 13 x 24 x 35 x 12 x 23 x 34 x 45 x 11 x 22 x 33 x 44 x 55 a 1 a 2 a 3 a 4 a 5

  • Each row of the table corresponds to a particular length of substrings of w.
  • xij corresponds to the subset of variables that can generate substring aiai+1...aj
  • We start by computing substrings of length 1.
  • Substrings of length k will be generated by combining substrings of length k − l and l (for all l values).
  • The string w is a member of L, if S ∈ x 15

Exercise 1: Use the CYK algorithm to determine if baaba ∈ L(G) holds, where the productions of your grammar G are

S → AB | BC A → BA | a B → CC | b C → AB | a

Exercise 2: Use the CYK algorithm to determine if cabab ∈ L(G) holds, where the productions of your grammar G are

S → AB | b A → CB | AA | a B → AS | b C → BS | c