Toc 2
Toc 2
Ambiguous Grammar: A grammar allowing multiple parse trees for the same string.
Example: A grammar generating a+a⋅aa + a \cdot aa+a⋅a with multiple parse trees.
GNF (Greibach Normal Form): A CFG where rules begin with terminals.
Example: A→aA′A \to aA'A→aA′.
Turing Machine (TM): A machine model for defining languages and computation.
Example: TM for recognizing anbncna^n b^n c^nanbncn
IN DETAIL:-
1. Alphabets
Definition: A finite, non-empty set of symbols. These symbols are the building blocks
for strings and languages.
Example: For a binary alphabet, Σ={0,1}\Sigma = \{0, 1\}Σ={0,1}. Any sequence of 0s
and 1s can be formed using this alphabet.
Source: Page 28.
2. Strings
3. Languages
Definition: A set of strings over a given alphabet. Languages can be finite or infinite.
Example: Over Σ={a,b}\Sigma = \{a, b\}Σ={a,b}, the language L={ab,aabb,aaabbb}L =
\{ab, aabb, aaabbb\}L={ab,aabb,aaabbb} contains strings where the number of 'a's equals
the number of 'b's.
Source: Page 30.
4. Regular Expressions
5. Grammar
6. Derivation
Definition: A leftmost derivation replaces the leftmost variable first, while a rightmost
derivation replaces the rightmost variable first.
Example: For S→0S0S \to 0S0S→0S0 and S→εS \to \varepsilonS→ε:
o Leftmost: S→0S0→010S \to 0S0 \to 010S→0S0→010.
o Rightmost: S→0S0→010S \to 0S0 \to 010S→0S0→010 (same in this case).
Source: Page 175.
8. Ambiguous Grammar
Definition: A grammar is ambiguous if there exists a string derivable in more than one
way (multiple parse trees).
Example: Grammar for arithmetic expressions:
E→E+E∣E×E∣aE \to E + E | E \times E | aE→E+E∣E×E∣a
String "a + a \times a" has two parse trees due to different operator precedence.
Source: Page 205.
9. Parse Tree
markdown
Copy code
S
/ \
0 S
/ \
0 ε
Definition:
o NFA (Nondeterministic Finite Automaton): Can move to multiple states for a
single input.
o DFA (Deterministic Finite Automaton): Has exactly one transition per input for
each state.
Example:
o DFA: Recognizes strings ending in "01".
o NFA: Recognizes strings containing "01" anywhere.
Source: Pages 45, 55.
Definition: A type of grammar where each production rule has a single variable on the
left-hand side.
Example: S→0S1∣εS \to 0S1 | \varepsilonS→0S1∣ε generates strings like "01", "0011",
etc.
Source: Page 169.
Definition: A CFG where rules are either A→BCA \to BCA→BC or A→aA \to aA→a,
where A,B,CA, B, CA,B,C are variables and aaa is a terminal.
Example: S→AB,A→a,B→bS \to AB, A \to a, B \to bS→AB,A→a,B→b.
Source: Page 266.
15. Recursion
4A & b]
1. Union:
o
Definition: The union of two regular languages L1L_1L1 and L2L_2L2, denoted
L1∪L2L_1 \cup L_2L1∪L2, contains strings that belong to either L1L_1L1 or
L2L_2L2 or both.
o Proof:
Let A1A_1A1 and A2A_2A2 be the DFAs for L1L_1L1 and L2L_2L2,
respectively. Construct a new NFA that starts from a new initial state and
transitions to the start states of both A1A_1A1 and A2A_2A2.
This NFA accepts strings in L1∪L2L_1 \cup L_2L1∪L2. Since NFAs and
DFAs are equivalent, L1∪L2L_1 \cup L_2L1∪L2 is regular.
o Example: If L1={ab}L_1 = \{ab\}L1={ab} and L2={ba}L_2 = \{ba\}L2={ba},
then L1∪L2={ab,ba}L_1 \cup L_2 = \{ab, ba\}L1∪L2={ab,ba}.
o Source: Page 131.
2. Concatenation:
o Definition: Concatenation L1L2L_1L_2L1L2 includes all strings formed by
concatenating a string from L1L_1L1 with one from L2L_2L2.
o Proof:
Construct an NFA by linking the accepting states of A1A_1A1 (for
L1L_1L1) to the start state of A2A_2A2 (for L2L_2L2) via ε\varepsilonε-
transitions.
This NFA accepts L1L2L_1L_2L1L2. Hence, L1L2L_1L_2L1L2 is
regular.
o Example: If L1={a}L_1 = \{a\}L1={a} and L2={b}L_2 = \{b\}L2={b}, then
L1L2={ab}L_1L_2 = \{ab\}L1L2={ab}.
o Source: Page 131.
3. Kleene Star:
o Definition: L∗L^*L∗ includes all strings formed by concatenating zero or more
strings from LLL.
o Proof:
Extend AAA (DFA for LLL) with ε\varepsilonε-transitions from its
accepting states back to the start state. Include ε\varepsilonε as a valid
string.
The modified automaton accepts L∗L^*L∗, showing closure.
o Example: If L={ab}L = \{ab\}L={ab}, then L∗={ε,ab,abab,ababab,… }L^* =
\{\varepsilon, ab, abab, ababab, \dots\}L∗={ε,ab,abab,ababab,…}.
o Source: Page 131.
1. Intersection:
o Proof:
Given L1L_1L1 and L2L_2L2 with DFAs A1A_1A1 and A2A_2A2,
construct a product automaton.
The new DFA accepts a string if both A1A_1A1 and A2A_2A2 accept it.
Example: L1={a,ab}L_1 = \{a, ab\}L1={a,ab}, L2={ab,b}L_2 = \{ab,
b\}L2={ab,b}, then L1∩L2={ab}L_1 \cap L_2 = \{ab\}L1∩L2={ab}.
o Source: Page 131.
2. Difference:
o Proof:
Express L1−L2L_1 - L_2L1−L2 as L1∩L2‾L_1 \cap \overline{L_2}L1
∩L2.
Since regular languages are closed under intersection and complement,
they are closed under difference.
o Example: L1={a,ab}L_1 = \{a, ab\}L1={a,ab}, L2={ab}L_2 = \{ab\}L2={ab},
then L1−L2={a}L_1 - L_2 = \{a\}L1−L2={a}.
o Source: Page 131.
1. Language Description:
wwRww^RwwR is the set of strings where www is followed by its reverse, e.g., "abba",
"abcba".
2. Proof Using Pumping Lemma:
o Assume LLL is regular. Let ppp be the pumping length.
o Choose w=apbap∈Lw = a^p b a^p \in Lw=apbap∈L. Here, w=xyzw = xyzw=xyz,
where ∣xy∣≤p|xy| \leq p∣xy∣≤p and ∣y∣>0|y| > 0∣y∣>0.
o By the pumping lemma, xy2z∈Lxy^2z \in Lxy2z∈L.
Pump yyy: y=aky = a^ky=ak (as ∣xy∣≤p|xy| \leq p∣xy∣≤p), so
xy2z=ap+kbapxy^2z = a^{p+k} b a^pxy2z=ap+kbap.
ap+kbap∉La^{p+k} b a^p \notin Lap+kbap∈/L because it is not
symmetric.
o This contradicts the assumption that LLL is regular.
o Conclusion: LLL is not regular.
o Source: Page 126