Flat All Units
Flat All Units
Flat All Units
Introduction
Symbols, Alphabets, Strings, Languages, operations on Strings and Languages, Finite State
Machine, Definitions, Model representation of a Finite Automata, Acceptance of Strings and
Languages, Deterministic finite automaton(DFA) and Non-deterministic Finite
Automaton(NFA),Transition diagrams and Language recognizers.(Proofs Not Required)
Symbols: Symbol is the smallest building block, which can be any alphabet, letter or any picture.
Ex: a,b,c, …, 0,1, 2, … [Formal language does not deal with the “meaning” of the symbols.]
A finite state machine (sometimes called a finite state automaton) is a computation model that can
be implemented with hardware or software and can be used to simulate sequential logic and some
computer programs. Finite state automata generate regular languages. Finite state machines can
be used to model problems in many fields including mathematics, artificial intelligence, games, and
linguistics.
e) The input is strings over Σ = {0, 1}. Accept: all strings of the form 00w, where w contains an even
number of ones.
Example 3.3: Let Σ= {a, b} and consider the following DFA M, whose language L(M) contains strings
consisting of one or more a’s followed by one or more b’s.
Tables and state diagrams are most useful for small automata. Formulas are helpful for summarizing a
group of transitions that fit a common pattern. They are also helpful for describing algorithms that modify
automatas.
Example
a) Draw a DFA to accept string of 0’s and 1’s ending with the string 011.
L= {011, 0011, 1011, 00011, 01011, 10011, 11011, ...},
b) Obtain a DFA to accept strings of a’s and b’s having a sub string aa
Example 3.4:
Example: construct a DFA strings ending with 100
Non Deterministic Automata
NFA is a mathematical model in which there can be more than one transitions with the same input to more
than one distinct states.
Definition:
A nondeterministic finite automaton is a 5 - tupple (Q, , , s, F ), where
Q is a finite set called the states,
is a finite set called the alphabet,
: Q 2Q is the transition function,
s Q is the start state, and
F Q is the set of accept/final states. (there can be multiple states)
Note: For any alphabet ∑ we write
The formal definition of an NFA is similar to that of a DFA. Both have states, an
alphabet, transition function, one start state, and a collection of accept states
Differ in one essential way: the transition functions:
Example:
1. Q {q1 , q2 , q3 , q4 },
2. {0,1}
0 1
q1 {q1} {q1 , q2 }
3. is given as q2 {q3 } {q3 }
q3 {q4 }
q4 {q4 } {q4 }
4. q1 is the start state.
5. F {q4 }.
Ans:
It accepts any binary string that contains 00 or 11 as a
substring.
Ans: Accepts all binary strings where the last symbol is 0 or that contain only 1’s.
Computation performed by an NFA
Condition 1 says that the machine starts its computation in the start state
Condition 2 says that state ri+1 is one of the allowable new states when is in state ri and reads yi+1. Note that
is a set
Condition 3 says that the machine accepts the input if the last state is in the accept state set.
An important property: Any NFA N can be converted to an equivalent NFA that has a single accept
state
Short Questions
1. Define: (i) Finite Automaton(FA) (ii)Transition diagram
2. What are the components of Finite automaton model?
3. What are the applications of automata theory?
4. How to check acceptance of string by finite automata?
5. What is a string? Write about concatenation of two strings?
6. What is Kleene Closure and Positive Closure?
7. Differentiate NFA and DFA
8. Explain transition diagram, transition table with example.
9. Define transition function of DFA.
10. Define ε –transitions.
11. Design DFA to accept strings with ‘c’ and ‘d’ such that number of d’s are divisible by 4.
12. Design DFA for the following over {a, b}
i) All strings containing not more than three a’s.
ii) All strings that has at least two occurrences of b between any two occurrences of a.
13. a) Design DFA for the following over {a,b}.
i) All strings containing not more than three a’s.
ii) All strings that has at least two occurrences of b between any two occurrences of a.
b) Construct a DFA accepting the set of all strings ending with 00?
14. Construct a DFA accepting the language
15. Construct a DFA accepting the language has neither aa nor bb as substring
16. a) What is NFA? Explain the transitions of NFA?
b) Construct an NFA that accepts the set of all strings over
{0,1} that start with 0 or 1 and end with 10 or 01.
c) Construct a DFA equivalent to the NFA given below
17. Construct DFA, which accepts set of all strings over {0, 1} which interpreted as binary number
is divisible by 2.
Ans: Consider the following inputs, {0, 01, 10, 11, 100, 101, 110........}
The state transition diagram of the language will be like:
In this DFA there are two states q0 and q1 and the input is strings of {0, 1} which is interpreted as
binary number.
The state q0 is final state and q1 is non-final state. State q0 will be representing all the numbers that are
divisible by 2, that is {0, 10, 100, 110…..}.
State q1 will be representing all the numbers that are not divisible by 2, that is {01, 11, 101, ……}.
Construct DFA, which accepts set of all strings over {0, 1} which interpreted as binary number is
divisible by 3.
Construct DFA, which accepts set of all strings over {0, 1} which interpreted as binary number is
divisible by 4.
Consider the following inputs, {0, 01, 10, 11, 100, 101, 110........}
The state transition diagram of the language will be like:
In this DFA there are three states q0, q1, q2, q3 and the input is strings of {0, 1} which is interpreted as
binary number. The state q0 is final state and q1, q2, q3 are non-final state.
State q0 will be representing all the numbers that are divisible by 4, that is {0, 100, 1000…..}.
State q1 will be representing all the numbers that are not divisible by 4 and give remainder 1 when
divided by 4, that is {01, 101,,……}.
State q2 will be representing all the numbers that are not divisible by 4 and give remainder 2 when
divided by 4, that is {10, 110, ……}.
State q4 will be representing all the numbers that are not divisible by 4 and give remainder 3 when
divided by 4, that is {11, 111, ……}.
The above automata will accept set of all strings over {0, 1} which when interpreted as binary number is
divisible by 4.
State Whenever the number is not divisible by 4 and gives remainder of 1 then it will go to state q1.
State Whenever the number is not divisible by 4 and gives remainder of 2 then it will go to state q2.
State Whenever the number is not divisible by 4 and gives remainder of 3 then it will go to state q3.
State Whenever the number is divisible by 4, then it will go to state q0 or if it was initially in q0 then
it will accept it.
Divisibility by 2
A number is divisible by 2 if its units place is either 0 or multiple of 2.
In other words, a number is divisible by 2, if the digit at ones place is an even number, that is the number
ends in 0, 2, 4 or 8.
Divisibility by 3
A number is divisible by 3 if the sum of digits is a multiple of 3.
In other words, a number is divisible by 3, if sum of all its digits is divisible by 3.
For example:
79851 is divisible by 3 as the sum of its digits, i.e., 7 + 9 + 8 + 5 + 1 = 30 is divisible by 3.
Divisibility by 4
A number is divisible by 4 if the number formed by its digits in tens and units place is divisible by 4.
In other words, a number is divisible by 4, if the number formed by its last 2 digits is divisible by 4.
Example: 88312 is divisible by 4 because the number formed by its last two digits i.e., 12 is divisible by 4.
Divisibility by 5
A number is divisible by 5 if its units place is 0 or 5.
In other words, a number is divisible by 5, if it ends in 0 or 5.
For example: 75325 is divisible by 5 as its last digit is 5.
UNIT-2
Acceptance of languages, Equivalence of NFA and DFA, NFA to DFA conversion, NFA
with Ɛ-transitions, Significance, Conversion of NFA with Ɛ-transitions to NFA without Ɛ-
transitions, Minimization of finite automata, Equivalence between two DFA’s.
where
The two automata are not equivalent if for a pair {q a, qb} one is INTERMEDIATE state
and the other is FINAL state.
2. If Initial State is Final State of one automaton, then in second automaton also Initial
State must be Final State for them to be equivalent.
Example:
Questions
Regular Set
Any set that denotes the value of the Regular Expression is called a "Regular Set".
Regular sets have various properties:
Property 1) The union of two regular sets is also a regular set
Let there be two regular expressions RE1 = 0(00)* and RE2 = (00)*
L1= {0, 000, 00000,..} (odd length strings without Null)
L2={ε, 00, 0000, 000000,.......} (even length strings with Null)
L1∪ L2 = {ε, 0, 00, 000, 0000, 00000, 000000,.......} (all possible lengths strings with Null)
RE(L1∪L2)= 0* (this is also a regular expression or a regular set)
Regular Expressions
Regular Expressions (RE) are used for representing certain sets of strings in an algebraic fashion.
Definitions:
1. ε (epsilon) is a RE indicates the language containing an empty string. L(ε) = {ε}
2. φ (phi) is a RE denoting an empty language. L(φ) = { }
3. a is a RE where L = {a}
4. If R is a RE denoting the language LR and S is a RE denoting the language LS, then
a) R+S is a RE corresponding to the language LR∪ LS
b) R•S is a RE corresponding to the language LR• LS
c) R* is a RE corresponding to the language LR*
Identity rules
Let r, r1, r2, and r3 be any regular expressions then the identity rules are as follows:
Regular expression (RE) can be converted into DFA by the following methods:
a) Thompson’s subset construction
• Given regular expression is converted into NFA
• Resultant NFA is converted into DFA
b) Direct Method
• In direct method, given regular expression is converted directly into DFA.
------------------------------------------------------------------------------------------------------------
RE to NFA RE to DFA
Conversion of Regular Expression to Finite Automata
Designing Finite Automata from Regular Expression
1.
2.
3.
4.
5.
6. The regular expression for even number of a’s is (b|ab*ab*)*. We can construct a finite
automata as
7. The regular expression for strings with ‘ab’ as substring is (a|b)*ab(a|b)*. We can construct
finite automata as
8. The regular expression for strings with count of a divisible by 3 is {a 3n | n >= 0}. We can
construct automata as
9. The regular expression for binary numbers which are divisible by three is (0|1(01*0)*1)*. We
can construct automata as
Pumping Lemma
Purpose:
1. It is used to prove that a Language is Not Regular
2. It cannot be used to prove that a language is Regular
All strings in the language can be repeated --- PUMPED--- if they are at least as long as a certain
length. The pumping Length (P)
Assignment
UNIT-4
Context Free Grammars: Context free grammars and languages, Derivation trees, Left most and
Right most derivation of strings and sentential forms Ambiguity, left recursion and left factoring in
context free grammars, Minimization of context free grammars, Normal forms for context free
grammars, Chomsky normal form, Grei-bach normal form, Pumping Lemma for Context Free
Languages (Proofs Not Required).
Pushdown Automata: Definition, Graphical notation, Acceptance of context free language,
Acceptance by final state and empty state and its equivalence, Equivalence of context free grammars
and pushdown automata. Definition of Context Sensitive Grammar (CFG) (Proofs Not Required)
Context Free Grammars (CFG)
Grammar: It contains set of rules to construct the sentence in a language.
Context Free means there is a single variable on the left side of each grammar rule.
In formal languages theory, a Context Free Language (CFL) is a language generated by some Context Free
Grammar (CFG).
The set of all CFL is identical to the set of languages accepted by Pushdown Automata (PDA).
Example CFG:
<sentence> –> <noun-phrase> <verb-phrase> (1)
<noun-phrase> –> <proper-noun> (2)
<noun-phrase> –> <determiner> <common-noun> (3)
<proper-noun> –> John (4)
<proper-noun> –> Jill (5)
<common-noun> –> car (6)
<common-noun> –> hamburger (7)
<determiner> –> a (8)
<determiner> –> the (9)
<verb-phrase> –> <verb> <adverb> (10)
<verb-phrase> –> <verb> (11)
<verb> –> drives (12)
<verb> –> eats (13)
<adverb> –> slowly (14)
<adverb> –> frequently (15)
Example Derivation:
<sentence> => <noun-phrase> <verb-phrase> by (1)
=> <proper-noun> <verb-phrase> by (2)
=> Jill <verb-phrase> by (5)
=> Jill <verb> <adverb> by (10)
=> Jill drives <adverb> by (12)
=> Jill drives frequently by (15)
Informally, a CFG is a set of rules for deriving (or generating) strings (or sentences) in a language.
Example-1: For generating a language that generates equal number of a’s and b’s in the form anbn | n≥0,
the CFG will be defined as G = ({S, A}, {a,b}, S –> aAb, A –>aAb| ε, S) //Remember: G = (V, T, P, S)
Solution:
Derivation Tree
A Derivation Tree or Parse Tree is an ordered rooted tree that graphically represents the semantic information
of strings derived from a CFG.
Example 3.2: Let G be a context free grammar for which the production rules are given as below:
QUESTION: Given a grammar, is it possible that every (left/right) derivation for a string is
unique?
Ans: ---------
Ambiguous Grammar
If a context free grammar G has more than one derivation tree for some string w ∈ L(G), it is called
an ambiguous grammar. There exist multiple right-most or left-most derivations for some string generated
from that grammar.
QUESTION: Why do we care about this? Isn’t our goal to determine whether or not w ∈ L(G)?
Parse trees give meaning to the string with respect to the grammar.
For example: a − b ∗ c means that a − (b ∗ c) (or) (a − b) ∗ c.
• How can we fix this?
Ans: Precedence Rule and Associativity Rule.
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner