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

Automata Learning

The document provides an overview of the Theory of Computation (TOC), emphasizing its foundational concepts such as languages, automata, and grammar. It explains the significance of symbols in languages, the concept of automata as models for processing strings, and details various types of automata including deterministic and non-deterministic finite automata. Additionally, it covers the structure and function of finite automata, including transition graphs and the process of string acceptance or rejection.

Uploaded by

somefo8729
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Automata Learning

The document provides an overview of the Theory of Computation (TOC), emphasizing its foundational concepts such as languages, automata, and grammar. It explains the significance of symbols in languages, the concept of automata as models for processing strings, and details various types of automata including deterministic and non-deterministic finite automata. Additionally, it covers the structure and function of finite automata, including transition graphs and the process of string acceptance or rejection.

Uploaded by

somefo8729
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 445

CSE322

Formal Languages and Automation


Theory
Learning
School of Computer Science
and Engineering
Theory of Computation (TOC)

• Behind every implementation, there is


one theory.
• Theory gives understanding of concept,
Principals, etc…
• To know, how computer works?, TOC is
behind this.
• Three pillar of TOC are, (i.e. LAG)
– Language
– Automata
– Grammer
Theory of Computation (TOC)

• Languages:
– Important aspect of any language is symbol.
– Symbols are building block of any language.
– Symbols are : {a,b,c,d,e,0,1,2,3,4,5……}
– Alphabets = Finite set of Symbols
• Example:
• Sigma (a,b)
– String : Sequence of Alphabets
• If length of string is 2, then
• {a,b,aa,ab,bb,ba}
• If length of string is 3 or 4?
Theory of Computation (TOC)

– What is language?
• Collection of all string is called as language.
• Language can be finite or Infinite
• Example:
1)L1 : Collection of all strings of length 3, Sigma
(a,b)
{aaa,aab,aba,abb,baa,bab,bba,bbb}
2)L2: All the string should start with a and end
with a, Sigma (a,b)
{aa,aaa,aaaa……...,aba,abbba,……}
3) L3: Length should be 0
Sigma 0 = epsilon
Theory of Computation (TOC)

– What is Concept of Automata?


– It is model or machine.
Description: If we want to find any string from
given any language, then
•Its possible when strings are finite, as we can
store same, but in case of infinite, its difficult. To
resolve this issue, Automata take place.
•Mechanism
– Finite Automata
– Pushdown Automata
– Linear bound Automata
– Turing Machine
Theory of Computation (TOC)

– Power of Sigma
– If Sigma {a,b},
• Sigma power 0: Set of all strings with the length “0”
– Answer: Epsilon OR Lambda (i.e. Null String)
• Sigma power 1: Set of all strings with the length “1”
– Answer: {a,b}
• Sigma power 2: Set of all strings with the length “2”
– Answer:{aa,ab,ba,bb}
.
.
.
• Sigma power n: Set of all strings with the length “n”
• Sigma * : Kleene Clouser (i.e. Infinite String)
Theory of Computation (TOC)

– Sigma + : Positive Clouser


– Sigma + = Sigma * - Sigma 0
= Sigma * - Epsilon
Topics

 Acceptability of a String by a Finite Automaton

 Transition Graph and Properties of Transition


Functions
Finite Automaton

Input
String
Output
“Accept”
Finite or
Automaton “Reject”
Transition Graph

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4

initial accepting
state state
transition
state
Initial Configuration
Input String
a b b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Reading the Input

a b b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Input finished

a b b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4

accept
Rejection

a b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Input finished

a b a

a, b

reject
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Another Rejection

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4

reject
Another Example

a a b

a a, b

b a, b
q0 q1 q2
a a b

a a, b

b a, b
q0 q1 q2
a a b

a a, b

b a, b
q0 q1 q2
a a b

a a, b

b a, b
q0 q1 q2
Input finished

a a b

a a, b
accept

b a, b
q0 q1 q2
Rejection Example

b a b

a a, b

b a, b
q0 q1 q2
b a b

a a, b

b a, b
q0 q1 q2
b a b

a a, b

b a, b
q0 q1 q2
b a b

a a, b

b a, b
q0 q1 q2
Input finished

b a b

a a, b

b a, b
q0 q1 q2

reject
Definition

An automaton is defined as a system where energy,


materials and information are transformed,
transmitted and used for performing some functions
without direct participation of man.
Input alphabet

 a, b

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Set of States
States

Q q0 , q1, q2 , q3 , q4 , q5 
a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Initial State

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Accepting State F

Set of Accepting States


F q4 
a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Formal Definition
• Finite Automaton (FA)

M Q, ,  , q0 , F 
Q : set of states
 : input alphabet
 : transition function
q0 : initial state
F: set of accepting states
DESCRIPTION OF A FINITE AUTOMATON
MCQ
• There are ________ tuples in finite state
machine.
a) 4
b) 5
c) 6
d) unlimited
Types of Automaton
• An automaton in which the output depends only
on the input is called an automaton without a
memory.
• An automaton in which the output depends
on the states as well. is called automaton with a
finite memory.
• An automaton in which the output depends only
on the states of the machine is called a Moore
machine.
• An automaton in. which the output depends on
the state as well as on the input at any instant
of time is called a Mealy machine
An Automaton
• Basics
Block Diagram of Finite
Automaton
Diagram
Transition System
Example
Class work
• 110011
• 110110
Example Table Form
Cont.
Class Work
• Check for the 101101
• 11111
• 000000
Input alphabet (Diagram
Based)
 a, b

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Cont.
Set of States

Q q0 , q1, q2 , q3 , q4 , q5 
a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Initial State

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Accepting State F

Set of Accepting States


F q4 
a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Example
Input String
a b b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Reading the Input

a b b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Input finished

a b b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4

accept
Rejection

a b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
a b a

a, b

q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Input finished

a b a

a, b

reject
q5
a, b
b a a b
q0 a q1 b q2 b q3 a q4
Class Work
• abbbaaab
• bababaa
• abbaaba
MCQ
• Which of the following is not a part of 5-
tuple finite automata?
a) Input alphabet
b) Transition function
c) Initial State
d) Output Alphabet
DFA
Deterministic Finite Automata (DFA)
•It's finite automata with deterministic
behavior. In DFA, there is exactly one
transition from any state of finite
automata for each input symbol. It
accepts the string by halting at a final
state, and it rejects it by halting at a non-
final state.
NFA
Non-deterministic Finite Automata
(NFA)
•It's a finite automata that isn't
deterministic. In NFA, there are zero or
more transitions from any state of finite
automata for each input symbol. It
accepts the string by halting in a final
state, and it rejects the string by halting
in a non-final state or in a dead
configuration.
DFA and NFA
• Deterministic Finite Automata (DFA) and
Non-deterministic Finite Automata (NFA)
are used in fields like machine learning,
pattern matching, and formal language
recognition and verification.
• They are fundamental concepts that
help design software that can interpret
languages and patterns, and even build
compilers.
DFA VS NFA
Sr. No. DFA NFA
1 DFA stands for Deterministic Finite NFA stands for Nondeterministic Finite
Automata. Automata.

2 For each symbolic representation of the


No need to specify how does the NFA
alphabet, there is only one state
react according to some symbol.
transition in DFA.

3 NFA can be understood as multiple little


DFA can be understood as one machine.
machines computing at the same time.

4 DFA is more difficult to construct. NFA is easier to construct.

5 Time needed for executing an input Time needed for executing an input
string is less. string is more.

6 All DFA are NFA. Not all NFA are DFA.

7 Epsilon move is not allowed in DFA Epsilon move is allowed in NFA

8 DFA allows only one move for single There can be choice (more than one
input alphabet. move) for single input alphabet.
DFA
EXAMPLES
Example
• DFA Description:
• States: Q = {q0, q1}
• Alphabet: Σ = {0, 1}
• Transitions:
– δ(q0, 0) = q0
– δ(q0, 1) = q1
– δ(q1, 0) = q1
– δ(q1, 1) = q0
• Start State: q0
• Accept States: {q1}
• Question: Does the DFA accept the string "010"?
Answer
• The DFA processes "010" as follows:
• Start at q0.
• Read '0', transition to q0.
• Read '1', transition to q1.
• Read '0', transition to q1. The DFA ends
in state q1, which is not an accept state,
so it does accept "010".
Diagram

0 1 0

0 0
1
q0 q1
1
Diagram

0 1 0

0 0
1
q0 q1
1
Diagram

0 1 0

0 0
1
q0 q1
1
Diagram

0 1 0

0 0
1
q0 q1
1 Accepted
Example
• DFA Description:
• States: Q = {q0, q1}
• Alphabet: Σ = {a, b}
• Transitions:
– δ(q0, a) = q1
– δ(q0, b) = q0
– δ(q1, a) = q1
– δ(q1, b) = q0
• Start State: q0
• Accept States: {q1}
• Question: Does the DFA accept the string "ab"?
Answer
The DFA processes "ab" as follows:
•Start at q0.
•Read 'a', transition to q1.
•Read 'b', transition to q0. The DFA ends
in state q0, which is not an accept state,
so it does not accept "ab".
Example
• DFA Description:
• States: Q = {q0, q1, q2}
• Alphabet: Σ = {0, 1}
• Transitions:
– δ(q0, 0) = q1
– δ(q0, 1) = q0
– δ(q1, 0) = q2
– δ(q1, 1) = q0
– δ(q2, 0) = q2
– δ(q2, 1) = q2
• Start State: q0
• Accept States: {q2}
• Question: Does the DFA accept the string "0010"?
Answer
• Yes. The DFA processes "0010" as
follows:
• Start at q0.
• Read '0', transition to q1.
• Read '0', transition to q2.
• Read '1', transition to q2.
• Read '0', transition to q2. The DFA ends
in state q2, which is an accept state, so
it accepts "0010".
Example
• DFA Description:
• States: Q = {q0, q1, q2}
• Alphabet: Σ = {a, b}
• Transitions:
– δ(q0, a) = q1
– δ(q0, b) = q0
– δ(q1, a) = q0
– δ(q1, b) = q2
– δ(q2, a) = q2
– δ(q2, b) = q2
• Start State: q0
• Accept States: {q2}
• Question: Does the DFA accept the string "abab"?
Answer
• Yes. The DFA processes "abab" as
follows:
• Start at q0.
• Read 'a', transition to q1.
• Read 'b', transition to q2.
• Read 'a', transition to q2.
• Read 'b', transition to q2. The DFA ends
in state q2, which is an accept state, so
it accepts "abab".
Example
• DFA Description:
• States: Q = {q0, q1, q2, q3}
• Alphabet: Σ = {0, 1}
• Transitions:
– δ(q0, 0) = q1
– δ(q0, 1) = q2
– δ(q1, 0) = q3
– δ(q1, 1) = q0
– δ(q2, 0) = q0
– δ(q2, 1) = q3
– δ(q3, 0) = q2
– δ(q3, 1) = q1
• Answer: No. The DFA processes "1100" as follows:
• Start at q0.
• Read '1', transition to q2.
• Read '1', transition to q3.
• Read '0', transition to q2.
• Read '0', transition to q0. The DFA ends in state q0, which is an accept state, so
it accepts "1100".
Cont.
• Start State: q0
• Accept States: {q0}
• Question: Does the DFA accept the
string "1100"?
Answer
• No. The DFA processes "1100" as
follows:
• Start at q0.
• Read '1', transition to q2.
• Read '1', transition to q3.
• Read '0', transition to q2.
• Read '0', transition to q0. The DFA ends
in state q0, which is an accept state, so
it accepts "1100".
NFA/NDFA
EXAMPLES
Nondeterministic Finite Automaton

Alphabet ={a}

q1 a q2
a
q0
a
q3
Alphabet ={a}

Two choices q1 a q2
a
q0
a
q3
Alphabet ={a}

Two choices q1 a q2 No transition


a
q0
a
q3 No transition
First Choice

a a

q1 a q2
a
q0
a
q3
First Choice

a a

q1 a q2
a
q0
a
q3
First Choice

a a

q1 a q2
a
q0
a
q3
First Choice

a a
All input is consumed
q1 a q2 “accept”
a
q0
a
q3
Second Choice

a a

q1 a q2
a
q0
a
q3
Second Choice

a a

q1 a q2
a
q0
a
q3
Second Choice

a a

q1 a q2
a
q0
a
No transition:
q3
the automaton hangs
Second Choice

a a
Input cannot be consumed
q1 a q2
a
q0
a
q3 “reject”
Example

aa is accepted by the NFA:

“accept”
q1 a q2 q1 a q2
a a
q0
a
q0
a
q3 q3 “reject”
because this
computation
accepts aa
Rejection example

q1 a q2
a
q0
a
q3
First Choice

q1 a q2
a
q0
a
q3
First Choice

a
“reject”
q1 a q2
a
q0
a
q3
Second Choice

q1 a q2
a
q0
a
q3
Second Choice

q1 a q2
a
q0
a
q3
Second Choice

q1 a q2
a
q0
a
q3 “reject”
Example

a is rejected by the NFA:

“reject”
q1 a q2 q1 a q2
a a
q0 q0
a a
q3 q3
“reject”

All possible computations lead to rejection


Rejection example

a a a

q1 a q2
a
q0
a
q3
First Choice

a a a

q1 a q2
a
q0
a
q3
First Choice

a a a

q1 a q2
a
q0 No transition:
a
the automaton hangs
q3
First Choice

a a a
Input cannot be consumed
q1 a q2 “reject”
a
q0
a
q3
Second Choice

a a a

q1 a q2
a
q0
a
q3
Second Choice

a a a

q1 a q2
a
q0
a
q3
Second Choice

a a a

q1 a q2
a
q0
a
No transition:
q3
the automaton hangs
Second Choice

a a a
Input cannot be consumed
q1 a q2
a
q0
a
q3 “reject”
aaais rejected by the NFA:

“reject”
q1 a q2 q1 a q2
a a
q0
a
q0
a
q3 q3 “reject”

All possible computations lead to rejection


Language accepted: L {aa}

q1 a q2
a
q0
a
q3
Lambda Transitions

q0 a q1  q2 a q3
a a

q0 a q1  q2 a q3
a a

q0 a q1  q2 a q3
(read head does not move)

a a

q0 a q1  q2 a q3
a a

q0 a q1  q2 a q3
all input is consumed

a a

“accept”

q0 a q1  q2 a q3

String aa is accepted
Rejection Example

a a a

q0 a q1  q2 a q3
a a a

q0 a q1  q2 a q3
(read head doesn’t move)

a a a

q0 a q1  q2 a q3
a a a

q0 a q1  q2 a q3

No transition:
the automaton hangs
Input cannot be consumed

a a a

“reject”

q0 a q1  q2 a q3

String aaa is rejected


Language accepted: L {aa}

q0 a q1  q2 a q3
Another NFA Example

q0 a q1 b q2  q3


a b

q0 a q1 b q2  q3


a b

q0 a q1 b q2  q3


a b

q0 a q1 b q2  q3


a b

“accept”
q0 a q1 b q2  q3


Another String

a b a b

q0 a q1 b q2  q3


a b a b

q0 a q1 b q2  q3


a b a b

q0 a q1 b q2  q3


a b a b

q0 a q1 b q2  q3


a b a b

q0 a q1 b q2  q3


a b a b

q0 a q1 b q2  q3


a b a b

q0 a q1 b q2  q3


a b a b

“accept”
q0 a q1 b q2  q3


Language accepted

L ab, abab, ababab, ...



ab

q0 a q1 b q2  q3


Example
• NFA Description:
• States: Q = {q0, q1, q2}
• Alphabet: Σ = {a, b}
• Transitions:
– δ(q0, a) = {q1, q2}
– δ(q0, b) = {q0}
– δ(q1, a) = {q1}
– δ(q1, b) = {q0, q2}
– δ(q2, a) = ∅
– δ(q2, b) = {q2}
• Start State: q0
• Accept States: {q2}
• Question: Does the NFA accept the string "aab"?
Example
• NFA Description:
• States: Q = {q0, q1, q2}
• Alphabet: Σ = {a, b}
• Transitions:
– δ(q0, a) = {q0, q1}
– δ(q0, b) = {q2}
– δ(q1, a) = {q2}
– δ(q1, b) = ∅
– δ(q2, a) = {q2}
– δ(q2, b) = {q1}
• Start State: q0
• Accept States: {q2}
• Question: Does the NFA accept the string "baa"?
Example
• NFA Description:
• States: Q = {q0, q1, q2, q3}
• Alphabet: Σ = {a, b}
• Transitions:
– δ(q0, a) = {q1}
– δ(q0, b) = {q0, q2}
– δ(q1, a) = {q3}
– δ(q1, b) = {q1}
– δ(q2, a) = ∅
– δ(q2, b) = {q3}
– δ(q3, a) = {q3}
– δ(q3, b) = ∅
• Start State: q0
• Accept States: {q3}
• Question: Does the NFA accept the string "abbb"?
Example
• NFA Description:
• States: Q = {q0, q1, q2, q3}
• Alphabet: Σ = {a, b}
• Transitions:
– δ(q0, a) = {q0, q1}
– δ(q0, b) = {q2}
– δ(q1, a) = {q3}
– δ(q1, b) = {q1, q2}
– δ(q2, a) = {q1}
– δ(q2, b) = {q3}
– δ(q3, a) = {q0}
– δ(q3, b) = ∅
• Start State: q0
• Accept States: {q3}
• Question: Does the NFA accept the string "abb"?
Example
• NFA Description:
• States: Q = {q0, q1, q2}
• Alphabet: Σ = {a, b}
• Transitions:
– δ(q0, a) = {q1}
– δ(q0, b) = {q2}
– δ(q1, a) = {q0, q1}
– δ(q1, b) = {q2}
– δ(q2, a) = ∅
– δ(q2, b) = {q1, q2}
• Start State: q0
• Accept States: {q1}
• Question: Does the NFA accept the string "aab"?
Moore and Mealy Machine
• Basics:
• DFA and NFA are the finite automata
without Output, where Moore and Mealy
are the finite automata with output.
• Moore machine always give output in
+1 form, if length of string is n then
output will be n+1.
• Example: Input String = 11010 Then
• Output will be Length of String + 1 =
5+1 =6
Cont.
• Mealy machine always give output in +0
form, if length of string is n then output
will be n.
• Example: Input String = 11010 Then
• Output will be Length of String = 5
Moore Machines
• Moore Machines are finite state machines
with output value and its output depends
only on the present state. It can be
defined as (Q, q0, ∑, , δ, λ) where:
• Q is a finite set of states.
• q0 is the initial state.
• ∑ is the input symbol.
• is the output symbol.
• δ is the
transition function which maps Q×∑ → Q.
• λ is the output function which maps Q → .
Cont.
Moore
Machine
0 0

1 0 q2/b
q0/a q1/b

1 1
Cont.
•λ:Q= (What will be Output
Corresponding to states?)
Cont.
• If Input string 101101
• Then Output will be 101101= 6 + 1 =7
0 0

1 0 q2/b
q0/a q1/b

1 1

• Output = abbbaab
Cont.
• Class Work:
Input String are as mentioned below,
what will be output?
1.11101000
2.1101
3.0000110101
4.0001101010
5.1010101010
6.101011110011
Mealy Machines

Mealy machines are also finite state machines


with output value and their output depends on
the present state and current input symbol.
It can be defined as (Q, q0, ∑, , δ, λ’) where:

•Q is a finite set of states.


•q0 is the initial state.
•∑ is the input symbol.
• is the output symbol.
•δ is the
transition function which maps Q×∑ → Q.
•‘λ’ is the output function that maps Q×∑→ .
Cont.
• Mealy Machine
a/0 a/1

b/1

q0 q1

b/0
Cont.
• λ : Q x ∑ -> (What will be Output
Corresponding to states?)
Cont.
• If Input string abbab
• Then Output will be abbab = 5

• Output = 01001
Cont.
• Class Work:
Input String are as mentioned below,
what will be output?
1.aaababababa
2.bbbbaaaa
3.bababaaab
4.babababbbaa
5.babaababaaa
6.ababababaabb
Regular Language
• A regular language is a language that can
be expressed with a regular expression or a
deterministic or non-deterministic finite
automata or state machine.
• A language is a set of strings which are
made up of characters from a specified
alphabet, or set of symbols.
• Example:
• L1 =
{a,aa,aaa,aaaa,aaaaa,aaaaaa,aaaaaaa…..}
• L2 = {ab,abab,ababab,abababab…….}
Regular Expression
• We use regular expression to represent
regular languages.
• Let, R be the regular expression over
alphabet Σ, if R is,
– ε is regular expression, denoting a set {ε}
R = ε and L(R) = {ε}
– Φ is regular expression, denoting a set {Φ}
R = Φ and L(R) = { }
– For each symbol a ∈ Σ, here a is regular
expression, denoting a set {a}
R = a and L(R) = {a}
Cont.
• R1 ∪ R2 = Regular Expression (Union), this
can also represent as R1 + R2
• R1 x R2 = Regular Expression (Concatenation)
• a* is regular expression
– a*is kleene closer, it contains all strings.
– a* = {ε,a,aa,aaa,aaaa,aaaaa,aaaaaa……}
NFA to DFA
CONVERSIONS
Example
• Create an NFA, in which 2nd last bits of
binary string will be 1.

1 0,1
q0 q1 q2

0,1 State 0 1
q0 q0 q0.q1
q1 q2 q2
q2 - -
Cont.

State 0 1
q0 q0 q0q1
q0q1 q0q2 q0q1q2
q0q2 q0 q0q1
q0q1q2 q0q2 q0q1q2
Cont.

0
1
q0 q0q1
1
0 1
0
q0q2 q0q1q2 1
0
Example

State 0 1

→q0 q0 q1
q1 {q1, q2} q1
*q2 q2 {q1, q2}
Cont.

State 0 1

→q0 q0 q1
q1 {q1, q2} q1
*q2 q2 {q1, q2}

State 0 1

→[q0] [q0] [q1]


[q1] [q1, q2] [q1]
*[q2] [q2] [q1, q2]
*[q1, q2] [q1, q2] [q1, q2]
Cont.
Example

State 0 1

→q0 {q0, q1} {q1}


*q1 ϕ {q0, q1}
Cont.

State 0 1

→[q0] [q0, q1] [q1]


*[q1] ϕ [q0, q1]
*[q0, q1] [q0, q1] [q0, q1]
Cont.
Minimization of DFA
• Minimization of DFA means reducing the
number of states from given FA.
• Thus, we get the FSM(finite state machine)
with redundant states after minimizing the
FSM.
• DFA minimization stands for converting a
given DFA to its equivalent DFA with minimum
number of states.
• DFA minimization is also called as
Optimization of DFA and uses partitioning
algorithm.
Example
DFA Minimization
a
a
q0 q1 b q3 a
b
a b
q2 q4 a
a b b b
q6 q5
b a
Cont.

State a b

q0 q1 q2

q1 q3 q4

q2 q3 q5

q3 q3 q1

q4 q4 q5

q5 q5 q4

q6 q2 q6
Cont.
Transition Table

Minimization
• Remove unreachable
state from initial state.
• q6 is unreachable state
from initial state qo.
• Therefor, q6 eliminated
from the DFA.
Cont.
Transition Table

Minimization
• Now convert all state in equivalent group.
• One group will be final states and another
one will be non-final states.

G1 : {q0,q1,q2} & G2: {q3,q4,q5}


G11:{q0} G12: {q1,q2} & G21:{q3} G22:
{q4,q5}
G111:{q0} G112: {q1,q2} & G211:{q3} G212:
{q4,q5}

So, at the end, we minimized DFA (From 7 states


to 4 states).
Cont.
• Minimized DFA

q0 q3
a
a,b b
a,b
b
q1q2 q4q5
REGULAR LANGUAGE &
EXPRESSION
Regular Language
• A regular language is a language that can be
expressed with a regular expression.
– ε is regular expression, denoting a set {ε}
R = ε and L(R) = {ε}
– Φ is regular expression, denoting a set {Φ}
R = Φ and L(R) = { }
• A language is a set of strings which are made up
of characters from a specified alphabet, or set of
symbols.
• Example:
• L1 = {a,aa,aaa,aaaa,aaaaa,aaaaaa,aaaaaaa…..}
• L2 = {ab,abab,ababab,abababab…….}
Cont.
• R1 ∪ R2 = Regular Expression (Union), this
can also represent as R1 + R2
• R1 x R2 = Regular Expression (Concatenation)
• a* is regular expression
– a*is kleene closer, it contains all strings
including null.
– a* = {ε,a,aa,aaa,aaaa,aaaaa,aaaaaa……}
– a+ = a*- ε = aa* is positive closer, it
contains all strings excluding null.
– a+ =
{a,aa,aaa,aaaa,aaaaa,aaaaaa,aaaaaaa……}
Cont.
• If Σ (a,b) then Regular expression for
Finite regular language can be…
Language Expression
No string: { } Φ
Length 0: {ε} ε
Length 1: {a,b} (a+b)
Length 2: {aa,ab,ba,bb} Either aa+ab+ba+bb OR
(a+b)(a+b)
Length 3: {aaa,aab,aba……} (a+b)(a+b)(a+b)
At most 1: {ε,a,b} (ε+a+b)
At most 2:{εε, εa, (ε+a+b)
εb,aε,aa,ab,bε,ba,bb} (ε+a+b)
Not more than 2 b’s and 1 a’s: {ε, a,b, ε + a + b + b (a+b)
ab, ba, bb, abb, bab……}
Cont.
• If Σ (a,b) then Regular expression for
Infinite regular language can be…
Language Expression
All string having single “b” a* b a*
All string having at least one “b” (a+b)* b (a+b)*
All string having at least “bbbb” as (a+b)* bbbb (a+b)*
substring
All string having at least “ab” (a+b)* ab (a+b)*
All string starting with “ba” ba (a+b)*
All string beginning and ending with a (a+b)* a
“a”
All string containing “a” (a+b)* a (a+b)*
All string starting and ending with (a (a+b)* b + b (a+b)* a)
different symbol
Pumping Lemma
• Pumping Lemma is used as proof of the
irregularity of a language. It means, that if
a language is regular, it always satisfies
the pumping lemma. If at least one string
is made from pumping, not in language A,
then A is not regular.
• Why we use pumping lemma?
– To check weather language is regular or not.
• Language can finite or infinite, if language
is finite then its always regular.
Cont.
• If L is an infinite language, then there
exists some positive integer “n”
9pumping length) such that any string w
belongs to L has a length greater than
equal to “n” is |w| >= n, then w can be
divided in to three parts: w = xyz
satisfied following condition.
• 1) for each i >= 0, xy’z belongs to L
• 2) |y| > 0
• 3) |xy| < = n
Cont.
• Pumping lemma is negative test to
check, that weather language is regular
or not.

Pass
PL Undecided

Fail
Definitely not regular
Cont..
• Need to take any string from language,
then need to divide it in to 3 parts (i.e.
xyz)
• After we need to pump y, that means
need to increase y=yy or yyy or yyyy
• Therefore, xyz can be xyyz or xyyyz or
xyyyyz, then need to check weather this
string pass the test or not.
• Note: Y length, always > 0, that means
y can not be epsilon.
Example
• Suppose, we have a language a power n,
b power 2n, where n >= 0.
• Now we take one string from given
language, w= aabbbb
• Now we divide it in to 3 parts,
• x=aa, y=bb and z=bb
• Now pump value of y, that means
increase value of y.
– Therefore, now x=aa, y=bbbb and z=bb
– Now need to check, weather this string
belongs to language?
Cont.
• No, its not belongs to language so its fail in
test, that means language is not regular.
• Because, a power n and b power 2n gven
in language but after pumping b increased
and its not satisfied language given.

• Check for,
1)Language a power n and b power n
2) Language a power 2n and b power n
Arden’s Theorem
• P and Q are two regular expression over Σ
and, if P does not contain ε then the
following equation in R given by;
• R = Q+RP has unique solution, that is
R=QP*
– Lets prove same,
– R = Q+RP
– = Q+(Q+RP)P
– = Q+QP+RPP
– = Q+QP+RP^2
– =Q+QP+(Q+RP) P^2
– =Q+QP+QP^2+RP^3
– =Q(P^0+P+P^2+P^3+……
– =QP*
Example
Example-1 a,b
a
A B

R=Q+RP => R=QP*


Lets Calculate,
A= ε
B=Aa+Ba+Bb
= Aa+B (a+b)
= εa+B (a+b)
= a+B (a+b) (Therefore, this equation is Map with R=Q+RP)
= a (a+b)* (Arden’s Theorem)
Cont.
• Example-2
a a
b
A B
b
• A= ε + Aa + Bb
• B = Ab + Ba (Therefore, this equation is Map with
R=Q+RP)
• B = Aba*
• Now we will put Value of B in A,
• A = ε + Aa + Aba* b
• = ε + A(a+ba*b) (Therefore, this equation is Map with R=Q+RP)
• = ε(a+ba*b)*
Cont.
• B = Aba* (We have, now we insert A
value in this)
• B = (a+ba*b)* ba*
Lets Check for
• Class Work
a a
b
A B
b b

a
NFA (With null Move) to DFA
• Σ (a,b)
b a,b
a

ε a
q0 q1 q
2

• This is NFA, which have null move, we


need to convert it in to DFA, so we
required to remove null move from this
NFA.
Cont…

First we need to check, which one is initial state,


n we need to check, how many state connected
h initial state with null move?
Then we combined that state, which connected
h initial state with null move

q0q1
Cont.
• Further, we will check transition for new
generated state.
• Here, we need to check transition for q0 and q1
state, because new generated state is
combination of these two states.
• We check transition for all input alphabet; here we
have a and b as input alphabet so,
– For input alphabet a, we have four transition for
new state,
• One for q0, it self in self-loop
• Second from qo to q1 (As null move given in NFA)
• Third from q0 to q2 (As null move and next path
have a itself)
• Fourth from q1 to q2
Cont.
• Now we take union of q0 and q1
• Therefore, q0 U q1 = q0q1q2 U q2
= q0q1q2
a
q0q1 q0q1q2

• Now we check for input alphabet b, so


we have only one state q1 itself.
–From q0 to q1 (Using null move)
–From q1 to q1 (As its in self-loop)
Cont…
So, we get,
a
q0q1 q0q1q2

q1

Now, we check for q0q1q2 state, for both


input alphabet a and b.
Cont.
• We get,
a
q0q1 q0q1q2 a

b b

q1 q1q2

Now, we check for q1 state, for both input


alphabet a and b.
Cont.
• We get,

q0q1 a q0q1q2 a

b b

b q1 q1q2
a
q2
Cont.
• Now we check for q1q2 and q2
a
q0q1 q0q1q2 a

b b

b q1 q1q2 b
a a
q2
a,b
Class Work
• Example b a,b
a

ε a
q0 q1 q
2
a
ε
q4 q3
Class Work
• Example b a,b
a

ε a
q0 q1 q
2
ε a

q4 q3
Myhill-Nerode Theorem
• Myhill-Nerode theorem is used to
minimize the DFA.
• Important Steps:
1. Draw a table for all pairs of states (P,Q)
2.Mark all pairs, where P ∈ F and Q ∉ F.
3.If there are any unmarked pair (P,Q)
such that [δ (P,x), δ (Q,x)] is marked,
then mark [P,Q]. Here x is input symbol.
4.Combine all the unmarked pairs and
make them a single state.
Cont..
• Example

1 1
B D F 0,1
0 1
0 0 1

A C 0
E 0
1

• Minimize given DFA, using Myhill-Nerode


Theorem.
Cont.
• For Marking pair, create a Table. First,
count total number of state, then create
Table for same.

A B C D E F
A
B
C
D
E
F
Cont.
• For Marking pair, create a Table. First,
count total number of state, then create
Table for same.
A B C D E F
A
B
C
D
E
F
Cont.
• Now, we will mark respective cell, If in any
pair single state is final and another one is
non-final, then we mark particular cell.
A B C D E F
A
B
C
D
E
F
• First Cell is AB
• Both state is non-final, so we not mark.
Cont.
• Now, we will mark respective cell, If in
any pair single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M
D
E
F

• Next Cell is CA
• C is final state and A is not, so we mark.
Cont.
• Now, we will mark respective cell, If in
any pair single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D
E
F

• Next Cell is CB
• C is final state and B is not, so we mark.
Cont.
• Now, we will mark respective cell, If in
any pair single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M
E
F

• Next Cell is DA
• D is final state and A is not, so we mark.
Cont.
• Now, we will mark respective cell, If in
any pair, single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M M
E
F

• Next Cell is DB
• D is final state and B is not, so we mark.
Cont.
• Now, we will mark respective cell, If in
any pair, single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M M
E
F

• Next Cell is DC
• D is final state and C is also, so we not mark.
Cont.
• Now, we will mark respective cell, If in
any pair, single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M M
E M
F

• Next Cell is EA
• E is final state and A is not, so we mark.
Cont.
• Now, we will mark respective cell, If in
any pair, single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M M
E M M
F

• Next Cell is EB
• E is final state and B is not, so we mark.
Cont.
• Now, we will mark respective cell, If in
any pair, single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M M
E M M
F

• Next Cell is EC
• E is final state and C is also, so we not mark.
Cont.
• Now, we will mark respective cell, If in
any pair, single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M M
E M M
F

• Next Cell is ED
• E is final state and D is also, so we not mark.
Cont.
• Now, we will mark respective cell, If in any
pair, single state is final and another one is
non-final, then we mark particular cell.
A B C D E F
A
B
C M M
D M M
E M M
F
• Next Cell is FA
• F is not final state and A is also, so we not mark.
Cont.
• Now, we will mark respective cell, If in any
pair, single state is final and another one is
non-final, then we mark particular cell.
A B C D E F
A
B
C M M
D M M
E M M
F
• Next Cell is FB
• F is not final state and B is also, so we not mark.
Cont.
• Now, we will mark respective cell, If in
any pair, single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M M
E M M
F M

• Next Cell is FC
• F is not final state and B is final, so we mark.
Cont.
• Now, we will mark respective cell, If in
any pair, single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M M
E M M
F M M

• Next Cell is FD
• F is not final state and D is final, so we mark.
Cont.
• Now, we will mark respective cell, If in
any pair, single state is final and another
one is non-final, then we mark particular
cell. A B C D E F
A
B
C M M
D M M
E M M
F M M M

• Next Cell is FE
• F is not final state and E is final, so we mark.
Cont.

Now, we will check for Unmarked Pair. So, here

BA, DC, EC, ED, FA and FB is unmarked pairs,


There fore we check for same using transition
(Including both input symbol, i.e. a and b)
Cont.

Now, we will check for Unmarked Pair, so first

(B,A) – δ (B,0) = A δ (B,1) = D


- δ (A,0) = B δ (A,1) = C
Here, we Check weather output Pair mark or
not? If not mark then again we keep BA as
Cont.

Now, we will check for next Unmarked Pair, so


next

(D,C) – δ (D,0) = E δ (D,1) = F


- δ (C,0) = E δ (C,1) = F
Here, we Check weather output Pair mark or
Cont.

Now, we will check for next Unmarked Pair, so


next

(E,C) – δ (E,0) = E δ (E,1) = F


- δ (C,0) = E δ (C,1) = F
Here, we Check weather output Pair mark or
Cont.

Now, we will check for next Unmarked Pair, so


next

(E,D) – δ (E,0) = E δ (E,1) = F


- δ (D,0) = E δ (D,1) = F
Here, we Check weather output Pair mark or
Cont.
- A B C D E F
A
B
C M M
D M M
E M M
F M M M M

Now, we will check for next Unmarked Pair, so


next

(F,A) – δ (F,0) = F δ (F,1) = F


- δ (A,0) = B δ (A,1) = C
Here, we Check weather output Pair mark or not? Here
for input 1, FC pair come and its already marked so we
Cont.
- A B C D E F
A
B
C M M
D M M
E M M
F M M M M M

Now, we will check for next Unmarked Pair, so


next

(F,B) – δ (F,0) = F
- δ (B,0) = A
Here, we Check weather output Pair mark or not? Here
for input 0, FA pair come and its already marked so we
Cont.
• Now, we will combine all unmarked pairs, So
• (A,B), (D,C), (E,C) and (E,D) are unmarked
pairs.
• (A,B) is in one group and both are intermediate
state so we create one state for this
combination.
• And all other combinations are final sate, so we
combined (C,D,E) in one state.0 0,1
0
1 1
AB CDE F

• We keep remaining state, as it is. (i.e. State F)


Closure properties of regular sets
• Property 1. The union of two regular set is regular.
• Proof −
• Let us take two regular expressions
• RE1 = a(aa)* and RE2 = (aa)*
• So, L1 = {a, aaa, aaaaa,.....} (Strings of odd length
excluding Null)
• and L2 ={ ε, aa, aaaa, aaaaaa,.......} (Strings of even
length including Null)
• L1 ∪ L2 = { ε, a, aa, aaa, aaaa, aaaaa, aaaaaa,.......}
• (Strings of all possible lengths including Null)
• RE (L1 ∪ L2) = a* (which is a regular expression itself)
• Hence, proved.
Closure properties of regular sets
• Property 2. The intersection of two regular set is
regular.
• Proof −
• Let us take two regular expressions
• RE1 = a(a*) and RE2 = (aa)*
• So, L1 = { a,aa, aaa, aaaa, ....} (Strings of all possible
lengths excluding Null)
• L2 = { ε, aa, aaaa, aaaaaa,.......} (Strings of even length
including Null)
• L1 ∩ L2 = { aa, aaaa, aaaaaa,.......} (Strings of even
length excluding Null)
• RE (L1 ∩ L2) = aa(aa)* which is a regular expression itself.
• Hence, proved.
Closure properties of regular sets
• Property 3. The complement of a regular set is
regular.
• Proof −
• Let us take a regular expression −
• RE = (aa)*
• So, L = {ε, aa, aaaa, aaaaaa, .......} (Strings of even
length including Null)
• Complement of L is all the strings that is not in L.
• So, L’ = {a, aaa, aaaaa, .....} (Strings of odd length
excluding Null)
• RE (L’) = a(aa)* which is a regular expression itself.
• Hence, proved.
Closure properties of regular sets
• Property 4. The difference of two regular set is
regular.
• Proof −
• Let us take two regular expressions −
• RE1 = a (a*) and RE2 = (aa)*
• So, L1 = {a, aa, aaa, aaaa, ....} (Strings of all possible
lengths excluding Null)
• L2 = { ε, aa, aaaa, aaaaaa,.......} (Strings of even
length including Null)
• L1 – L2 = {a, aaa, aaaaa, aaaaaaa, ....}
• (Strings of all odd lengths excluding Null)
• RE (L1 – L2) = a (aa)* which is a regular expression.
Closure properties of regular sets
• Property 5. The reversal of a regular set is regular.
• Proof −
• We have to prove LR is also regular if L is a regular set.
• Let, L = {01, 10, 11, 10}
• RE (L) = 01 + 10 + 11 + 10
• LR = {10, 01, 11, 01}
• RE (LR) = 01 + 10 + 11 + 10 which is regular
• Hence, proved.
• Property 6. The closure of a regular set is regular.
• Proof −
• If L = {a, aaa, aaaaa, .......} (Strings of odd length excluding Null)
• i.e., RE (L) = a (aa)*
• L* = {a, aa, aaa, aaaa , aaaaa,……………} (Strings of all lengths excluding Null)
• RE (L*) = a (a)*
• Hence, proved.
Closure properties of regular sets
• Property 7. The concatenation of two regular sets is
regular.
• Proof −
• Let RE1 = (0+1)*0 and RE2 = 01(0+1)*
• Here, L1 = {0, 00, 10, 000, 010, ......} (Set of strings
ending in 0)
• and L2 = {01, 010,011,.....} (Set of strings beginning
with 01)
• Then, L1 L2 =
{001,0010,0011,0001,00010,00011,1001,10010,.......
......}
• Set of strings containing 001 as a substring which can
be represented by an RE − (0 + 1)*001(0 + 1)*
Regular Expression to FA
• Example: ba*b
• First we need to generate strings from
above language, So
• bb
• bab
• baaab
• baaaab
• baaaaab
• ba^nb
Cont.
• So we can design below FA.

b b
A B C
Cont.
• Example: (a+b) c
• First we need to generate strings from
above language, So
• ac
• bc
• So we can design below FA.
a
c
A B C
b
Cont.
• Example: a(bc)*
• First we need to generate strings from
above language, So
•a
• abc
• abcbc
• abcbcbc a
A B
b c
C
RG to RE (Grammar to Expression)
• Its Regular Grammar, Which generated
regular language, which is accepted by
finite automata.
RG

RL

FA
Cont…

Finite
Automata

Regular
Expressio
n
Regular Regular
Language Gramma
r
Cont…
• Convert the following left recursive
grammar in to Regular Expression.
• A Aa/b
A A

b A a

A a
Answer: ba*
A b
Cont..
• AAa/b1/b2
• Answer: (b1+b2)a*
• AAa/b1/b2/………bn
• Answer: (b1+b2+……+bn)a*
• AAa1/Aa2/b
• Answer: (a1+a2)*b
• AAa1/Aa2/……Aan/b
• Answer: (a1+a2+……+an)*b
• AAa1/Aa2/………Aan/b1/b2………bn
• Answer: (a1+a2+…….+an)* (b1+b2+…..
+bn)*
Examples
• S01S/01
• Answer: (01)* 01 = 01^+
• S0011S/01/10
• Answer: (0011)* (01+10)

• S01A/B11
• 01(011)*01 + (101)*1111
• A011A/01
• (011)*01
• B101B/11
• (101)*11
Cont…
• S011A/101B
• A110A/00
• B11B/S
• Answer:
• A110A/00 (110)*00
• Now, I put value of A in S,
• S0011(110)*00/101B
• Now I solve B
• B11B/S (11)*S
• Now Solve S:
• S0011(110)*00/101(11)*S
• (101(11)*)*0011(110)*00
RL to RG
• a*bc
• a*b*c*(x+y)
• (a+b+c+d)z*
• a^+
Right RG to FA
• S01S/1
Cont…
• S011S/01
Cont…
• S001S/10A
• A101A/0/1
Left RG to FA
• Reverse the right hand side of every
production
• Construct FA
• Interchange initial state and final state
• Change the direction of edges
Cont…
• SS10/01
• S01S/10
Example
• S0101S/10
• SS110/01
Regular Expressions
• The language accepted by finite automata can be
easily described by simple expressions called Regular
Expressions. It is the most effective way to represent
any language.
• The languages accepted by some regular expression
are referred to as Regular languages.
• A regular expression can also be described as a
sequence of pattern that defines a string.
• Regular expressions are used to match character
combinations in strings. String searching algorithm
used this pattern to find the operations on a string.
Regular Expression
Phi- Empty Set; Epsilon- Null String: String is there but its null
• In a regular expression, x* means zero
or more occurrence of x. It can generate
{e, x, xx, xxx, xxxx, .....}
• In a regular expression, x+ means one or
more occurrence of x. It can generate
{x, xx, xxx, xxxx, .....}
Regular Expressions
We give a formal recursive definition of regular expressions over
∑ as follows:
1. Any terminal symbol (i.e. an element of ∑), Λ and ∅ are
regular
expressions. When we view a in ∑ as a regular expression, we
denote it by a.
2. The union of two regular expressions R1and R2 , written as R 1 +
R2, is also a regular expression.
3. The concatenation of two regular expressions R1and R2, written
as
R1 R2, is also a regular expression.
4. The iteration (or closure) of a regular expression R written as R*,
is
also a regular expression.
5.If R is a regular expression, then (R) is also a regular expression.
6. The regular expressions over∑ are precisely those obtained
recursively by the application of the rules 1-5 once or several times
Definitions
Any set represented by a regular
expression is called a regular set.
If for example, a, b ε ∑. Then
(i) a denotes the set {a},

(ii) a + b denotes {a, b},

(iii) ab denotes {ab},

(iv) a* denotes the set {lambda, a, aa. aaa, ... } and

(v) (a + b)* denotes {a, b}*. The set represented by R is


denoted by L(R),
Questions

Describe the following sets by regular


expressions:
(a) {101}
(b) {abba}
(c) {01,10}
(d) {Λ ,ab}
(e) {abb,a, b, bba}
(f){Λ , 0, 00, 000.... }
(g) {1, 11, 111 ... }
Solution
(a) Now. {1}. {O} are represented by 1 and O. respectively. 101
is obtained
by concatenating 1,0 and 1 So. {10 I} is represented by 1*0*1.

(b) abba represents {abba}.

(c) As {01, 10} is the union of {01} and {10}, we have {01, 10}
represented by 01 + 10

(d) The set {Λ , ab} is represented by Λ + ab

(e) The set {abb, a, b, bba} is represented by abb + a + b + bba.

f) As {Λ , 0, 00, 000, ... } is simply {O}*. it is represented by 0*

(g) Any element in {1, 11, 111, ... } can be obtained by


concatenating
1 and any element of {1}*. Hence 1(1)* represents {1, 11,
111, ... }
Example 1:
Write the regular expression for the language accepting all
combinations of a's, over the set ∑ = {a}
Example 1:
Write the regular expression for the language accepting all
combinations of a's, over the set ∑ = {a}
Solution:
All combinations of a's means a may be zero, single, double and so
on. If a is appearing zero times, that means a null string. That is
we expect the set of {ε, a, aa, aaa, ....}. So we give a regular
expression for this as:
R = a*
That is Kleen closure of a.
Example 2:

• Write the regular expression for the language


accepting all combinations of a's except the null
string, over the set ∑ = {a}
Example 2:

• Write the regular expression for the language


accepting all combinations of a's except the null
string, over the set ∑ = {a}
• Solution:
The regular expression has to be built for the language
L = {a, aa, aaa, ....}
This set indicates that there is no null string. So we can
denote regular expression as:
R = a+
Example 3:

Write the regular expression for the language


accepting all the string containing any
number of a's and b's.
Example 3:

Write the regular expression for the language


accepting all the string containing any
number of a's and b's.

Solution:
The regular expression will be:
r.e. = (a + b)*
This will give the set as L = {ε, a, aa, b, bb, ab, ba, aba,
bab, .....}, any combination of a and b.
The (a + b)* shows any combination with a and b even a
null string.
Example 4
• Write the regular expression for the language
accepting all the string which are starting with
1 and ending with 0, over ∑ = {0, 1}.
Example 4
• Write the regular expression for the language
accepting all the string which are starting with
1 and ending with 0, over ∑ = {0, 1}.
Solution:
In a regular expression, the first symbol should be 1, and the
last symbol should be 0. The r.e. is as follows:
R = 1 (0+1)* 0
Example 5
• Write the regular expression for the language
starting and ending with a and having any
having any combination of b's in between.
Example 5
• Write the regular expression for the language
starting and ending with a and having any
having any combination of b's in between.
• Solution:
The regular expression will be:
R = a b* b
Example
• Write the regular 6
expression for the
language starting with a but not having
consecutive b's.
Example
• Write the regular 6
expression for the
language starting with a but not having
consecutive b's.
Solution:
The regular expression has to be built for the
language:
L = {a, aba, aab, aba, aaa, abab, .....}
The regular expression for the above
language is:
R = {a + ab}*
Example 7
Write the regular expression for the language accepting
all the string in which any number of a's is followed
by any number of b's is followed by any number of
c's.
Example 7
Write the regular expression for the language accepting
all the string in which any number of a's is followed
by any number of b's is followed by any number of
c's.
• Solution:
As we know, any number of a's means a* any number of b's means
b*, any number of c's means c*. Since as given in problem
statement, b's appear after a's and c's appear after b's. So the
regular expression could be:
R = a* b* c*
Example 8
• Write the regular expression for the language
over ∑ = {0} having even length of the string.
Example 8
• Write the regular expression for the language
over ∑ = {0} having even length of the string.
Solution:
The regular expression has to be built for the
language:
L = {ε, 00, 0000, 000000, ......}
The regular expression for the above language
is:
R = (00)*
Example 9
• Write the regular expression for the
language having a string which should
have atleast one 0 and alteast one 1.
Example 9
• Write the regular expression for the
language having a string which should
have atleast one 0 and alteast one 1.
Solution:
The regular expression will be:
R = [(0 + 1)* 0 (0 + 1)* 1 (0 + 1)*] + [(0
+ 1)* 1 (0 + 1)* 0 (0 + 1)*]
• Describe the language denoted by
following regular expression
RE. = (b* (aaa)* b*)*
• Describe the language denoted by
following regular expression
RE. = (b* (aaa)* b*)*
The language can be predicted from the regular
expression by finding the meaning of it. We will first
split the regular expression as:
r.e. = (any combination of b's) (aaa)* (any combination
of b's)
L = {The language consists of the string in which a's
appear triples, there is no restriction on the number
of b's}
Problem
Solution
IDENTITIES FOR
REGULAR
`
EXPRESSIONS
Which among the following are incorrect
regular identities?
a) εR=R
b) ε*=ε
c) Ф*=ε
d) RФ=R
Answer: d
Explanation: I2: There are few identities
over Regular Expressions which include:
RФ=ФR=Ф
(0+ε) (1+ε) represents
a) {0, 1, 01, ε}
b) {0, 1, ε}
c) {0, 1, 01 ,11, 00, 10, ε}
d) {0, 1}
Answer: a
Explanation: The regular expression is
fragmented and the set of the strings
eligible is formed. ‘+’ represents union
while ‘.’ Represents concatenation.
Which of the following is correct?
Statement 1: ε represents a single string in the set.

Statement 2: Ф represents the language that consist of


no string.

a.Statement 1 and 2 both are correct


b.Statement 1 is false but 2 is correct
c. Statement 1 and 2 both are false
d. There is no difference between both the statements,
ε and Ф are different notation for same reason
Answer: (a).Statement 1 and 2 both are
correct
Let for ∑= {0,1} R= (∑∑∑) *, the language of R
would be
a.{w | w is a string of odd length}
b.{w | w is a string of length multiple of 3}
c.{w | w is a string of length 3}
d.All of the mentioned
Answer: (b).{w | w is a string of length
multiple of 3}
If ∑= {0,1}, then Ф* will result to:
a. ε
b. Ф
c. ∑
d. None of the mentioned
Regular Expression denote precisely the
________ of Regular Language.
a) Class
b) Power Set
c) Super Set
d) None of the mentioned
Answer: a
Explanation: Regular Expression denote
precisely the class of regular language.
Given any regular expression, L(R) is a
regular language.
Given any regular language L, there is a
regular expression R, such that L(R)=L.
Pumping Lemma
While applying Pumping lemma over a
language, we consider a string w that
belong to L and fragment it into _________
parts.
a) 2
b) 5
c) 3
d) 6
If we select a string w such that w∈L,
and w=xyz. Which of the following
portions cannot be an empty string?
a) x
b) y
c) z
d) all of the mentioned
Answer: b

Explanation: The lemma says, the portion y in xyz cannot be zero


or empty i.e. |y|>0, this condition needs to be fulfilled to check the
conclusion condition
There exists a language L. We define a
string w such that w∈L and w=xyz and |
w| >=n for some constant integer n.What
can be the maximum length of the
substring xy i.e. |xy|<=?
a) n
b) |y|
c) |x|
d) none of the mentioned
Answer: a

Explanation: It is the first conditional


statement of the lemma that states that |
xy|<=n, i.e. the maximum length of the
substring xy in w can be n only.
f d is a final state, which of the following is correct according to the given diagra

a) x=p, y=qr, z=s


b) x=p, z=qrs
c) x=pr, y=r, z=s
d) All of the mentioned
Let w be a string and fragmented by
three variable x, y, and z as per pumping
lemma. What does these variables
represent?
a) string count
b) string
c) string count and string
d) none of the mentioned
ARDEN’S THEORM

Theorem :
(Arden' s theorem) Let P and Q be two regular
expressions over ∑. If P does not contain Λ, then
the following equation in R, namely
R = Q + RP
has a unique solution (i.e. one and only one
solution) given by R = QP*.
Ardens Theorem
Example 1: Constructing RE for
NDFA
Example 2: Constructing RE for
DFA
Example 3
Example 4
P, O, R be regular expression over ∑, P is
not ε, then
R=Q + RP has a unique solution:
a) Q*P
b) QP*
c) Q*P*
d) (P*O*) *
Arden’s theorem is true for:
a) More than one initial states
b) Null transitions
c) Non-null transitions
d) None of the mentioned
Answer: c
Explanation: Arden’s theorem strictly
assumes the following;
a) No null transitions in the transition
diagrams
b) True for only single initial state
Closure Properties of Regular
Language
THEORM

Proof
Q + (QP*)P = Q(Λ+ P*P) = QP* by I9
Important justification
PROBLEM
SOLUTION
PROBLEM & SOLUTION
Difference between Null and Ø
TRANSITION SYSTEM CONTAINING Λ -
MOVES
Suppose we want to replace a Λ -move from vertex V1 to vertex
V2' Then
we proceed as follows:

Step 1- Find all the edges starting from V2.

Step 2- Duplicate all these edges starting from V1' without


changing the edge
labels.

Step 3- If V1 is an initial state, make V2 also as initial state.

Step 4- If V2 is a final state. make V1 also as the final state.


EXAMPLE
EXAMPLE
Construct RE from given FA
Convert this automata with null
moves to automata without it
Construct RE from Finite Automata
answer
• (a + a(b + aa)*b)*a(b + aa)*a
Construct RE from given DFA
Answer
• (ab + ba)*
Construct RE from given DFA, take
q1 as initial state
Answer
• 0*(1*)
Construct RE from given DFA
Answer
• (0 + 1(1 + 01)* 00)*
Construct RE from given DFA
• Q1 as initial state
• (0 + 1(1 + 011)*(00 + 010)*(1(1 +
011)* 01)
Closure properties of regular sets
• Property 1. The union of two regular set is regular.
• Proof −
• Let us take two regular expressions
• RE1 = a(aa)* and RE2 = (aa)*
• So, L1 = {a, aaa, aaaaa,.....} (Strings of odd length
excluding Null)
• and L2 ={ ε, aa, aaaa, aaaaaa,.......} (Strings of even
length including Null)
• L1 ∪ L2 = { ε, a, aa, aaa, aaaa, aaaaa, aaaaaa,.......}
• (Strings of all possible lengths including Null)
• RE (L1 ∪ L2) = a* (which is a regular expression itself)
• Hence, proved.
Closure properties of regular sets
• Property 2. The intersection of two regular set is
regular.
• Proof −
• Let us take two regular expressions
• RE1 = a(a)* and RE2 = (aa)*
• So, L1 = { a,aa, aaa, aaaa, ....} (Strings of all possible
lengths excluding Null)
• L2 = { ε, aa, aaaa, aaaaaa,.......} (Strings of even length
including Null)
• L1 ∩ L2 = { aa, aaaa, aaaaaa,.......} (Strings of even
length excluding Null)
• RE (L1 ∩ L2) = aa(aa)* which is a regular expression itself.
• Hence, proved.
Closure properties of regular sets
• Property 3. The complement of a regular set is
regular.
• Proof −
• Let us take a regular expression −
• RE = (aa)*
• So, L = {ε, aa, aaaa, aaaaaa, .......} (Strings of even
length including Null)
• Complement of L is all the strings that is not in L.
• So, L’ = {a, aaa, aaaaa, .....} (Strings of odd length
excluding Null)
• RE (L’) = a(aa)* which is a regular expression itself.
• Hence, proved.
Closure properties of regular sets
• Property 4. The difference of two regular set is
regular.
• Proof −
• Let us take two regular expressions −
• RE1 = a (a*) and RE2 = (aa)*
• So, L1 = {a, aa, aaa, aaaa, ....} (Strings of all possible
lengths excluding Null)
• L2 = { ε, aa, aaaa, aaaaaa,.......} (Strings of even
length including Null)
• L1 – L2 = {a, aaa, aaaaa, aaaaaaa, ....}
• (Strings of all odd lengths excluding Null)
• RE (L1 – L2) = a (aa)* which is a regular expression.
Closure properties of regular sets
• Property 5. The reversal of a regular set is regular.
• Proof −
• We have to prove LR is also regular if L is a regular set.
• Let, L = {01, 10, 11, 10}
• RE (L) = 01 + 10 + 11 + 10
• LR = {10, 01, 11, 01}
• RE (LR) = 01 + 10 + 11 + 10 which is regular
• Hence, proved.

• Property 6. The closure of a regular set is regular.


• Proof −
• If L is R* then L* will be (R*)* which is also a regular expression (I8)
• Hence, proved.
Closure properties of regular sets
• Property 7. The concatenation of two regular sets is
regular.
• Proof −
• Let RE1 = (0+1)*0 and RE2 = 01(0+1)*
• Here, L1 = {0, 00, 10, 000, 010, ......} (Set of strings
ending in 0)
• and L2 = {01, 010,011,.....} (Set of strings beginning
with 01)
• Then, L1 L2 =
{001,0010,0011,0001,00010,00011,1001,10010,.......
......}
• Set of strings containing 001 as a substring which can
be represented by an RE − (0 + 1)*001(0 + 1)*
Construct FA Equivalent to regular
expression
Construct FA Equivalent to regular
expression
• 10 + (0 + 11)0*1
• (0 +1 )*(00 + 11)(0 + 1)*
Equivalence of 2 regular expression
• Prove (a + b)* =a*(ba*)* by
constructing regular expressions
CONSTRUCTION OF A REGULAR GRAMMAR
GENERATING T(M) FOR A GIVEN DFA M
• Construct a regular grammar G
generating the regular set represented
by
• P = a*b(a + b)*.
CONSTRUCTION OF A TRANSITION
SYSTEM M
ACCEPTING L(G) FOR A GIVEN
REGULAR
GRAMMAR G
• Let G =({Ao, A1,, {a. b}. P, Ao). where P
consists of Ao->aA1,A1->bA1,A1->a,A1-
>bA0
• Construct a transition system M
accepting L(G).
Pumping Lemma
MyHill Nerode Theorem
Equivalence of 2 Regular
Expressions: Example 1
(1 + 00*1) + (1 + 00*1)(1 + 10*1)*(1 + 10*1) =
0*1(1+10*1)*

Take (1 + 00*1) as common


(1 + 00*1) (ε +(1 + 10*1)*(1 + 10*1))
The above equation is of type (ε + R*R) where R = (1 +
00*1). (ε + R*R) can be written as R*
(1 + 00*1)(1 + 10*1)*
Take 1 as common
(ε + 00*)1(1 + 10*1)*
(ε + 00*) can be written as 0*
0*1(1 + 10*1)* =R.H.S.
Example 2
((00*(01)*0) + 0*(10)*)* = (0 + 10)*

From the identity rules (PQ)*P = P(QP)* Substitute the


identity rule in the given equation.
((00*0(10)*) + 0*(10)*)*
We take (10)* common
((00*0 + 0*)(10)*)*
We take (00*0 + 0*) as 0* because RR*=R* and R+R=R
(0*(10)*)*
We use the identity rule (A + B)* = (A*B*)* we write:
(0 + 10)*
UNIT IV SYLLABUS
• Ambiguity in Context Free Grammar,
Language of a Context Free Grammar,
Applications of Context Free Grammar,
Pumping Lemma for Context Free Grammar,
Normal Forms for Context Free Grammar -
Chomsky Normal Form, Greibach Normal
Form, Context-Free Languages and Derivation
Trees, Leftmost and Rightmost derivations,
Sentential forms, Construction of Reduced
Grammars, Elimination of null and unit
productions
CFG?
• Formal Definition of CFG
• CFG (V,T,P,S)
• V: Finite set of Variable (Non-Terminal)
• T: Finite set of Terminal (V ∪ T) ≠ Φ
• P: Production Rules (Substitution Rules)
• S: Start Symbol

• CFG is type-2 grammar as per


chomskey classification.
Example
• S 01S/ε

• Its language can be 0^n 1^n, n>=0


Capabilities of CFG
• Context free grammar is useful to describe most
of the programming languages.

• If the grammar is properly designed then an


efficient parser can be constructed automatically.

• Using the features of associatively & precedence


information, suitable grammars for expressions
can be constructed.

• Context free grammar is capable of describing


nested structures like: balanced parentheses,
matching begin-end, corresponding if-then-else's
& so on.
Applications of CFG
• Context Free Grammar (CFG) is of great
practical importance. It is used for following
purposes-

• For defining programming languages
• For parsing the program by constructing
syntax tree
• For translation of programming languages
• For describing arithmetic expressions
• For construction of compilers
Derivation
• Derivation is a sequence of production rules. It is
used to get the input string through these
production rules.
• During parsing we have to take two decisions.
• These are as follows:

• We have to decide the non-terminal which is to


be replaced.
• We have to decide the production rule by which
the non-terminal will be replaced.
• We have two options to decide which non-
terminal to be replaced with production rule.
Left-most Derivation

• In the left most derivation, the input


is scanned and replaced with the
production rule from left to right.

• So in left most derivatives we read


the input string from left to right.
Example
• Production rules:
•S=S+S
•S=S-S
• S = a | b |c
• Input:
•a-b+c
Cont…
• The left-most derivation is:
•S=S+S
•S=S-S+S
•S=a-S+S
•S=a-b+S
•S=a-b+c
Right-most Derivation

• In the right most derivation, the input


is scanned and replaced with the
production rule from right to left.

• So in right most derivatives we read


the input string from right to left.
Example
• Production rules:
•S=S+S
•S=S-S
• S = a | b |c
• Input:
•a-b+c
• The right-most derivation is:
•S=S-S
•S=S-S+S
•S=S-S+c
•S=S-b+c
•S=a-b+c
Parse Tree
• Parse tree is the graphical representation of
symbol. The symbol can be terminal or non-
terminal.

• In parsing, the string is derived using the start


symbol. The root of the parse tree is that start
symbol.

• It is the graphical representation of symbol


that can be terminals or non-terminals.
Cont…
• Parse tree follows the precedence of
operators.

• The deepest sub-tree traversed first.

• So, the operator in the parent node has


less precedence over the operator in the
sub-tree.
Cont…
The parse tree follows these points:

• All leaf nodes have to be terminals.

• All interior nodes have to be non-


terminals.

• In-order traversal gives original input


string.
Example
• Production rules:
• S= S + S | S * S
• S = a|b|c

• Input:
•a*b+c
Cont…

Step 1 Step 2
Step 3

Step 4
Step 5
POLLING QUESTIONS
1. Which of the following statement is
false?

a) Context free language is the subset of


context sensitive language
b) Regular language is the subset of context
sensitive language
c) Recursively enumerable language is the
super set of regular language
d) Context sensitive language is a
subset of context free language
2. 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
Significance of CFG

• Context free languages strike a balance


between what is easy enough for a computer
to understand and what is expressive enough
for a human to use.

• Mathematical expressions as well as large


chunks of human languages can be modeled
by context free grammars.

• Therefore they are the basis of most


programming languages and human-readable
data formats.
Convert CFL to CFG
• Language given: a^n b^n, where n>=0
• So, in this language no. a always equal
to no. b and always follow a.
• Therefore,
• SaSb/ε can be solution in form of CFG.
Cont..
• Language given: a^n b^n+2, where
n>=0
• So, in this language no. b always +2
then no. a
• Therefore,
• SaSb/bb can be solution in form of
CFG
Cont…
• Language given: a^2n b^n, where
n>=0
• So, in this language no. a twice then no.
b
• Therefore,
• SaaSb/ ε can be solution in form of
CFG
Cont…
• Language given: a^2n+3 b^n, where
n>=0
• So, in this language no. a twice + 3 then
no. b
• Therefore,
• SaaSb/ aaa can be solution in form of
CFG
Ambiguity in CFG
• A context free grammar is called
ambiguous if there exists more than one
Derivation (LMD or more than one RMD)
for a string which is generated by
grammar.
• If the grammar is not ambiguous then it
is called unambiguous.
• Example:
• G: SSa/aS/a
• Lets check for string aaa
Cont…
• For unambiguous there exactly one
derivation a string which is generated
by grammar.
• Example:
• G: SAB
• AaA/b
• BbB/a
• Lets check for string abba
Example
• G: EE+E/id
• Lets check for string id+id+id, weather
it is ambiguous or unambiguous
grammar?
Example

• Problem: Check whether the


grammar G with production rules −
X → X+X | X*X |X| a
is ambiguous or not.
Solution
• Let’s find out the derivation tree for the
string "a+a*a". It has two derivations.
• Derivation 1 −
X → X+X → a +X → a+ X*X → a+a*X →
a+a*a
• Parse Tree 1 −
• Derivation 2 −
X → X*X → X+X*X → a+ X*X → a+a*X →
a+a*a
• Parse Tree 2 −

Since there are two parse trees for a single


string "a+a*a", the grammar G is
ambiguous.
Example

• P: S = aSb | SS |∈
• For the string aabb, the above
grammar generates two parse trees:
Practice Questions
1. Check whether the given grammar is ambiguous
or not-
S → SS| a| b

2. Check whether the given grammar is ambiguous


or not-
S → A / B, A → aAb / ab, B → abB / ∈

3. Check whether the given grammar is ambiguous


or not-
S → AB / C, A → aAb / ab, B → cBd / cd, C → aCd /
aDd, D → bDc / bc
4. Check whether the given grammar is
ambiguous or not-
R → R + R / R . R / R* / a / b

5. Check whether the given grammar is


ambiguous or not-
S → aSbS / bSaS / ∈
CFL Closure Property

• Context-free languages
are closed under −
– Union
– Concatenation
– Kleene Star operation
Context-free languages
are not closed under
•Intersection − If L1 and L2 are context free
languages, then L1 ∩ L2 is not necessarily
context free.

•Intersection with Regular Language − If


L1 is a regular language and L2 is a context
free language, then L1 ∩ L2 is a context free
language.

•Complement − If L1 is a context free


language, then L1’ may not be context free.
CFG Simplification
• In a CFG, it may happen that all the
production rules and symbols are not
needed for the derivation of strings.

• Besides, there may be some null


productions and unit productions.

• Elimination of these productions and


symbols is called simplification of
CFGs.
Cont…
• Simplification essentially comprises of
the following steps −

• Reduction of CFG
– Removal of Unit Productions
– Removal of Null Productions
Remove Unit Production
• SAB
• Aa
SAB
• BC/b Aa
• CD Ba/b
• DE
• Ea
• Rules to remove unit production:
– Left and right side if have single variable then its
known as unit production.
– Apply Dependency graph, if possible.
– Remove unreachable Variable.
Cont…
• SaA/B
• Aba/bb
• BA/bba

• Solution:
• SaA/bba/ba/bb
• Aba/bb
Remove Null Production
• SaS/A
• A ε

• Solution:
• Here A produce null so remove A.
• Also, S produce A but A is null so value
of S will be null. Apply same over
grammar S.
• Therefore SaS/ε/a (Here, ε still
available because, its part of language)
Example
• SABC
• AaA/ε
• BbB/ε
• Cc
• Solution:
– A and B both Produce null. So we replace same
from grammar.
– SABC/BC/AC/C
– AaA/a
– BbB/b
– Cc
Chomskey Normal Form
• CNF stands for Chomsky normal form. A
CFG(context free grammar) is in
CNF(Chomsky normal form) if all
production rules satisfy one of the
following conditions:
– A non-terminal generating two non-
terminals. For example, S → AB.
– A non-terminal generating a terminal. For
example, S → a.
• ABC
• Aa
Cont…
• Convert CFG to CNF
• SaB/bA/R
• Aa/aS/aBA
• Bb/bS/aAAB
• Db/bc
• Step-1: Simplified CFG
• SaB/bA/R
SaB/bA
• Aa/aS/aBA Aa/aS/aBA
• Bb/bS/aAAB Bb/bS/aAAB
• Db/bc
Cont…
• Step-2:

Production Solution
Aa Aa
AaS AC1S, C1a
AaBA AC1C2, C2BA
Bb Bb
BbS BC3S, C3b
BaAAB BC4C5, C4C1A,
C5AB
SaB SC1B
SbA SC3A
Cont…
• Final Answer in form of CNF:
• Aa/C1S/C1C2
• Bb/C3S/C4C5
• SC1B/C3A
• C1a
• C2BA
• C3b
• C4C1A
• C5AB
Problem

1. Convert the following CFG into CNF


S → ASA | aB, A → B | S, B → b | ε

2. Convert the following CFG into CNF


S → a | aA | B,A → aBB | ε,B → Aa | b

3. Convert the following CFG into CNF


S → ASB A → aAS|a|ε B → SbS|A|bb
Greibach Normal Form
• GNF stands for Greibach normal form. A
CFG(context free grammar) is in
GNF(Greibach normal form) if all the
production rules satisfy one of the
following conditions:
– A start symbol generating ε. For example, S
→ ε.
– A non-terminal generating a terminal. For
example, A → a.
– A non-terminal generating a terminal which
is followed by any number of non-terminals.
For example, S → aASB.
Cont…
• GNF must be in below form,
– A a X (Where X ∈ V* , and a ∈ T)
• To make grammar compile friendly, we
use either CNF or GNF.
• Example: SaSb/ab
• Solution: SaSb
Sab
Now Take Bb and replace terminal b
with non-terminal B. So,
SaSB and SaB, Bb
Cont…
• Example:
• SaAb/bB
• Aa/b
• Bb

• Solution:
• SaAB/bB
• Aa/b
• Bb
Problem
1. Convert the following CFG into GNF
S → XY | Xn | p, X → mX | m, Y → Xn |
o

2. Convert the following


∈ CFG into GNF
S → XB | AA,A → a | SA,B → b,X → a

3. Convert the following CFG into GNF


S → CA| BB,B → b | SB,C → b,A → a
Pumping Lemma for CFG
• If L is a context-free language, there is a
pumping length p such that any
string w ∈ L of length ≥ p can be
written as

w = uvxyz, where
vy ≠ ε,
|vxy| ≤ p,
and for all i ≥ 0, uvixyiz ∈ L
Cont.
• Pumping lemma is negative test to
check, that weather language is not
CFL.

Pass
PL Undecided

Fail
Definitely not CFL
Example
• Find out whether the language L =
{xnynzn | n ≥ 1} is context free or not.

• Solution:
• Let assume L is context free.
Then, L must satisfy pumping lemma.
• Pick string from given language L (i.e.
W=x power ^3, Y power^3 and z
power^3) so it will looks like,
• xxxyyyzzz
Cont…
• Now divide given string in five parts (i.e.
u,v,x,y,z), So
• xx x yy y zzz
•u v x y z

Now pump v and y (We can pump by 2), So


• Xx xx yy yy zzz
•u v x y z
Pumped Pumped

• As result string not belongs to L. So given


Language is not CFL
Practice
• Consider the CFG in to the CNF with the
following productions:
• S→Aa∣BC
• A→Bb∣a
• B→Cc∣b
• C→AB∣ab
Cont…
• Consider the CFG in to the GNF with the
following productions:
• S→abB∣baA/cCA
• A→bB∣aA
• B→cC∣ba
• C→aB∣ab
MCQ
• Given grammar G:
(1)S->AS
(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
MCQ
• Given grammar G:
(1)S->AS
(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
Cont…
• Given grammar G:
S->aS| AB
A-> e
B-> e
D-> b
Reduce the grammar, removing all the e
productions and useless production
a) S->aS| AB| A| B, D-> b
b) S->aS| AB| A| B| a, D-> b
c) S->aS| AB| A| B
d) None of the mentioned
Cont…
• Given grammar G:
S->aS| AB
A-> e
B-> e
D-> b
Reduce the grammar, removing all the e
productions and useless production
a) S->aS| AB| A| B, D-> b
b) S->aS| AB| A| B| a, D-> b
c) S->aS| AB| A| B
d) None of the mentioned
Cont…
The Greibach normal form grammar for
the language L = {an bn+1 | n ≥ 0 } is

• a) S → aSB, B →bB I λ
• b) S → aSB, B →bB I b
• c) S → aSB I b, B→b
• d) S → aSB I b
Cont…
The Greibach normal form grammar for
the language L = {an bn+1 | n ≥ 0 } is

• a) S → aSB, B →bB I λ
• b) S → aSB, B →bB I b
• c) S → aSB I b, B→b
• d) S → aSB I b
Cont..
1. In pumping lemma for
context free language
a) We start by assuming the given
language is context free and then we
get contradict
b) We first convert the given language
into regular language and then apply
steps on
c) Both (a) and (b)
d) None of these
Cont..
1. In pumping lemma for
context free language
a) We start by assuming the given
language is context free and then
we get contradict
b) We first convert the given language
into regular language and then apply
steps on
c) Both (a) and (b)
d) None of these
Cont…
The format: A->aB refers to which of the
following?

a) Chomsky Normal Form


b) Greibach Normal Form
c) Backus Normal Form
d) None of the mentioned
Cont…
The format: A->aB refers to which of the
following?

a) Chomsky Normal Form


b) Greibach Normal Form
c) Backus Normal Form
d) None of the mentioned
Description of PDA Model
• Formal Definition of PDA:
• P={Q, Σ, Γ,q0,Z,F, δ}
• A Pushdown Automata (PDA) can be defined as :
• Q is the set of states
• ∑is the set of input symbols
• Γ is the set of pushdown symbols (which can be
pushed and popped from stack)
• q0 is the initial state
• Z is the initial pushdown symbol (which is initially
present in stack)
• F is the set of final states
• δ is a transition function which maps Q x {Σ ∪ ∈} x Γ
into Q x Γ*.
Design PDA
• P={Q, Σ, Γ,q0,Z,F, δ}
• L={O^n 1^2n , n>0}
• Take one string from given Language:
0 0 1 1 1 1 ε
• Start with initial state, at the time Tau in stack
at Z0
q0

Γ Z0

Stack
Design PDA
• P={Q, Σ, Γ,q0,Z,F, δ}
• L={O^n 1^2n , n>0}
• Take one string from given Language:
0 0 1 1 1 1 ε
0,Z0/0Z
0
q0
• We have input 0, so tau at Z0 (i.e. 0,Z0).
• Now in PDA, Machine first POP Z0, then it 0
• will reinsert Zo and 0 in Stack. Z0 Γ
Design PDA
• P={Q, Σ, Γ,q0,Z,F, δ}
• L={O^n 1^2n , n>0}
• Take one string from given Language:
0 0 1 1 1 1 ε
0,Z0/0Z
0
0,0/00
q0
• We have input 0, so tau at 0 (i.e. 0,0).
0
• Now in PDA, Machine first POP 0, then it
• will reinsert 0 and 0 in Stack.
0 Γ
Z0
Design PDA
• P={Q, Σ, Γ,q0,Z,F, δ}
• L={O^n 1^2n , n>0}
• Take one string from given Language:
0 0 1 1 1 1 ε
0,Z0/0Z
0 ,0/00
q0 1,0/0
q1
• We have input 1, so tau at 0 (i.e. 1,0). 0 Γ
• Now in PDA, Machine first POP 0 and reinsert
0
• 0 again, then move towards new state Z0
Design PDA
• P={Q, Σ, Γ,q0,Z,F, δ}
• L={O^n 1^2n , n>0}
• Take one string from given Language:
0 0 1 1 1 1 ε
0,Z0/0Z
0
0,0/00
q0 1,0/0
q1 1,0/ε
q2
• We have input 1, so tau at 0 (i.e. 1,0).
• Now in PDA, Machine first POP 0 and reinsert
0 Γ
• ε, then move towards new state Z0
Design PDA
• P={Q, Σ, Γ,q0,Z,F, δ}
• L={O^n 1^2n , n>0}
• Take one string from given Language:
0 0 1 1 1 1 ε
0,Z0/0Z 1,0/0
0
0,0/00
q0 1,0/0
q1 1,0/ε
q2
• We have input 1, so tao at 0 (i.e. 1,0).
• Now in PDA, Machine first POP 0 and reinsert
0 Γ
• 0 again, then move towards previous state Z0
Design PDA
• P={Q, Σ, Γ,q0,Z,F, δ}
• L={O^n 1^2n , n>0}
• Take one string from given Language:
0 0 1 1 1 1 ε
0,Z0/0Z 1,0/0
0
0,0/00
q0 1,0/0
q1 1,0/ε
q2
• We have input 1, so tau at 0 (i.e. 1,0).
• Now in PDA, Machine first POP 0 and then
Γ
• reinsert ε and move towards next state Z0
Design PDA
• P={Q, Σ, Γ,q0,Z,F, δ}
• L={O^n 1^2n , n>0}
• Take one string from given Language: q3
0 0 1 1 1 1 ε

Z0
/
Z0
0,Z0/0Z 1,0/0

ε,
0
0,0/00
q0 1,0/0
q1 1,0/ε
q2
• We have input ε, so tau at Z0 (i.e. ε,Z0).
• Now in PDA, Machine first POP Z0 and then
• move towards final state Z0 Γ
Design PDA
• P={Q, Σ, Γ,q0,Z,F, δ}
• L={O^n 1^2n , n>0}
• Take one string from given Language: q3
0 0 1 1 1 1

Z0
/
Z0
0,Z0/0Z 1,0/0

ε,
0
0,0/00
q0 1,0/0
q1 1,0/ε
q2
• We have not input, and tau at ε (i.e. Stack
• empty) So process done.
Γ
DPDA and NPDA
• We can create NPDA for all CFL, but
cant create DPDA for all CFL.
• As we know, PDA is nothing but Finite
automata + Stack.

• DPDA: QxεxΓ QΓ*


• NPDA: QxεxΓ 2^QΓ*

• NPDA is powerful then DPDA


Cont…
• DPDA: For every input with the current
state, there is only one move.

• For every input with the current state,


We can have multiple moves.
LL(k) and LR(K)
Grammars
Top-down and Bottom-
• The termup Parsers
"LL(k) grammar" refers to a class of context-free
grammars in formal language theory.
• In the context of automata theory, LL(k) grammars are a subset
of context-free grammars that can be parsed by a certain type
of parsing algorithm called LL(k) parsing.
• L: Stands for Left-to-right scanning of the input.
• L: Stands for Leftmost derivation. This means that when
constructing a parse tree, the leftmost non-terminal symbol is
always the one expanded first.
• (k): The 'k' represents the number of look ahead symbols the
parser uses to make parsing decisions. In LL(k) parsing, the
parser looks at 'k' symbols of the input to decide which
production to use.
Cont…
• LR(k) grammars are a class of context-free
grammars that are more powerful than LL(k)
grammars. LR(k) parsers are capable of parsing a
larger set of grammars, including many programming
languages. In LR(k) parsing, 'L' stands for scanning
the input from left to right, 'R' stands for constructing
a rightmost derivation in reverse (hence, "LR"), and
'k' represents the number of lookahead symbols used
for making parsing decisions.
• An LR(k) grammar allows an LR(k) parser to decide
which production to apply based on the current input
symbol and k lookahead symbols. These parsers can
handle a broader range of grammars than LL(k)
parsers.
Cont…
• In LLK and LRK, first L known as left to
right reading and remaining L and R
known as below,
• LMD and RMD
• SaAbBe
• Then If we picking A variable
(nonterminal), then it will known as LMD.
• If we picking B Variable then it will
known as RMD.
• LMD follow Top-Down and RMD follow
Bottom up
Properties of LL(k) Grammars
• Predictive Parsing: LL(k) grammars can be parsed using a top-down,
left-to-right parsing strategy with a lookahead of k symbols. This means
that you can predict the production to apply based on the current non-
terminal and the next k input symbols.
• Leftmost Derivation: LL(k) grammars are parsed using leftmost
derivation, where at each step, the leftmost non-terminal in the current
production is expanded. This property simplifies parsing and leads to
efficient LL(k) parsers.
• No Backtracking: LL(k) parsers do not require backtracking. Once a
production is chosen, there is no need to undo or backtrack the parsing
process. The parsing decision is made deterministically based on the
current symbol being parsed and the lookahead symbols.
• LL(1) Grammars: A subset of LL(k) grammars is LL(1) grammars,
where the parsing decision is based on a single lookahead symbol
(k=1). LL(1) grammars are particularly useful because of their
simplicity, and many programming languages can be described by LL(1)
grammars.
• Parsing Table: LL(k) grammars can be represented by a parsing table.
This table guides the parsing process by indicating which production to
use for a given non-terminal and lookahead symbol. If there are no
conflicts in the table, the grammar is LL(k).
Properties of LR(k) Grammars
• Property 1 : Every LR(k) grammar G is unambiguous.
There exists a unique right-most derivation. Any pushdown
automaton accepts a context- free language and for any
context-free language L, we can construct a pushdown
automaton accepting L.
• Property 2 If G is an LR(k) grammar. there exists a
deterministic pushdown automaton A accepting L(G).
• Property 3 If A is a deterministic pushdown automaton A, there
exists an LR(l) grammar G such that L(G) =N(A).
• Property 4 If G is an LR(k) grammar, then there exists LR(K’)
such that K’>K
• Property 5 The class of deterministic languages is a proper
subclass of the class of context-free languages.
• Property 6 LR(k) is closed under complementation but not
under union and intersection.

You might also like