CS 3240: Languages and Computation Introducing Regular Languages: Deterministic Finite Automata and Regular Expressions
Mar 28, 2015
CS 3240: Languages and Computation
Introducing Regular Languages:
Deterministic Finite Automata
and Regular Expressions
Automata Finite Automata model many design and
analysis tasks, e.g. Lexical analyzer in a compiler Digital cicuit design Keywork searching in texts or on the web. Software for verifying finite state systems, such as communication protocols. Your ATM, vendig machine, Etc.
1950-59 McCulloch&Pitts, Rabin&Scott, Moore, Huffman
Finite State Machine and Finite Automata
Deterministic Finite Automata
A simplest model for computingDeterministic: Machine is in a state. Upon
receipt of a symbol will go to a unique state.Finite: Have a finite number of statesAutomata: (pl. of automaton) Self-operating
machine DFA: finite-state machine without ambiguity
DFA and Strings
DFA can recognize stringsString is input If DFA ends at accept state, string is recognized
A language is called a regular language if some finite automaton recognizes it
Let us look at a few example before giving formal mathematical definition
DFA Examples
1 2
0 11
0
Accept all stringsthat end in 1
Note: The alphabet for this example is {0, 1}. Each statehas a transition for every symbolin the alphabet
accept state
transition
start state
DFA Examples
Accept strings of 'a's and 'b's that begin and end with same symbol
5
3
4
2
1a
a
a
a
a
b
bb
b
b
DFA Examples
2
Keep running count of total of symbols readin mod 3. Accept on 0.
1
00 1
2
0
1
2
0
1
2
Start
DFA Examples
Strings with an oddnumber of ones.
Even Odd
0 0
1
1
DFA Examples
Strings containingthe substring 001
'001'
0 01
1
'0' '00'
0
10,1
Formal Definition of DFA A DFA consists of:
Alphabet A set of states Q A transition function δ : Q Q One start state q0
One or more accepting states F Q
Language accepted by a DFA is the set of strings such that DFA ends at an accepting state Each string is c1c2…cn with ci States are qi = δ(qi-1,ci ) for i=1…n
qn is an accepting state
Can DFA's be designed to accept any string?
No!
Examples
Design a DFA to recognize strings that start out with k zeros followed by k ones. Impossible
Design a DFA to recognize strings with an equal number of ones and zeros. Impossible
Design a DFA to recognize strings with an equal number of strings "01" and "10".Possible!
Actually the thirdone is regular!
DFA to recognize strings with an equal number of strings "01" and "10"
0
0
0
0
0
1
1
1
1
1
1
0
1
0
DFA More examples
DFA More examples
A,B are the input into which themarble is dropped. The x-levers cause fall either to left or right, but lever reversesupon a marble passingAccept if marble exits through D
Non-Deterministic Finite Automata
NFA and -NFA
Nondeterministic Finite AutomataSame input may produce multiple pathsAllows transition with an empty string or
transition from one state to different states given a character
q1 q2
empty string transition
q1
q21
q31
nondeterministic transition