Automata Theory: Lecture 5 & 6

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 17

Automata Theory

Lecture 5 & 6
Lecture’s Objective:
To understand Finite Automata
Finite automata
• A simple theoretical model of a computer able to decide(yes/no) many
problems.

• States and actions/transitions

• Idea behind construction of an FA


• 1) Receives input one at a time.
• 2) Answer for the string has been read so far.
• 3) Assumes input ^ if has not read anything yet.
Finite Automata - Idea
H
I TC
SW

start off on
BATTERY

input: switch
bulb is on if and only if
output: light bulb there was an odd number of
actions: flip switch flips
states: on, off
Finite Automata - Idea 1
1 start off off
1

2 2 2 2
BATTERY
1
2
off on
1

inputs: switches 1 and 2


actions: 1 for “flip switch 1” bulb is on if and only if
actions: 2 for “flip switch 2” both switches were flipped
an odd number of times
states: on, off
Tricks to construct FA
1. Construct the successful path for smallest word(s) then complete missing edges
2. Label states all possibilities and then adjust edges appropriately. Make states final where want to accept
3. Tree style construction
• Examples:
Accepts just Null
Accept exactly one a
Accepts nothing
Accepts Everything
String of even and odd length
Starting with a
Ending with a
Containing a double letter
Containing a triple letter
Starting and ending with same letters (both versions)
Starting and ending with different letters
FA for some finite language
Even-Even
Ending in ab or ba
Finite automata – cont.
Finite automata – cont.
Finite automata – Tree style construction
FA – Formal Definition
A little about DFA’s application
Suppose we’re writing a compiler and in its lexical analyzer’s phase
want to decide whether a string encountered is identifier or not.

The steps are as


1. Write RegEx
2. Construct DFA (Recognizer)
3. Implement DFA
Question
How to implement DFA?
Transition Table – A way to implement DFA

State a b
 q0 q1 q0
q1 q2 q0
F q2 q2 q0

Can easily be implemented by a 2D array/Adjacency matrix


Exercises - Another angle
Exercise
L4 = {x Ɛ {0,1}* | x is divisible by 3}
Exercise
• You visit a super store, buy some products and pay the bill. Let suppose the shopkeeper
has to return you change of 4 rupees. There are three types of currency notes in your
country, 1 rupee, 2 rupees, and 5 rupees.

• You have to construct a DFA accepting all possible combinations of notes summing to 4
rupees.
 
• Modify the FA you constructed in previous part assuming the customer is little bit
dishonest and accepts the change if the shopkeeper mistakenly returns more than 4
rupees.
 
• Hint: The alphabet set would be as ∑ = {1, 2, 5}
Exercise
Enter a regexp that matches all the items in the first column (positive examples) but none of those in
the second (negative examples).

Suppose ∑ = {a to z, A to Z} all English languages lower and uppercase alphabets

Positive Negative

pit pt
spot Pot
spate peat
slap two part
respite

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy