0% found this document useful (0 votes)
37 views17 pages

Unit-1 Part-1

This document defines and provides examples of key concepts related to strings and formal languages. It defines the length of a string, prefixes, suffixes, substrings, the power or set of all strings that can be formed from an alphabet, concatenation, and languages. It also defines natural languages versus formal languages. Formal languages have specific rules and meanings are not important. They can be specified by grammars or machines. The document provides examples of deterministic finite automata (DFAs), non-deterministic finite automata (NFAs), and differences between the two.

Uploaded by

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

Unit-1 Part-1

This document defines and provides examples of key concepts related to strings and formal languages. It defines the length of a string, prefixes, suffixes, substrings, the power or set of all strings that can be formed from an alphabet, concatenation, and languages. It also defines natural languages versus formal languages. Formal languages have specific rules and meanings are not important. They can be specified by grammars or machines. The document provides examples of deterministic finite automata (DFAs), non-deterministic finite automata (NFAs), and differences between the two.

Uploaded by

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

Length of string-: is the total no of symbol present in the string .

Example1 -: ∑={0,1} w=01010


Then length of string is denoted by |w| and here it is 5
so we can write |w|=5
Example2-: w =ε then the length of w is given by |w|=0
Prefix-: prefix of a string is any number of leading symbol of string.
Example-: let w=abc Prefix of w are ε,a,ab,abc.
Suffix-: is the any number of trailing symbol of string.
Example w=abc The suffix are ε,c,bc,abc
Substring-:Any sequence of symbol over the given string.
Example-: w=abc The substring of w are ε,a,b,c,bc,ab,abc.
Power of an alphabet-The string that can be formed by taking number of
symbol from given alphabet ∑ , no of symbol we can take will be given by the
power.
Example-: ∑={0,1}
Then ∑ 0={ε}
∑ 1={0,1}
∑ 2={00,01,10,11}
∑ 3={000,001,011,....,111}
∑ *=∑ 0 ᴗ ∑ 1 ᴗ ∑ 2 ᴗ ∑ 3 .........
So ∑*={ε,0,1,00,01,11,10,000,001.....}
∑ += All the string except non-empty string
So ∑ += ∑1 ᴗ ∑ 2 ᴗ ∑ 3 ......... And then
∑ +={0,1,00,01,11,10,000,001.....}
Concatenation of String-: if w and x are two string then the concatenation of
two string is denoted by wx.
Example-: w=1110 and x=0101
Then wx=11100101
Language-:It is the set of string over the alphabet ∑ which follows a set of rules
called the grammar.L Or otherwise we can say set of string generated by
grammar taking symbol from ∑ .
Example 1- All string start with 11 from ∑={0,1}
L ={110,111,1100,1111,1101,1110,........}
Example 2-: set of binary number whose value is prime.
L= {10,11,101,111,1011,......}
Note-: L={ϕ} is called empty language.
And L={ε} Language consisting of only the empty string.
Natural Language-: the language we use as medium of communication.
Formal Lanugage-: collection of string where format (given by grammar) is
important and meaning is not important.
a formal language is a set of strings of symbols drawn from a finite alphabet. A
formal language can be specified either by a set of rules (such as regular
expressions or a context-free grammar) that generates the language, or by
a formal machine that accepts (recognizes) the language. A formal machine
takes strings of symbols as input and outputs either “yes” or “no.” A machine is
said to accept a language if it says “yes” to all and only those strings that are in
the language. Alternatively, a language can be defined as the set of strings for
which a particular machine says “yes.”
Formal languages can be grouped into a series of successively larger classes
known as the Chomsky hierarchy. Most of the classes can be characterized in
two ways: by the types of rules that can be used to generate the set of strings,
or by the type of formal machine that is capable of recognizing the language.

Language of machine -: Set of all accepted string of the machine


Grammar-: A set of rules used to generate the string for a particular language
Q. Find the number of prefix, suffix, and substring for a given string of length n.
Ans-: Number of prefix=n+1
Number of suffix=n+1
Number of substring =(n(n+1))/2 + 1.

Trap state in DFA


If a transition goes to a state from which it can never escape. Such a state is called a trap
state. It is called the dead state.

In the above example, q2 is a trap or dead state because it can’t reach the final state.

Application of DFA (Deterministic Finite Automata)


The different applications of deterministic finite automata are as follows −

 Protocol analysis text parsing.


 Video game character behavior.
 Security analysis.
 CPU control units.
 Natural language processing Speech recognition, etc.

Example
Construct transition table of DFA for a given diagram.
Q= {q0,q1,q2}
Σ ={0,1}
q0= {q0}
F= {q2}

Transition diagram
The transition diagram is as follows −
Transition Table
The transition table is as follows −

Present state Next state for input 0 Next state for input 1

->q0 q0 q1

q1 q2 q1

*q2 q2 q2

Explanation
 Step 1 − In the above table q0 is the initial state, on input ‘0’ the q0 state goes to
itself and on input ‘1’ it goes to state q1.
 Step 2 − q1 is the intermediate state, on input ‘0’ q1 goes to q2 state and on input
‘1’, q1 goes to itself.
 Step 3 − q2 is the final state, q2 on ‘0’ goes to q2 itself and input ‘1’ goes to q2
itself.

Non-deterministic Finite Automaton


In NDFA, for a particular input symbol, the machine can move to any combination of the states in the
machine. In other words, the exact state to which the machine moves cannot be determined. Hence, it
is called Non-deterministic Automaton. As it has finite number of states, the machine is called Non-
deterministic Finite Machine or Non-deterministic Finite Automaton.

o NFA stands for non-deterministic finite automata. It is easy to construct an


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

In the following image, we can see that from state q0 for input a, there are two next
states q1 and q2, similarly, from q0 for input b, the next states are q0 and q1. Thus it
is not fixed or determined that with a particular input where to go next. Hence this
FA is called non-deterministic finite automata.

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 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).
Graphical Representation of an NDFA: (same as DFA)
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.
Example
Let a non-deterministic finite automaton be →

 Q = {a, b, c}
 ∑ = {0, 1}
 q0 = {a}
 F = {c}
The transition function δ as shown below −

Present State Next State for Input 0 Next State for Input 1

A a, b b

B c a, c

C b, c c

Its graphical representation would be as follows −

Example 1:
1. Q = {q0, q1, q2}
2. ∑ = {0, 1}
3. q0 = {q0}
4. 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

In the above diagram, we can see that when the current state is q0, on input 0, the
next state will be q0 or q1, and on 1 input the next state will be q1. When the current
state is q1, on input 0 the next state will be q2 and on 1 input, the next state will be
q0. When the current state is q2, on 0 input the next state is q2, and on 1 input the
next state will be q1 or 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

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 Ε ε

Difference between DFA and NFA :

DFA NFA

DFA stands for Deterministic Finite NFA stands for Nondeterministic Finite
Automata. Automata.
DFA NFA

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.

DFA cannot use Empty String transition. NFA can use Empty String transition.

NFA can be understood as multiple little


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

In NFA, each pair of state and input


In DFA, the next possible state is
symbol can have many possible next
distinctly set.
states.

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

DFA rejects the string in case it


NFA rejects the string in the event of all
terminates in a state that is different
branches dying or refusing the string.
from the accepting state.

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

All DFA are NFA. Not all NFA are DFA.

DFA requires more space. NFA requires less space then DFA.

Dead configuration is not allowed. Dead configuration is allowed.


eg: if we give input as 0 on q0 state so eg: if we give input as 0 on q0 state so we
we must give 1 as input to q0 as self can give next input 1 on q1 which will go
loop. to next state.
DFA NFA

δ: QxΣ -> Q i.e. next possible state δ: QxΣ -> 2^Q i.e. next possible state
belongs to Q. belongs to power set of Q.

Backtracking is allowed in DFA. Backtracking is not always possible in NFA.

Conversion of Regular expression to Conversion of Regular expression to NFA


DFA is difficult. is simpler compared to DFA.

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

DFA allows only one move for single There can be choice (more than one
input alphabet. move) for single input alphabet.

NFA and DFA Equivalence

Problem Statement
Let X = (Qx, ∑, δx, q0, Fx) be an NDFA which accepts the language L(X). We have to design
an equivalent DFA Y = (Qy, ∑, δy, q0, Fy) such that L(Y) = L(X). The following procedure
converts the NDFA to its equivalent DFA −

Algorithm
Input − An NDFA
Output − An equivalent DFA
Step 1 − Create state table from the given NDFA.
Step 2 − Create a blank state table under possible input alphabets for the equivalent DFA.
Step 3 − Mark the start state of the DFA by q0 (Same as the NDFA).
Step 4 − Find out the combination of States {Q0, Q1,... , Qn} for each possible input alphabet.
Step 5 − Each time we generate a new DFA state under the input alphabet columns, we have
to apply step 4 again, otherwise go to step 6.
Step 6 − The states which contain any of the final states of the NDFA are the final states of
the equivalent DFA.

Example 1
Let us consider the NDFA shown in the figure below.

Q δ(q,0) δ(q,1)

A {a,b,c,d,e} {d,e}

B {c} {e}

C ∅ {b}

D {e} ∅

E ∅ ∅

Using the above algorithm, we find its equivalent DFA. The state table of the DFA is shown
in below.

Q δ(q,0) δ(q,1)

[a] [a,b,c,d,e] [d,e]

[a,b,c,d,e] [a,b,c,d,e] [b,d,e]

[d,e] [e] ∅

[b,d,e] [c,e] [e]

[e] ∅ ∅
[c, e] ∅ [b]

[b] [c] [e]

[c] ∅ [b]

The state diagram of the DFA is as follows −

Example 2:
Convert the given NFA to DFA.
Solution: For the given transition diagram we will first construct the transition table.

State 0 1

→q0 q0 q1

q1 {q1, q2} q1

*q2 q2 {q1, q2}

Now we will obtain δ' transition for state q0.

1. δ'([q0], 0) = [q0]
2. δ'([q0], 1) = [q1]

The δ' transition for state q1 is obtained as:

1. δ'([q1], 0) = [q1, q2] (new state generated)


2. δ'([q1], 1) = [q1]

The δ' transition for state q2 is obtained as:

1. δ'([q2], 0) = [q2]
2. δ'([q2], 1) = [q1, q2]

Now we will obtain δ' transition on [q1, q2].

1. δ'([q1, q2], 0) = δ(q1, 0) ∪ δ(q2, 0)


2. = {q1, q2} ∪ {q2}
3. = [q1, q2]
4. δ'([q1, q2], 1) = δ(q1, 1) ∪ δ(q2, 1)
5. = {q1} ∪ {q1, q2}
6. = {q1, q2}
7. = [q1, q2]

The state [q1, q2] is the final state as well because it contains a final state q2. The
transition table for the constructed DFA will be:
State 0 1

→[q0] [q0] [q1]

[q1] [q1, q2] [q1]

*[q2] [q2] [q1, q2]

*[q1, q2] [q1, q2] [q1, q2]

The Transition diagram will be:

Example 3:
Convert the given NFA to DFA.
Solution: For the given transition diagram we will first construct the transition table.

State 0 1

→q0 {q0, q1} {q1}

*q1 ϕ {q0, q1}

Now we will obtain δ' transition for state q0.

1. δ'([q0], 0) = {q0, q1}


2. = [q0, q1] (new state generated)
3. δ'([q0], 1) = {q1} = [q1]

The δ' transition for state q1 is obtained as:

1. δ'([q1], 0) = ϕ
2. δ'([q1], 1) = [q0, q1]

Now we will obtain δ' transition on [q0, q1].

1. δ'([q0, q1], 0) = δ(q0, 0) ∪ δ(q1, 0)


2. = {q0, q1} ∪ ϕ
3. = {q0, q1}
4. = [q0, q1]

Similarly,

1. δ'([q0, q1], 1) = δ(q0, 1) ∪ δ(q1, 1)


2. = {q1} ∪ {q0, q1}
3. = {q0, q1}
4. = [q0, q1]

As in the given NFA, q1 is a final state, then in DFA wherever, q1 exists that state
becomes a final state. Hence in the DFA, final states are [q1] and [q0, q1]. Therefore
set of final states F = {[q1], [q0, q1]}.

The transition table for the constructed DFA will be:

State 0 1

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

*[q1] Φ [q0, q1]

*[q0, q1] [q0, q1] [q0, q1]

The Transition diagram will be:

Even we can change the name of the states of DFA.

Suppose

1. A = [q0]
2. B = [q1]
3. C = [q0, q1]

With these new names the DFA will be as follows:

You might also like