You are on page 1of 21

FORMAL

METHODS
Lecture 7: Finite state machine models

LECTURER: QURATULAIN
DEPARTMENT OF INFORMATION TECHNOLOGY
GOVERNMENT COLLEGE UNIVERSITY FAISALABAD
FINITE STATE MACHINE
MODELS

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.
DETERMINISTIC FINITE AUTOMATON
In the automata theory, a branch of theoretical computer
science, a deterministic finite automaton (DFA)—also known
as deterministic finite state machine—is a finite state machine
that accepts/rejects finite strings of symbols and only produces
a unique computation (or run) of the automaton for each input
string. 'Deterministic' refers to the uniqueness of the
computation.
DETERMINISTIC FINITE AUTOMATON
Because DFAs can be reduced to a efficient algorithms to
determine:
1. whether a DFA accepts any strings
2. whether a DFA accepts all strings
3. whether two DFAs recognize the same language
4. the DFA with a minimum number of states for a particular
regular language
NONDETERMINISTIC FINITE AUTOMATON
In the automata theory, a nondeterministic finite automaton
(NFA) or nondeterministic finite state machine is a finite state
machine where from each state and a given input symbol the
automaton may jump into several possible next states.
This distinguishes it from the deterministic finite automaton
(DFA), where the next possible state is uniquely determined.
Accepts string any number of a,b
Example :
Q = {q0}
∑ = {a,b}
Start a,b
q0 = {q0} q0
F = {q0}
L={ a, b, ab,ba, abbb, babaa, babb, abab,….. }

Transition Table
Present Next state for Input
Next State of Input b
State a

→q0 q0 q0 F
accepts string of a Accepts ALL strings of a’s
Example :
Example :
Q = {q0, q1}
Q = {q0, q1}
∑ = {a}
∑ = {a}
q0 = {q0}
q0 = {q0}
F = {q1}
F = {q1}
L= {a, aa, aaa, aaaa, aaaaa, ….} a
L={ a }
qo a a
Start q1 qo q1
Start

Transition Table Transition Table


Present Next state for Input Present Next state for Input
State a State a

→q0 q1 →q0 q1

q1 ε q1 q1
Accepts string either starting from a OR b and
followed by any number of a,b
Example :
Q = {q0, q1}
∑ = {a,b}
Start qo a a,b
q1
q0 = {q0}
F = {q1}
b
L={ a, b, ab,ba, abb, baa, bab, aba,….. }

Transition Table
Present Next state for Input
Next State of Input b
State a

→q0 q1 q1

F q1 q1 q1
That accepts strings of a’s and b’s, ending
with A.
Example : b a
a
Q = {q0, q1, q2} Start qo q1
∑ = {a, b}
q0 = {q0}
b
F = {q1}
L= { aa, ab, ba, baa, baba, aba, aba,…}

Transition Table
Present Next state for Input
Next State of Input b
State a

→q0 q1 q0

q1 q1 q0
That accepts strings of a’s and b’s, where all
a’s come before all b’s.
Example : a b
Q = {q0, q1, q2} b
Start qo q1
∑ = {a, b}
q0 = {q0}
F = {q0,q1} a
L= {

Transition Table q2
a,b
Present Next state for Input
Next State of Input b
State a
→q0 q0 q1

q1 q2 q1

F q2 q2 q2
NFA: ACCEPT ALL STRING OF LENGTH AT LEAST 2.
Transition Table
Example 3: Present State Next state for Input 0 Next State of Input 1

NFA with →q0 q1 q1


∑ = {0, 1} and accept all
string of length at least 2. q1 q2 q2

*q2 ε ε

Start 0, 1 0,1

qo q1 q2
NFA: ACCEPTS ALL STRINGS STARTING WITH 01.
Example 2: Transition Table
NFA with Present State Next state for Input 0 Next State of Input 1
∑ = {0, 1}
→q0 q1 ε

q1 ε q2

F q2 q2 q2

0, 1

Start 0 1

qo q1 q2
DFA: LANGUAGE IN WHICH0 ALWAYS APPEARS
IN A GROUP OF 3
Example:
Transition Table
Q = {q0, q1, q2}
Present Next state for Next State of
∑ = {0, 1} State Input 0 Input 1
q0 = {q0} →q0 q1 q0
F = {q3} q1 q2 ε
L= {000, 0001,10001,1000,0001000, ….}
q2 q3 ε

q3 q1 q3
1
1

Start 0 0 0

qo q1 q2 q3

0
DFA: ACCEPTS ALL STARTING WITH 0.
Transition Table
Example : Present State Next state for Input 0 Next State of Input 1
DFA with
→q0 q2 q1
∑ = {0, 1} L= {00, 01, 000,
001,…} q1 ε ε

F q2 q2 q2

Start

qo
0 0,1

1
q2

q1
DFA: ACCEPTS THE STRINGS WITH AN EVEN
NUMBER OF 0'S FOLLOWED BY SINGLE 1
Example : 1
0
DFA with ∑ = {0, 1} qo
Start q1
L= {001, 0101, 010001, 01010101,…}
0

1
Transition Table
Present
State
Next state for Input
0
Next State of Input 1 q2
→q0 q2 q1

q1 ε ε

F q2 q2 q2
DFA: ACCEPTS ALL ENDING WITH 0.
Transition Table

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

DFA with ∑ = {0, 1} →q0 q1 q0

q1 q1 q0

L= { 00, 10, 110,


100,…} 1
0
X L = {11,10..}
Start 0

qo q1
1
EXAMPLES OF DFA
Design a FA with ∑ = {0, 1} accepts those string which starts with 1 and ends with 0.

1
0

Start 1 0

qo q1 q2
1

Home Task:
Draw a Transition Table
EXAMPLES OF DFA
Design a FA with ∑ = {0, 1} accepts the only input 101.

Home Task:
• Create a DFA Diagram
• Draw a Transition Table
EXAMPLES OF DFA
Design FA with ∑ = {0, 1} accepts even number of 0's and even number of 1's.

Start 1
0
qo q1

1
1 1 1 1
Home Task:
0 Draw a Transition
q2 q3
Table
0
Next Lecture TYPES OF FINITE STATE
MACHINE

Mealy State Machine


Moore State Machine
FINITE STATE MACHINE
APPLICATIONS
• FSMs are used in games; they are most recognized for being utilized in artificial
intelligence, and however, they are also frequent in executions of navigating parsing
text, input handling of the customer, as well as network protocols.
• These are restricted in computational power; they have the good quality of being
comparatively simple to recognize. So, they are frequently used by software
developers as well as system designers for summarizing the performance of a difficult
system.
• The finite state machines are applicable in vending machines, video games, traffic
lights, controllers in CPU, text parsing, analysis of protocol, recognition of speech,
language processing, etc.

You might also like