0% found this document useful (0 votes)
18 views

Finite Automata

The document discusses finite automata theory. It provides examples of finite automata and how they work. A finite automaton consists of a finite set of states, an input alphabet, and transition rules specifying the next state for each current state-input pair. It changes states based on sequential input letters until reaching an accepting state. There are two main types: deterministic finite automata (DFAs) which transition to exactly one state per input, and non-deterministic finite automata (NFAs) which may transition to multiple states per input or without input. The document explains finite automata using examples, transition tables, diagrams, and applications in formal language recognition.

Uploaded by

hamzajaat751
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Finite Automata

The document discusses finite automata theory. It provides examples of finite automata and how they work. A finite automaton consists of a finite set of states, an input alphabet, and transition rules specifying the next state for each current state-input pair. It changes states based on sequential input letters until reaching an accepting state. There are two main types: deterministic finite automata (DFAs) which transition to exactly one state per input, and non-deterministic finite automata (NFAs) which may transition to multiple states per input or without input. The document explains finite automata using examples, transition tables, diagrams, and applications in formal language recognition.

Uploaded by

hamzajaat751
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 37

Duration: 1 Hour Degree: BSCS Course Code: BCS-3513 Semester: 5th

Chapter 5
Finite Automata
Theory of Automata
Lecturer: Sana Rehman
2 4. Finite Automaton
Example:
 Pieces are set up on a playing board.
 Dice are thrown and a number is generated at random.
 Depending on the number, the pieces on the board must be rearranged in a fashion completely
specified by the rules.
 The child has no options about changing the board.
 Everything is determined by the dice.
 Then some other child's turn to throw the dice and make his or her move, but this hardly matters,
since no skill or choice is involved.
 The one who win the game is dependent entirely on what sequence of numbers is generated by the
dice, not on who moves them.
3 Continued…
 All the possible positions of the pieces on the board are called the states.
 The game changes from one state to another in a fashion determined by the input of a certain
number.
 For each possible number there is one and only one resulting state.
 A possibility is allowed that after a number is entered the game is still in the same state as it was
before.
Final State
 After a certain number of rolls, the board arrives at a state that means a victory for one of the players
and the game is over.
 This state is called final state.
 More than one final states can be possible called halting, terminal or accepting states
4 Continued…
 This model is called finite automaton, “finite" because the number of possible states and number of
letters in the alphabet are both finite, and "automaton" because the change of states is totally
governed by the input
 "Automaton“ comes to us from the Greek, so its correct plural is "automata.“
 Finite Automaton is abbreviated as FA
5 Continued…
Definition
 A finite automaton is a collection of three things:
1. A finite set of states, one of which is designated as the initial state, called the start state, and some
(maybe none) of which are designated as final states.
2. An alphabet Σ of possible input letters, from which are formed strings, that are to be read one letter at
a time.
3. A finite set of transitions that tell for each state and for each letter of the input alphabet which state to
go to next.
6 Continued…
Mathematical Definition

Formal Specification of machine is


7 How It Works
 It works by being presented with an input string of letters that it reads letter by letter starting at the
leftmost letter.
 Beginning at the start state the letters determine a sequence of states.
 The sequence ends when the last input letter has been read.
8 Continued…
Example:
 The input alphabet has only the two letters a and b.
 There are only three states, x, y, and z.
 State x is the starting state and state z as the only final state.
 Let the following be the rules of transition:
1. From state x and input a go to state y.
2. From state x and input b go to state z.
3. From state y and input a go to state x.
4. From state y and input b go to state z.
5. From state z and any input stay at state z.
9 Continued…
Example:
 It fulfills all three requirements demanded above: states, alphabet, transitions
 So, it is finite automaton
 The set of all strings that do leave us in a final state is called the language defined by the finite
automaton.
10 Transition Table

 If an input string is made up of only the letter a repeated some number of times, then the action of the
FA will be to jump back and forth between state x and state y.
 No such word can ever be accepted.
 To get into state z, it is necessary for the string to have the letter b in it.
 As soon as a b is encountered in the input string, the FA jumps immediately to state z no matter what
state it was in before.
11 Transition Diagram / State Diagram/
Finite State Machine
 Graphical representation of transition table
 A state machine reads a series of inputs.
 When it reads an input, it will switch to a different state.
 Each state specifies which state to switch to, for a given input.
 Each state is represented by a small circle
 Two states are connected with arrows
 If a certain letter makes a state go back to itself, it is indicated by an arrow that returns to the same
circle-called a loop.
 The start state can be indicated by labeling it with the word "start" or by a minus sign,
 The final states can be indicated by labeling them with the word "final" or plus signs.
12 Continued…
13 Continued…
 Sometimes a start state is indicated by an arrow and a final state by drawing a box or another circle
around its circle.
14 Usage of State Machines
 The output of a state machine is its final state.
 It goes through all its processing, and then the final state is read, and then an action is taken.
 A state machine doesn’t do anything as it moves from state to state.
 It processes, and when it gets to the end, the state is read and something external triggers the desired
action (for example, dispensing a soda can).
15 Continued…
 Example:
 Input strings aaaabba and bbaabbbb.
16 Continued…
 Example:

 One edge from the state on the right back has been drawn into itself and given this loop the two
labels a and b, separated by a comma meaning that this is the path traveled if either letter is read.
(drawing repeated loops is avoided)
 The first letter of the input takes us to the right-hand state and, once there, we are trapped forever.
 It omits the possibility that the input is the null string Ʌ.
 If the input string is the null string, we are left back at the left-hand state, and we never get to the
final state.
17 Continued…
 By convention we shall say that Ʌ starts in the start state and then ends right there on all FA’s.
 The language accepted by this machine is the set of all strings except Ʌ
 This has the regular expression definitions
18 Continued…
 Example:
 One of the many FA's that accepts all words is:

 The sign ± means that the same state is both a start and a final state.
 There is only one state and no matter what happens we must stay there, the language for this machine
is:
19 Continued…
 Example:
 Build a finite automaton that accepts all the words in the language that is, all the strings that begin
with the letter a.
a
 Start at state x
 If the first letter b is read, machine go to a dead-end state y. (A "dead-end state“ is an informal way
of describing a state that no string can leave once it has entered.)
 If the first letter a is read, machine go to the dead-end state z, where z is a final state.
20 Continued…
How Language will be accepted by Machine
21

 To determine what language this machine will accept


 Trace the paths associated with some specific input strings.
 Let input the string ababa.
 Begin at the start state 1.
 The first letter is an a, so it takes to state 2. From there the next letter, b, takes us to state 3.
Continued…
22
 The next letter, a, then takes back to state 2.
 The fourth letter is a b and that takes us to state 3 again.
 The last letter is an a that returns us to state 2 where we end.
 State 2 is not a final state (no +), so this word is not accepted.
 The word babbb.
 As always, start in state 1.
 The first letter b takes us to state 3.
 An a then takes us to state 2. The third letter b takes us back to state 3.
 Now another b takes us to state 4.
 Once in state 4, we cannot get out no matter what the rest of the string is.
 Once in state 4 we must stay in state 4, and since that is the final state the string is accepted.
Continued…
23
 There are two ways to get to state 4 in this FA.
 One is from state 2, and the other is from state 3.
 The only way to get to state 2 is by reading the input letter a (either while .in state 1 or in state 3).
 So when we are in state 2 we know we have just. read an a.
 If we read another a immediately, we go straight to state 4.
 Similarly with state 3. To get to state 3 we need to read a b.
 Once in state 3, if we read another b immediately, we go to state 4; otherwise, we go to state 2.
 The words accepted by this machine are exactly those strings that have a double letter in them.
 This language, can also be defined by the regular expression
Types of Finite Automata
24
a. Deterministic Finite Automata (DFA)
 In a DFA, for an input character, the machine goes to one state only.
 A transition function is defined on every state for every input symbol.
 Also in DFA null (or ε) move is not allowed, i.e., DFA cannot change state without any input
character.
Continued…
25
Continued…
26
Non-Deterministic Finite Automata (NFA)
1. Null (or ε) move is allowed i.e., it can move forward without reading symbols.
2. Ability to transmit to any number of states for a particular input.
Implying that the machine can exist in more than one state at the same time
Continued…
27
Mathematically:
28 Continued…
Reading State Diagram
29

 The circles are “states” that the machine can be in.


 The arrows are the transitions.
 Initially if we are in state s and read an ‘a’, we’ll transition to state q.
 If you read a ‘b’, we’ll stay in state s.
 So if we start on s from left to right, we will read the ‘a’ and move to state q.
 Then, we’ll read ‘b’ and move back to state s.
 Another ‘b’ will keep us on s, followed by an ‘a’ — which moves us back to the q state.
30 Continued…

 If we end in state s, the sequence must end with a letter ‘b’.


 If we end in state q, the sequence ends with the letter ‘a’.
Reading State Diagram
31

 It has two paths to final states


 For states and six transitions
 Its Regular Expression is
TASK: Make transition table
Continued…
32
Example
33
Example
34
 A FSM (Finite State Machine) with a binary alphabet, which requires that the input
contains an even number of 0s.
Example
35

 This machine will accept all words with b as the third letter and reject all other words.
Example
36
 FA, one that accepts only the word baa.

 The language accepted by this FA is L ={baa}


Example
37

You might also like