Professional Documents
Culture Documents
• Complementation
• Union
• Intersection
• Concatenation
• Reversal
• Closure
Complementation
Let L be a language over an alphabet Σ.
The complementation of L, denoted by L ( or L’), is Σ*– L.
Example:
Let Σ = {0, 1} be the alphabet.
L = {Σ* | the number of 1’s in is even}.
L’ = {Σ* | the number of 1’s in is not even}.
L’ = {Σ* | the number of 1’s in is odd}.
Union
Let L1 and L2 be languages over an alphabet Σ.
The union of L1 and L2, denoted by L1L2, is
L1L2 = {x | x is in L1 or L2}.
Example:
{ x {0,1}* | x begins with 0 } {x{0,1}*|x ends with 0}
= {x {0,1}*| x begins or ends with 0}
Intersection
Let L1 and L2 be languages over an alphabet Σ.
The intersection of L1 and L2, denoted by L1L2, is { x | x is
in L1 and L2}.
Example:
{ x{0,1}* | x begins with 0} { x{0,1}*| x ends with 0}
= { x{0,1}*| x begins and ends with 0}
Concatenation
Let L1 and L2 be languages over an alphabet Σ.
The concatenation of L1 and L2, denoted by L1L2, is {w1w2| w1 is in
L1 and w2 is in L2}.
Example
L1 = { x {0,1}*| x begins with 0} L2 ={x {0,1}*| x ends with 0}
L1L2 = { x {0,1}*| x begins and ends with 0 and length(x) 2}
Note: N T
Derivation
• Non terminals - N
• Terminals – T
• Total alphabet - V = N T
, V * are strings in V *
is obtained from in one step
*
is obtained from in zero or more steps
a A
L(G) = { ab }
Grammar
G = ({S}, {a, b}, P, S), where
P: S → aS
S→b S S S S
a S a S
b a S
a a S
S
b
a S
b
L(G) = { b, ab, a2b, a3b,. . . } b
L(G) = { anb / n ≥ 0 }
Grammar (Examples)
G= ({E}, {+, *, (, ), id }, P, E), where
P: E → E + E (rule 1)
E E E
E → E * E (rule 2)
E → (E) (rule 3) id E + E E * E
E → id (rule 4) id
id id id
Leftmost derivation
1 4 2 4 4
E E E id E id E * E id id * E id id * id
Rightmost derivation
1 2 4 4 4
E E E E E * E E E * id E id * id id id * id
Grammar
Let G = (N, T, P, S) be a grammar.
Then L(G) is called the language generated by G.
*
*
L(G) = { w T / S w}
| | ≤ | |
• CF Type – 2 Context-free grammar
A V * A N
• REG Type – 3 Regular grammar
A aB or A b A, B N a T b T { }
Chomsky Hierarchy
Language Grammar Machine Example
Regular grammars
Finite-state
Type 3 Regular languages • Right-linear grammars automata a*
• Left-linear grammars
Push-down
Type 2 Context-free languages Context-free grammars an b n
automata
Linear-bound
Type 1 Context-sensitive languages Context-sensitive grammars a n b nc n
automata
Recursively-enumerable
Recursive
Context-sensitive
Context-free
Regular
Grammars are classified on different basis as-
L(G) = { anbnCn/ n ≥ 1 }