0% found this document useful (0 votes)
22 views21 pages

ATCD UT1 Material - 220816 - 203517

Uploaded by

rodsingle948
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)
22 views21 pages

ATCD UT1 Material - 220816 - 203517

Uploaded by

rodsingle948
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/ 21

Unit – I: Introduction to theory of computation

The central concepts of Automata Theory: Alphabet, Strings, Language Definitions with
examples, Operations on Languages, Language Recognizers, Finite Automaton Model.
Deterministic and Non Deterministic Finite Automata: Deterministic finite automaton,
Transition Tables and Diagrams, Types of States, Non-deterministic finite automaton.

1.0 The central concepts of Automata Theory:

1.0.1 Symbol: Symbol is a character.

Eg: a, b, c……..z

0, 1, 2……….9

+, -, % ….special characters

1.0.2 Alphabet: An alphabet is a finite, non-empty set of symbol. It is denoted by sigma (Σ).

Eg: Σ = {0, 1} set of binary alphabets.

Σ = {a, b ….z} set of all lowercase letters

Σ = {+, &, %,…………} set of all special characters.

1.0.3 String: A string is finite sequence of symbols chosen from alphabet and denoted by
symbol w.

Example:

 011100110 is a string from binary alphabet Σ = {0, 1}


 If Σ = {a, b} then various strings that can be formed from Σ are {ab, aa, aaa, bb, bbb…..}.

1. Empty String: The empty string is the string with zero occurrences of symbol. It is denoted
by “ε”.

Example:

 w =ε then the length of w is given by |w|=0

2. Length of string: It is the number of symbols in the string and it is denoted by |ω|.

Example:

 ω = 010110101 from binary alphabet Σ = {0, 1}. Length |ω| =9.

3. Prefix: The prefix of any string is any number of leading symbols of string.

 Example: Let w = abc - Prefix of w are ε, a, ab, abc.

1
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
4. Suffix: Suffix of any string is any number of trailing symbol of string.

Example:

 Let w = abc - Suffix of w are ε, c, bc, abc.

5. Substring: Any sequence of symbol over the given string.

Example:

 w=abc - The substring of w are ε, a, b, c, bc, ab, abc.

6. Concatenation of String: if w and x are two strings then the concatenation of two strings is
denoted by wx.

Example:

 w=1110 and x=0101


 Then xy=11100101

1.0.4 Power of an alphabet:

If “Σ” is an alphabet, set of all strings of certain length from that alphabet by using exponential
notation. It is denoted by Σk is the set of strings of length k.

Eg: Σ = {0, 1} has 2 symbols.

a) Σ1 = {0,1} – 21 = 2 i.e., k=2


b) Σ2 = {00, 01, 10, 11} – 22 i.e., k =4
c) Σ3 = {000, 001, 010, 011, 100, 101, 110, 111} – 23 = 8

1.0.5 Kleen Closure: The set of strings over an alphabet Σ is usually denoted by Σ * = kleen
closure.

Representation: Kleen closure (Σ* = Σ0 υ Σ1 υ Σ2 υ Σ3…………) with epsilon symbol.

Example: Σ* = {0, 1}*

= {ε, 0, 1, 00, 01, 10, 11……………….}

1.0.6 Kleen plus: The set of all strings over an alphabet Σ excluding ε is usually denoted by ε + =
kleen plus.

Representation: Kleen plus or positive closure (Σ+ = Σ1 υ Σ2 υ Σ3………………….) without


epsilon symbol (or) (Σ+ = Σ* - {ε})

Example: Σ+ = {0,1}+ = {0, 1, 00, 01, 10, 11……………….}

2
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
1.1 Language:

Language is a collection of strings (or) Finite set of non-empty strings.

If Σ is an alphabet, and L is superset of Σ *, then L is a language.

Note that language is formed by appropriate strings and strings are formed by alphabets.

Examples:

1. Σ = {ε, 0, 00, 000…}

The language is defined as ‘any number of zeros’.

2. Σ = {0, 1}

L = {x | x is in Σ* and x contains an even number of 0‟s}

3. Σ = {0, 1, 2… 9}

4. The set of legal English words

5. The set of legal C programs

6. The set of string consisting of n 0’s followed by n 1’s {ε, 01, 0011, 000111……….}

Operations on Languages:

1. Union: If L1 and L2 are two languages then, Union of two languages is denoted as L1 υ L2. i.e.,
L1 υ L2 = {x, y | x ϵ L1 and y ϵ L2}.

Example:

Let L1 = {00, 01} and L2 = {00, 110, 11}

L1 υ L2 = {00, 01, 110, 11}

2. Concatenation: If L1 and L2 are two languages then, Concatenation of two languages is


denoted by L1.L2 i.e., L1.L2 = {x.y | x ϵ L1 and y ϵ L2}.

Example:

Let L1 = {00, 01} and L2 = {00, 110, 11}

L1.L2 = {0000, 00110, 0011, 0100, 01110, 0111}

3. Closure: Let L be the language, then L* = ⋃∞


𝑖=0 𝐿
𝑖

Example:

3
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
L = {ab} then,

L1 = {ab}

L2 = L1.L1 = {abab}

L3 = L1.L1.L1 = {ababab}

L4 = L1.L1.L1.L1 = {abababab}

L* = ⋃∞ 𝒊
𝒊=𝟎 𝑳 = L υ L υ L υ L …………L
0 1 2 3

L* = {ε, ab, abab, ababab………………}

4. Positive Closure of a language: Let L be the language, then L+ = ⋃∞


𝒊=𝟏 𝑳
𝒊


Example: L+ = ⋃∞ 𝒊
𝒊=𝟏 𝑳 = L υ L υ L …………L
1 2 3

L+ = {ab, abab, ababab, abababab………………}

1.2 Language Recognizers:

Chomsky Hierarchy represents the class of languages that are accepted by the different
machines. According to Chomsky hierarchy, grammar is divided into 4 types as follows:

1. Type 0 is known as unrestricted grammar.


2. Type 1 is known as context-sensitive grammar.
3. Type 2 is known as a context-free grammar.
4. Type 3 Regular Grammar.

Figure: Chomsky Hierarchy

4
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
This is a hierarchy. Therefore every language of type 3 is also of type 2, 1 and 0. Similarly, every
language of type 2 is also of type 1 and type 0, etc.

1. Type 0 Grammar:

Type 0 grammar is known as Unrestricted grammar. There is no restriction on the grammar rules
of these types of languages. These languages are also known as the Recursively Enumerable
languages. These languages can be efficiently modeled by Turing machines.

These are of the form: α → β, where α, β ϵ (V υ T)*

Example:

bAa → aa

S→s

2. Type 1 Grammar:

Type 1 grammar is known as Context Sensitive Grammar. The context sensitive grammar is used
to represent context sensitive language. The language generated by the grammar is recognized by
the Linear Bound Automata. The context sensitive grammar follows the following rules:

 The context sensitive grammar may have more than one symbol on the left hand side of
their production rules.
 The number of symbols on the left-hand side must not exceed the number of symbols on
the right-hand side.
 The rule of the form A → ε is not allowed unless A is a start symbol. It does not occur on
the right-hand side of any rule.
 The Type 1 grammar should be Type 0. In type 1, Production is in the form of α → β,
where |α| ≤ |β|.

Example:

S → AT

T → xy

A→a

3. Type 2 Grammar:

Type 2 Grammar is known as Context Free Grammar. Type2 grammars generate context free
languages. The language generated by the grammar is recognized by pushdown automata. Type
2 should be type 1. The production rule is of the form: α → β, where |α| ≤ |β|, αϵV, |α| = 1.

5
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
Example:

A → aBb

A→b

B→a

4. Type 3 Grammar:

Type 3 Grammar is known as Regular Grammar. Regular languages are those languages which
can be described using regular expressions. These languages can be modeled by NFA or DFA.

Type 3 is most restricted form of grammar. The Type 3 grammar should be Type 2 and Type 1.
Type 3 should be in the form of α → β.

Example:

S → a | bA (Right linear grammar)

S → a | Ab (Left linear grammar)

1.2 Finite Automata:

Finite Automata is an abstract computing device. It is mathematical model of a system with


discrete inputs, outputs, states and set of transitions from state to state that occurs on input
symbols from alphabet Σ.

Its representations are:

1. Transitions (Transition diagrams or transition table)


2. Tabular (Transition table)
3. Mathematical (Transition function or mapping function)

1.2.1 Formal Definition of Finite Automata:

A finite automata is a collection of 5-tuples; they are

M = (Q, Σ, δ, q0, F)

Where

Q: is a Finite set of states

Σ: is a finite set called the alphabets

δ: (Q x Σ)–>Q is the transition function

6
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
q0: The initial/starting state, q0 is in Q

F: A set of final/accepting states, which is a subset of Q

1. Transition Diagrams:

It is a directed graph associated with the vertices of the graph corresponds to the state of the
finite automata.

Example: we have 3 states Q0, Q1 and Q2 along with 2 inputs a and b as shown below. Q0 is
the initial state and Q1 is the final state. Which is accepting any string starting with a.

Figure: Transition Diagram

2. Transition Table:

 It is basically a tabular representation, of the transition function that takes two arguments
(a state and a symbol) and returns a value (the next state).
 Rows corresponds to states
 Column corresponds to input symbols
 Entries corresponds to next states
 The start state is marked with an arrow (→)
 The accept state is marked with a star (*)

3. Example of Transition function:

A = ({q0, q1, q2}, {0, 1}, δ, q0, {q1})

Where the transition function δ is given by the table


7
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
Transition Diagram

1.2.2 Applications of Automata:

1. It plays an important role in the compiler design.


2. In switching theory and design and analysis of digital circuits automata theory is applied.
3. Design & analysis of complex software and hardware systems.
4. To prove the correctness of the program automata theory is used.
5. To design finite state machines such as Moore and mealy machines.
6. It is base for the formal languages and these formal languages are useful of the
programming languages.

1.3 Finite Automata Model:

Finite automata can be represented by input tape and finite control.

Input tape: It is a linear tape having some number of cells. Each input symbol is placed in each
cell.

Finite control: The finite control decides the next state on receiving particular input from input
tape. The tape reader reads the cells one by one from left to right, and at a time only one input
symbol is read.

Figure: Finite Automata Model

8
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
1.4 Types of Finite Automata:

1.4.1 DFA (Deterministic finite automata):

 DFA refers to deterministic finite automata. The finite automata are called deterministic
finite automata if the machine is read an input string one symbol at a time.
 In DFA, there is only one path for specific input from the current state to the next
state.
 DFA does not accept the null move, i.e., the DFA cannot change state without any input
character.
 DFA can contain multiple final states. It is used in Lexical Analysis in Compiler.

Example: In the following diagram, we can see that from state 0 for input 0, there is only one
path which is going to 1. Similarly, from 0, there is only one path for input 1 going to 0.

Figure: DFA with Σ = {0, 1}

One important thing to note is, there can be many possible DFAs for a pattern. A DFA with a
minimum number of states is generally preferred.

Formal Definition of DFA:

A DFA is a collection of 5-tuples same as of FA.

9
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
Q: finite set of states

∑: finite set of the input symbol

q0: initial state

F: final state

δ: Transition function

Transition function can be defined as:

δ: Q x ∑→Q

Graphical Representation of DFA

A DFA can be represented by digraphs called state diagram. In which:

1. The state is represented by vertices.


2. The arc labeled with an input character show the transitions.
3. The initial state is marked with an arrow.
4. The final state is denoted by a double circle.

Example 1:

Q = {q0, q1, q2}

∑ = {0, 1}

q0 = {q0}

F = {q2}

Solution:

Transition Diagram -

Transition Table:

Present State Next state for Input 0 Next state for Input 1
→q0 q0 q1
q1 q2 q1
*q2 q2 q2

10
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
Example 2:

DFA with ∑ = {0, 1} accepts all starting with 0.

Solution:

Example 3:

DFA with ∑ = {0, 1} accepts all ending with 0.

Solution:

Example 4:

Design a FA with ∑ = {0, 1} accepts those string which starts with 1 and ends with 0.

Solution:

The FA will have a start state q0 from which only the edge with input 1 will go to the next state.

Example 5:

Design a FA with ∑ = {0, 1} accepts the only input 101.

Solution:

11
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
Example 6:

Design FA with ∑ = {0, 1} accepts even number of 0's and even number of 1's.

Solution:

This FA will consider four different stages for input 0 and input 1. The stages could be:

Step -1:

Make initial state “q0” then it is that possibility that there would not be any “1” or “0” as, empty
string contain even number of 0’s and even number of 1’s.

Step -2:

Create transition of input alphabet ‘1’ from state “q0” to state “q1” and input alphabet ‘0’ from
state “q0” to state “q2”.

Step -3:

After number of ‘1’ at “q1” are odd 1’s. So, send input alphabet ‘1’ from state “q1” to state “q0“
and input alphabet ‘0’ from state “q1” to state “q3“.

Step -4:

After step 3 we have got an even number of 1’s at “q0” and an odd number of 0’s and 1’s “q1,
q2, q3”. Now send input alphabet ‘0’ from state “q2” to state “q0“ and input alphabet ‘1’ from
state “q2” to state “q3“.

Step -5:

At this step, we complete the over the machine with “q3“ so that after the transition the machine
will accept the string the number of ‘1’ and ‘0’ are even. As last even number of ‘1’ and ‘0’
reach to “q0” so make the state “q0” be the final state.

12
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
Transition table of above DFA:

In above table -> represents initial state and * represents final state.

Example 7:

Design FA with ∑ = {0, 1} accepts the set of all strings with three consecutive 0's.

Solution:

The strings that will be generated for this particular languages are 000, 0001, 1000, 10001, .... in
which 0 always appears in a clump of 3. The transition graph is as follows:

Example 8:

Design a DFA L(M) = {w | w ε {0, 1}*} and W is a string that does not contain consecutive 1's.

Solution:

When three consecutive 1's occur the DFA will be:

Here two consecutive 1's or single 1 is acceptable, hence

13
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
The stages q0, q1, q2 are the final states. The DFA will generate the strings that do not contain
consecutive 1's like 10, 110, 101..... etc.

Example 9:

Design a FA with ∑ = {0, 1} accepts the strings with an even number of 0's followed by single 1.

Solution:

The DFA can be shown by a transition diagram as:

Example 10:

Design a DFA accepting the set of all strings such that the number of 0’s is a multiple of 3 over
the alphabet {0, 1}.

Solution: Designing DFA step by step:

Step-1:

Make initial state “A” then it is the possibility that there would not be any ‘0’ but have only ‘1’
in the string which is acceptable because 0 is divisible by 3.So, in this case, nay number of 1’s
can be present here and for this put self-loop of ‘1’ on initial state “A”.

Step-2:

Create transition of input alphabet ‘0’ from state “A” to state “B”.

14
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
Step-3:

After one ‘0’ any number of 1’s can be present i.e, no ‘1’ or more than one ‘1’.For this put self-
loop of ‘1’ on state “B”.

Step-4:

Now create transition of input alphabet ‘0’ from state “B” to state “C” and after two 0’s any
number of 1’s can be found in the string and for this put self-loop of ‘1’ on initial state “C”.

Step-5:

Before transition of third ‘0’ we need to think about the logic so that after this transition the
machine will accept string that have number of zeros divisible by 3.For this transit ‘o’ from state
“C” to state “A”.AS third zero is reaching to state “A” so make state “A” be final state.

Transition Table:

15
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
1.4.2 NFA (Non-Deterministic finite automata):

 NFA stands for non-deterministic finite automata. It is easy to construct an NFA than
DFA for a given regular language.
 The finite automata are called NFA when there exist many paths for specific input
from the current state to the next state.
 Every NFA is not DFA, but each NFA can be translated into DFA.
 NFA is defined in the same way as DFA but with the following two exceptions, it
contains multiple next states, and it contains ε transition.

Example: In the below NFA there are multiple paths for the input string “00”. Since one of the
paths leads to a final state, “00” is accepted by the above NFA.

Figure: DFA with Σ = {0, 1}

Formal definition of NFA:

NFA also has five states same as DFA, but with different transition function, as shown follows:

δ: Q x ∑ →2Q

where,

Q: finite set of states

∑: finite set of the input symbol

q0: initial state

F: final state

δ: Transition function

Graphical Representation of an NFA

An NFA can be represented by digraphs called state diagram. In which:

1. The state is represented by vertices.


2. The arc labeled with an input character show the transitions.
3. The initial state is marked with an arrow.

16
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
4. The final state is denoted by the double circle.

Example 1:

Q = {q0, q1, q2}

∑ = {0, 1}

q0 = {q0}

F = {q2}

Solution:

Transition diagram:

Transition Table:

Present State Next state for Input 0 Next State of Input 1


→q0 q0, q1 q1
q1 q2 q0
*q2 q2 q1, q2
Example 2:

NFA with ∑ = {0, 1} accepts all strings with 01.

Solution:

Transition Table:

Present State Next state for Input 0 Next State of Input 1


→q0 q1 ε
q1 ε q2
*q2 q2 q2

17
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
Example 3:

NFA with ∑ = {0, 1} and accept all string of length atleast 2.

Solution:

Transition Table:

Present State Next state for Input 0 Next State of Input 1


→q0 q1 q1
q1 q2 q2
*q2 ε ε

Example 4:

Design a NFA for the transition table as given below:

Present State Next state for Input 0 Next State of Input 1


→q0 q0, q1 q0, q2
q1 q3 ε
q2 q2, q3 q3
*q3 q3 q3

Solution:

The transition diagram can be drawn by using the mapping function as given in the table.

18
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
Example 5:

Design an NFA with ∑ = {0, 1} accepts all string ending with 01.

Solution:

Hence, NFA would be:

Example 3:

Design an NFA with ∑ = {0, 1} in which double '1' is followed by double '0'.

Solution:

The NFA with double 1 is as follows:

It should be immediately followed by double 0.

Then,

Now before double 1, there can be any string of 0 and 1. Similarly, after double 0, there can be
any string of 0 and 1. Hence the NFA becomes

Now considering the string 01100011

q0 → q1 → q2 → q3 → q4 → q4 → q4 → q4

Example 4:

Design an NFA in which all the string contains a substring 1110.

Solution:

19
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
The language consists of all the string containing substring 1010. The partial transition diagram
can be:

Now as 1010 could be the substring. Hence we will add the inputs 0's and 1's so that the
substring 1010 of the language can be maintained. Hence the NFA becomes:

Transition table for the above transition diagram can be given below:

Present State Next state for Input 0 Next State of Input 1


→q1 q1 q1, q2
q2 q3
q3 q4
q4 q5
*q5 q5 q5

Consider a string 111010,

δ(q1, 111010) = δ(q1, 1100)

= δ(q1, 100)

= δ(q2, 00)

Got stuck! As there is no path from q2 for input symbol 0. We can process string 111010 in
another way.

δ(q1, 111010) = δ(q2, 1100)

= δ(q3, 100)

= δ(q4, 00)

= δ(q5, 0)

= δ(q5, ε)

As state q5 is the accept state. We get the complete scanned, and we reached to the final state.

20
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.
Example 5:

Design an NFA with ∑ = {0, 1} accepts all string in which the third symbol from the right end is
always 0.

Solution:

Thus we get the third symbol from the right end as '0' always. The NFA can be:

The above image is an NFA because in state q0 with input 0, we can either go to state q0 or q1.

21
Mr. K. Leela Prasad, Asst. Prof. CSE Dept.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy