MELJUN P. CORTES,
MBA,MPA,BSCS,ACS

Automata theory
and formal languages

MELJUN CORTES
What is automata theory
• Automata theory is the study of abstract
computational devices
• Abstract devices are (simplifie...
A simple computer
H
TC
WI
S

BATTERY

input: switch
output: light bulb
actions: flip switch
states: on, off
A simple “computer”
H
TC
WI
S

f
BATTERY

start

on

off
f

input: switch
output: light bulb
actions: f for “flip switch”
...
Another “computer”
1
1

start

off

2

BATTERY

off

1
2

2

2

1

2
off

1

on

inputs: switches 1 and 2
actions: 1 for “...
A design problem
1

BATTERY

2
3

4

?

5

Can you design a circuit where the light is on if and
only if all the switches ...
A design problem
• Such devices are difficult to reason about, because
they can be designed in an infinite number of ways
...
These devices can model many things
• They can describe the operation of any “small
computer”, like the control component ...
Different kinds of automata
• This was only one example of a computational device,
and there are others
• We will look at ...
Some devices we will see
finite automata

Devices with a finite amount of memory.
Used to model “small” computers.

push-d...
Some highlights of the course
• Finite automata
– We will understand what kinds of things a device with finite
memory can ...
Some highlights of the course
• Turing Machines
– This is a general model of a computer, capturing anything
we could ever ...
Some highlights of the course
• Time-bounded Turing Machines
– Many problems are possible to solve on a computer in
princi...
Preliminaries of automata theory
• How do we formalize the question
Can device A solve problem B?
• First, we need a forma...
Problems
• Examples of problems we will consider
–
–
–
–

Given a word s, does it contain the subword “fool”?
Given a numb...
Alphabets and strings
• A common way to talk about words, number, pairs of
words, etc. is by representing them as strings
...
Strings
A string over alphabet Σ is a finite sequence
of symbols in Σ.
• The empty string will be denoted by ε
• Examples
...
Languages
A language is a set of strings over an alphabet.
• Languages can be used to describe problems with
“yes/no” answ...
Finite Automata
Example of a finite automaton
f
on

off
f

• There are states off and on, the automaton starts in
off and tries to reach t...
Deterministic finite automata
• A deterministic finite automaton (DFA) is a 5-tuple
(Q, Σ, δ, q0, F) where
– Q is a finite...
Example

q0

1
1

q1

alphabet Σ = {0, 1}
start state Q = {q0, q1, q2}
initial state q0
accepting states F = {q0, q1}

0,1...
Language of a DFA
The language of a DFA (Q, Σ, δ, q0, F) is the set of
all strings over Σ that, starting from q0 and
follo...
Examples
0

0
1

q0

q1

1
0

1
1

q0

0

0
q0

q1

1
1

q1

0,1
0

q2

What are the languages of these DFAs?
Examples
• Construct a DFA that accepts the language
L = {010, 1}

( Σ = {0, 1} )
Examples
• Construct a DFA that accepts the language
( Σ = {0, 1} )

L = {010, 1}

• Answer
0

q0

1
0

qε

0

q01

q010

...
Examples
• Construct a DFA over alphabet {0, 1} that accepts all
strings that end in 101
Examples
• Construct a DFA over alphabet {0, 1} that accepts all
strings that end in 101
• Hint: The DFA must “remember” t...
Examples
• Construct a DFA over alphabet {0, 1} that accepts all
strings that end in 101
• Sketch of answer:

0

0

q0

1
...
Upcoming SlideShare
Loading in …5
×

MELJUN CORTES Automata Theory (Automata1)

458 views

Published on

MELJUN CORTES Automata Theory (Automata1)

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
458
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
31
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

MELJUN CORTES Automata Theory (Automata1)

  1. 1. MELJUN P. CORTES, MBA,MPA,BSCS,ACS Automata theory and formal languages MELJUN CORTES
  2. 2. What is automata theory • Automata theory is the study of abstract computational devices • Abstract devices are (simplified) models of real computations • Computations happen everywhere: On your laptop, on your cell phone, in nature, … • Why do we need abstract models?
  3. 3. A simple computer H TC WI S BATTERY input: switch output: light bulb actions: flip switch states: on, off
  4. 4. A simple “computer” H TC WI S f BATTERY start on off f input: switch output: light bulb actions: f for “flip switch” states: on, off bulb is on if and only if there was an odd number of flips
  5. 5. Another “computer” 1 1 start off 2 BATTERY off 1 2 2 2 1 2 off 1 on inputs: switches 1 and 2 actions: 1 for “flip switch 1” actions: 2 for “flip switch 2” states: on, off bulb is on if and only if both switches were flipped an odd number of times
  6. 6. A design problem 1 BATTERY 2 3 4 ? 5 Can you design a circuit where the light is on if and only if all the switches were flipped exactly the same number of times?
  7. 7. A design problem • Such devices are difficult to reason about, because they can be designed in an infinite number of ways • By representing them as abstract computational devices, or automata, we will learn how to answer such questions
  8. 8. These devices can model many things • They can describe the operation of any “small computer”, like the control component of an alarm clock or a microwave • They are also used in lexical analyzers to recognize well formed expressions in programming languages: ab1 is a legal name of a variable in C 5u= is not
  9. 9. Different kinds of automata • This was only one example of a computational device, and there are others • We will look at different devices, and look at the following questions: – What can a given type of device compute, and what are its limitations? – Is one type of device more powerful than another?
  10. 10. Some devices we will see finite automata Devices with a finite amount of memory. Used to model “small” computers. push-down automata Devices with infinite memory that can be accessed in a restricted way. Used to model parsers, etc. Turing Machines Devices with infinite memory. Used to model any computer. time-bounded Turing Machines Infinite memory, but bounded running time. Used to model any computer program that runs in a “reasonable” amount of time.
  11. 11. Some highlights of the course • Finite automata – We will understand what kinds of things a device with finite memory can do, and what it cannot do – Introduce simulation: the ability of one device to “imitate” another device – Introduce nondeterminism: the ability of a device to make arbitrary choices • Push-down automata – These devices are related to grammars, which describe the structure of programming (and natural) languages
  12. 12. Some highlights of the course • Turing Machines – This is a general model of a computer, capturing anything we could ever hope to compute – Surprisingly, there are many things that we cannot compute, for example: Write a program that, given the code of another program in C, tells if this program ever outputs the word “hello” – It seems that you should be able to tell just by looking at the program, but it is impossible to do!
  13. 13. Some highlights of the course • Time-bounded Turing Machines – Many problems are possible to solve on a computer in principle, but take too much time in practice – Traveling salesman: Given a list of cities, find the shortest way to visit them and come back home Beijing Chengdu Xian Shanghai Guangzhou Hong Kong – Easy in principle: Try the cities in every possible order – Hard in practice: For 100 cities, this would take 100+ years even on the fastest computer!
  14. 14. Preliminaries of automata theory • How do we formalize the question Can device A solve problem B? • First, we need a formal way of describing the problems that we are interested in solving
  15. 15. Problems • Examples of problems we will consider – – – – Given a word s, does it contain the subword “fool”? Given a number n, is it divisible by 7? Given a pair of words s and t, are they the same? Given an expression with brackets, e.g. (()()), does every left bracket match with a subsequent right bracket? • All of these have “yes/no” answers. • There are other types of problems, that ask “Find this” or “How many of that” but we won’t look at those.
  16. 16. Alphabets and strings • A common way to talk about words, number, pairs of words, etc. is by representing them as strings • To define strings, we start with an alphabet An alphabet is a finite set of symbols. • Examples Σ1 = {a, b, c, d, …, z}: the set of letters in English Σ2 = {0, 1, …, 9}: the set of (base 10) digits Σ3 = {a, b, …, z, #}: the set of letters plus the special symbol # Σ4 = {(, )}: the set of open and closed brackets
  17. 17. Strings A string over alphabet Σ is a finite sequence of symbols in Σ. • The empty string will be denoted by ε • Examples abfbz is a string over Σ1 = {a, b, c, d, …, z} 9021 is a string over Σ2 = {0, 1, …, 9} ab#bc is a string over Σ3 = {a, b, …, z, #} ))()(() is a string over Σ4 = {(, )}
  18. 18. Languages A language is a set of strings over an alphabet. • Languages can be used to describe problems with “yes/no” answers, for example: The set of all strings over Σ1 that contain the substring “fool” L2 = The set of all strings over Σ2 that are divisible by 7 = {7, 14, 21, …} L3 = The set of all strings of the form s#s where s is any string over {a, b, …, z} L4 = The set of all strings over Σ4 where every ( can be matched with a subsequent ) L1 =
  19. 19. Finite Automata
  20. 20. Example of a finite automaton f on off f • There are states off and on, the automaton starts in off and tries to reach the “good state” on • What sequences of fs lead to the good state? • Answer: {f, fff, fffff, …} = {f n: n is odd} • This is an example of a deterministic finite automaton over alphabet {f}
  21. 21. Deterministic finite automata • A deterministic finite automaton (DFA) is a 5-tuple (Q, Σ, δ, q0, F) where – Q is a finite set of states – Σ is an alphabet – δ: Q × Σ → Q is a transition function – q0 ∈ Q is the initial state – F ⊆ Q is a set of accepting states (or final states). • In diagrams, the accepting states will be denoted by double loops
  22. 22. Example q0 1 1 q1 alphabet Σ = {0, 1} start state Q = {q0, q1, q2} initial state q0 accepting states F = {q0, q1} 0,1 0 q2 transition function δ: inputs states 0 q0 q1 q2 0 q0 q2 q2 1 q1 q1 q2
  23. 23. Language of a DFA The language of a DFA (Q, Σ, δ, q0, F) is the set of all strings over Σ that, starting from q0 and following the transitions as the string is read left to right, will reach some accepting state. f M: on off f • Language of M is {f, fff, fffff, …} = {f n: n is odd}
  24. 24. Examples 0 0 1 q0 q1 1 0 1 1 q0 0 0 q0 q1 1 1 q1 0,1 0 q2 What are the languages of these DFAs?
  25. 25. Examples • Construct a DFA that accepts the language L = {010, 1} ( Σ = {0, 1} )
  26. 26. Examples • Construct a DFA that accepts the language ( Σ = {0, 1} ) L = {010, 1} • Answer 0 q0 1 0 qε 0 q01 q010 1 0, 1 1 q1 0, 1 qdie 0, 1
  27. 27. Examples • Construct a DFA over alphabet {0, 1} that accepts all strings that end in 101
  28. 28. Examples • Construct a DFA over alphabet {0, 1} that accepts all strings that end in 101 • Hint: The DFA must “remember” the last 3 bits of the string it is reading
  29. 29. Examples • Construct a DFA over alphabet {0, 1} that accepts all strings that end in 101 • Sketch of answer: 0 0 q0 1 qε 1 0 q1 1 q00 1 q01 … q10 q11 1 … 1 1 q001 … 0 q000 q101 … 0 q111 1

×