0% found this document useful (0 votes)
29 views45 pages

Unit 1 TAFL

Uploaded by

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

Unit 1 TAFL

Uploaded by

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

Theory of Automata & Formal Languages

Unit: 1

TAFL

Course Details
(B Tech 4th Sem)

TAFL KCS - 402 Unit Number: 1


1
6/12/2023
Content

• Introduction
• Theory of computation
• Basic Definitions
• Deterministic Finite Automata
• DFA Examples
• Non Deterministic Finite Automata
• NDFA Example
• Equivalence of DFA and NDFA
• Minimization of NDFA
• Machines with Output

TAFL KCS - 402 Unit


6/12/2023 2
Number: 1
Unit Objective

• To understand the designing of Deterministic Finite Automata.


• To understand the designing of Non deterministic finite automata.
• To understand the Minimization of Finite Automata.
• To understand the designing the Finite automata with output.

TAFL KCS - 402 Unit Number: 1


6/12/2023 3
Prerequisite and Recap

• Brief review of different operations like Union, Intersection,


difference, Complement, Introduction of graph & concept of
equivalence relation & equivalence class

TAFL KCS - 402 Unit Number: 1


6/12/2023 4
Unit I Syllabus

Basic Concepts and Automata Theory: Introduction to Theory of


Computation- Automata, Computability and Complexity, Alphabet,
Symbol, String, Formal Languages, Deterministic Finite Automaton
(DFA)- Definition, Representation, Acceptability of a String and
Language, Non Deterministic Finite Automaton (NFA), Equivalence of
DFA and NFA, NFA with ε-Transition, Equivalence of NFA’s with and
without ε-Transition, Finite Automata with output- Moore Machine,
Mealy Machine, Equivalence of Moore and Mealy Machine,
Minimization of Finite Automata, Myhill-Nerode Theorem, Simulation
of DFA and NFA

TAFL KCS - 402 Unit Number: 1


6/12/2023 5
Theory of Computation (CO1)

Objective: To understand the basic definition of Automata

• It is a branch of computer science that deals with how effectively a


problem can be solved on a model of computation by using an
algorithm.

Theory of
Computation

Theory of
Computability Complexity
Automata and
Theory Theory
Formal Languages

TAFL KCS - 402 Unit Number: 1


6/12/2023 6
Theory of Computation (CO1)
Objective: To understand the basic definition of Automata

Theory of Automata and Formal Languages :


• It deals with the definition and properties of various mathematical models
of computer.
• Example : Finite Automat, Context Free Grammar, PDA, Turing Machine

Computability Theory:
• It deals with what can and what cannot be computed by model.

Complexity Theory:
• It deals with computable problems based on their hardness.

Purpose of TOC:
• In order to develop formal mathematical model of computations that
reflect real world computers.

TAFL KCS - 402 Unit Number: 1


6/12/2023 7
Basic Definitions:

Symbol:
It is a character.
For Example : a,b,c,…….z
0,1,2,3,4…9
+,-,%,&........ Special characters.

Alphabet:
An alphabet is defined as a finite non empty set of symbols. It is representd
by symbol : Σ
Example: Σ: {0,1} set of binary alphabets.
Σ: {a,b,c,……z- set of all lower case letters.
Σ: {+,-,*,/,……- set of all special characters.

TAFL KCS - 402 Unit Number: 1


6/12/2023 8
Basic Definitions…

String

Definition − A string is a finite sequence of symbols taken from ∑.

Example − ‘cabcad’ is a valid string on the alphabet set ∑ = ,a, b, c, d-

Length of a String

Definition − It is the number of symbols present in a string. (Denoted by |S|).


• Examples −
– If S = ‘cabcad’, |S|= 6
– If |S|= 0, it is called an empty string (Denoted by λ or ε)

TAFL KCS - 402 Unit Number: 1


6/12/2023 9
Basic Definitions…

Kleene Star
• Definition − The Kleene star, ∑*, is a unary operator on a set of symbols
or strings, ∑, that gives the infinite set of all possible strings of all possible
lengths over ∑ including λ.
• Representation − ∑* = ∑0 ∪ ∑1 ∪ ∑2 ∪……. where ∑p is the set of all
possible strings of length p.
• Example − If ∑ = ,a, b-, ∑* = ,λ, a, b, aa, ab, ba, bb,………..-

Kleene Closure / Plus


• Definition − The set ∑+ is the infinite set of all possible strings of all
possible lengths over ∑ excluding λ.
• Representation − ∑+ = ∑1 ∪ ∑2 ∪ ∑3 ∪…….
• ∑+ = ∑* − , λ -
• Example − If ∑ = , a, b - , ∑+ = { a, b, aa, ab, ba, bb,………..-

TAFL KCS - 402 Unit Number: 1


6/12/2023 10
Basic Definitions (Continued)

Language

• Definition − A language is a subset of ∑* for some alphabet ∑. It can be


finite or infinite.
• Example − If the language takes all possible strings of length 2 over ∑ = ,a,
b}, then L = { ab, aa, ba, bb }

TAFL KCS - 402 Unit Number: 1


6/12/2023 11
Automata

An automaton with a finite number of states is called a Finite


Automaton (FA) or Finite State Machine (FSM).

Formal definition of a Finite Automaton

An automaton can be represented by a 5-tuple (Q, ∑, δ, q0, F), where −


• Q is a finite set of states.
• ∑ is a finite set of symbols, called the alphabet of the automaton.
• δ is the transition function.
• q0 is the initial state from where any input is processed (q0 ∈ Q).
• F is a set of final state/states of Q (F ⊆ Q).

TAFL KCS - 402 Unit Number: 1


6/12/2023 12
Deterministic Finite Automaton (DFA)

Recap: In previous slides we have learned about basic definitions used


in Automata.

Prerequisite: Knowledge about Alphabet, string and language.

Objective: To understand the formal mathematical definition of DFA

TAFL KCS - 402 Unit Number: 1


6/12/2023 13
Deterministic Finite Automaton (DFA)

Objective: To understand the formal mathematical definition of DFA

Formal Definition of a DFA

• A DFA can be represented by a 5-tuple (Q, ∑, δ, q0, F) where −


• Q is a finite set of states.
• ∑ is a finite set of symbols called the alphabet.
• δ is the transition function where δ: Q × ∑ → Q
• q0 is the initial state from where any input is processed (q0 ∈ Q).
• F is a set of final state/states of Q (F ⊆ Q).

TAFL KCS - 402 Unit Number: 1


6/12/2023 14
Graphical Representation of a DFA (CO1)

A DFA is represented by digraphs called state diagram.

•The vertices represent the states.


•The arcs labeled with an input alphabet show the transitions.
•The initial state is denoted by an empty single incoming arc.
•The final state is indicated by double circles.

Example
Let a deterministic finite automaton be →
•Q = {a, b, c},
•∑ = ,0, 1-,
•q0 = {a},
•F = {c},

TAFL KCS - 402 Unit Number: 1


6/12/2023 15
Graphical Representation of a DFA

Its graphical representation would be as follows −

TAFL KCS - 402 Unit Number: 1


6/12/2023 16
DFA - Examples

1. Design a DFA that accepts “a”, over an alphabet ∑={a}

a
q0 q1

TAFL KCS - 402 Unit Number: 1


6/12/2023 17
DFA - Examples

2. Design a DFA that accepts 0 or more ‘a’

q0

TAFL KCS - 402 Unit Number: 1


6/12/2023 18
DFA - Examples

3. Design a DFA over an alphabet ∑={a}, which accepts those strings


which starts with 1 and ends with 0.

1 0

1 0
q0 q1 q2

TAFL KCS - 402 Unit Number: 1


6/12/2023 19
DFA - Examples

4. Draw a DFA for following language over an alphabet {a,b}, L={all


strings starting with abb}

a,b

a b b
q0 q1 q2 q3

TAFL KCS - 402 Unit Number: 1


6/12/2023 20
DFA - Examples

5. Draw a DFA for following language over an alphabet {a,b}, L={all


strings with abb as substring}

b a
a,b

a b b
q0 q1 q2 q3

TAFL KCS - 402 Unit Number: 1


6/12/2023 21
DFA - Examples

6. Draw a DFA for following language over an alphabet {a,b}, L={all


strings ending with abb}

b a
a a,b

a b b
q0 q1 q2 q3

TAFL KCS - 402 Unit Number: 1


6/12/2023 22
DFA - Examples

7. Design a DFA over an alphabet {a,b} such that every string


accepted must be of length:
• |w|=2(mod3)

R=0
a,b
q0 q1 R=1

a,b a,b

q2 R=2

TAFL KCS - 402 Unit Number: 1


6/12/2023 23
Non – Deterministic Finite Automata (CO1)

Recap: Learn the designing of DFA

Prerequisite: Understanding of DFA

Objective: To understand the mathematical definition of NDFA

TAFL KCS - 402 Unit Number: 1


6/12/2023 24
Non – Deterministic Finite Automata (CO1)

Objective: To understand the mathematical definition of NDFA

Formal Definition of an NDFA

• An NDFA can be represented by a 5-tuple (Q, ∑, δ, q0, F) where −


• Q is a finite set of states.
• ∑ is a finite set of symbols called the alphabets.
• δ is the transition function where δ: Q × ∑ → 2Q
(Here the power set of Q (2Q) has been taken because in case of
NDFA, from a state, transition can occur to any combination of Q
states)
• q0 is the initial state from where any input is processed (q0 ∈ Q).
• F is a set of final state/states of Q (F ⊆ Q).

TAFL KCS - 402 Unit Number: 1


6/12/2023 25
Non – Deterministic Finite Automata

• An NDFA is represented by digraphs called state diagram.


• The vertices represent the states.
• The arcs labeled with an input alphabet show the transitions.
• The initial state is denoted by an empty single incoming arc.
• The final state is indicated by double circles.

TAFL KCS - 402 Unit Number: 1


6/12/2023 26
NDFA – EXAMPLE

1. Draw a NDFA to accept strings containing the substring 0101

0,1 0,1
0 1 0 1
q0 q1 q2 q3 q4

TAFL KCS - 402 Unit Number: 1


6/12/2023 27
THE EQUIVALENCE OF DFA AND NDFA

• Construct a DFA equivalent of following NDFA:


δ/Σ a b
→q0 q0,q1 q0
q1 q2 q1
q2 q3 q3
*q3 q2

δ/Σ a b
*→q0+ [q0,q1] [q0]
[q0,q1] [q0,q1,q2] [q0,q1]
[q0,q1,q2] *[q0,q1,q2,q3] *[q0,q1,q3]
*[q0,q1,q3] [q0,q1,q2] [q0,q1,q2]
*[q0,q1,q2,q3] *[q0,q1,q2,q3] *[q0,q1,q2,q3]

TAFL KCS - 402 Unit Number: 1


6/12/2023 28
MINIMIZATION OF DFA (CO1)

Minimize the given DFA-

TAFL KCS - 402 Unit Number: 1


6/12/2023 29
MINIMIZATION OF DFA
Solution-
Step-01:
The given DFA contains no dead states and inaccessible states.

Step-02:
Draw a state transition table-

a b
→q0 q1 q2
q1 q1 q3
q2 q1 q2
q3 q1 *q4
*q4 q1 q2

TAFL KCS - 402 Unit Number: 1


6/12/2023 30
MINIMIZATION OF DFA

Step-03:

Now using Equivalence Theorem, we have-


• P0 = { q0 , q1 , q2 , q3 } { q4 }
• P1 = { q0 , q1 , q2 } { q3 } { q4 }
• P2 = { q0 , q2 } { q1 } { q3 } { q4 }
• P3 = { q0 , q2 } { q1 } { q3 } { q4 }

• Since P3 = P2, so we stop.


• From P3, we infer that states q0 and q2 are equivalent and can be merged
together.
• So, Our minimal DFA is

TAFL KCS - 402 Unit Number: 1


6/12/2023 31
MINIMIZATION OF DFA (CO1)

So after minimization the final


DFA will be Like:

Initial DFA

Final DFA

TAFL KCS - 402 Unit Number: 1


6/12/2023 32
Finite Automata with Outputs (CO1)

Recap: Learn about DFA, NDFA and their designing, and


minimization and interconversions.

Prerequisite: Knowledge about DFA, NDFA .

Objective: To understand the Finite Automata Machines which


gives output.

TAFL KCS - 402 Unit Number: 1


6/12/2023 33
Finite Automata with Outputs (CO1)
Moore Machine Mealy Machine
• It is consists of 6 Touples • It is consists of 6 Touples
• Q-Finite set of states • Q-Finite set of states
• Σ-i/p alphabet • Σ-i/p alphabet
• δ-Transition Function • δ-Transition Function
(λ : Q×Σ→Q) (λ :Q×Σ→ ∆)
• q0-initial state • q0-initial state
• ∆-o/p alphabet • ∆-o/p alphabet
• λ-o/p function • λ -o/p function

TAFL KCS - 402 Unit


6/12/2023 34
Number: 1
Moore machine

• Construct a Moore machine that takes set of all strings over


alphabet {a,b} as i/p and prints 1 as o/p for every string ending
with ‘baa’ as substring.

TAFL KCS - 402 Unit Number: 1


6/12/2023 35
Mealy Machine

• Construct a Mealy machine for 1’s compliment

TAFL KCS - 402 Unit Number: 1


6/12/2023 36
Moore to Mealy conversion

Given Moore Machine Mealy Machine after conversion

Link: https://www.youtube.com/watch?v=RBDE-vO7Ux0

TAFL KCS - 402 Unit Number: 1


6/12/2023 37
Mealy to Moore Conversion
Given Mealy
Machine

Moore Machine after


Given Mealy Moore Machine after Conversion
Machine Conversion

Link: https://www.youtube.com/watch?v=vcNRb2cj1GI

TAFL KCS - 402 Unit Number: 1


6/12/2023 38
Daily Quiz

1. Draw a DFA for the following language over {0,1}:


a. All strings with even number of 0 and even number of 1.
b. All string of length at most 5.
2. Prove that NDFA = DFA
3. Give DFA accepting the following language over alphabet {0,1}
a. The set of all strings ending in 00
b. The ste of strings with 011 as sub string.
c. The set of string starting with 10.
4. What do you understand by Epsilon closure in FA?
5. State and prove Myhill Nerode Theorem.
6. Construct a DFA for the language that contains the strings ending
with 0.

6/12/2023 TAFL KCS - 402 Unit Number: 1 39


MCQ s

• The non- Kleene Star operation accepts the following string of finite length
over set A = {a,b} | where string s contains even number of 0 and 1
A. ab,aabb,ababab
B. aabb,bbaabbaa
C. ε,aabb,bbaabbaa
D. ε,aabb,bbaabbaa

• A regular language over an alphabet ∑ is one that cannot be obtained from


the basic languages using the operation

A. Union
B. Concatenation
C. Kleene*
D. All of the mentioned

6/12/2023 TAFL KCS - 402 Unit Number: 1 40


MCQ s

• Which of the following is a not a part of 5-tuple finite automata?

a. Input alphabet
b. Transition function
c. Initial State
d. Output Alphabet

• Moore Machine is an application of:

a. Finite automata without input


b. Finite automata with output
c. Non- Finite automata with output
d. None of the mentioned

6/12/2023 TAFL KCS - 402 Unit Number: 1 41


Expected Questions for University Exam

1. Design a DFA over an alphabet {0,1}, which accepts those strings


which starts with 1 and ends with 0.
2. Design a DFA over an alphabet {0,1}, which accepts those stings
which contain odd number of 1’s.
3. Design a DFA over an alphabet {0,1}, which accepts those stings of
length at most 5.
4. Design a DFA for a language of strings for an alphabet {0,1}, which
accepts a string ending with 10.
5. Design a DFA for the language containing strings in which left most
symbol differ from right most symbol over an alphabet {0,1}.

6/12/2023 TAFL KCS - 402 Unit Number: 1 42


Summary

• The knowledge of regular languages and finite automata is essential


for designing a compiler.

• Deterministic Finite Automata are machine model which recognize


strings of a regular language.

• All type of Finite Automata (DFA, NDFA ) are equal in power and
convert one type of automata to other.

6/12/2023 TAFL KCS - 402 Unit Number: 1 43


References

1. Aho, Hopcroft and Ullman, The Design and Analysis of Computer


Algorithms, Addison Wesley.
2. Aho, Sethi, Ullman, Compilers Principles, Techniques and Tools,
Pearson Education, 2003.
3. Hopcroft and Ullman, Introduction to Automata Theory, Languages
and Computation, Addison Wesley.
4. Kohavi, ZVI, Switching And Finite Automata Theory, Tata McGraw-
Hill, 2006.
5. Lewis and Papadimitriou, Elements of the Theory of Computation,
Prentice-Hall.
6. Martin, Introduction to Languages and the Theory of Computation,
McGraw-Hill, 2nd edition,1996.
7. Mishra, KLP, Chandrasekaran, N. Theory of Computer Science,
(Automata, Languages and Computation) PHI, 2002.

6/12/2023 TAFL KCS - 402 Unit Number: 1 44


6/12/2023 TAFL KCS - 402 Unit Number: 1 45

You might also like