Professional Documents
Culture Documents
and
Theory of Automata
Formal Languages and Theory of Automata
Chapter 1
Introduction
Definitions
• Symbol – An atomic unit, such as a digit, character, lower-case letter,
etc. Sometimes a word. [Formal language does not deal with the
“meaning” of the symbols.]
3
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
6
What is Formal Language ?
7
Formal Language Examples:
Σ = {0, 1}
L = {x | x is in Σ* and x contains an even number of 0’s}
Σ = {0, 1, 2,…, 9, .}
L = {x | x is in Σ* and x forms a finite length real number}
= {0, 1.5, 9.326,…}
8
Formal Language Examples:
Σ = {English words}
L = {x | x Σ* and x is a syntactically correct English sentence}
9
What is automata theory ?
10
A simple “computer”
H
W ITC
S
BATTERY
input: switch
output: light bulb
actions: flip switch
states: on, off
11
A simple “computer”
H
W ITC
S
input: switch
bulb is on if and only if there was
output: light bulb
an odd number of flips
actions: f for “flip switch”
states: on, off
12
Another “computer”
1
1 start off off
1
2 2 2 2
BATTERY
1
2
off on
1
13
A design problem
1 4
?
5
BATTERY
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?
14
A design problem
15
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:
16
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?
17
Some devices we will see
finite automata Devices with a finite amount of memory.
Used to model “small” computers.
19
Problems
20
Graphs and trees
Graphs
Definition: A graph (undirected graph) consists of:
a. A non-empty set v called the set of vertices,
b. A set E called the set of edges, and
c. A map Φ (phi) which assigns to every edge a unique unordered pair
of vertices
e1 e6
v1 v2 e1 = {v1, v2}
e2 e3 e5 e2 = {v1, v3}
…
v3 v4
e4 e6 = {v2, v2} (a self loop)
e1
v1 v2 e1 = (v1, v2)
e2 e3 e5 v1 : a predecessor of v2
v2 : a successor of v1
v3 v4
e4
Substrings of a string
A string obtained by removing a prefix or a suffix from a string is
called a substring of w.
Eg: if w=abc, then b is a substring of w.
Every prefix and suffix of string w is a substring of w, but not every
substring of w is a prefix or a suffix.
For every string w, both w and λ are prefixes, suffixes and
substrings of w.
L1 = {λ},
L2 = {0, 1, 01} over ∑
L3 = {an | n>= 0} over ∑ = {a}
L4={λ,0,00,000,…} is a language over alphabet ∑={0}
31
Example of a finite automaton
off on
• 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}
32
Deterministic finite automata
33
Deterministic finite automata
34
Example
0 1 0,1
q0 1 q1 0 q2
states
q1 q2 q1
For every transition rule d(qi,a)= qj, the graph
q2 q2 q2
has an edge (qi, qj) labeled a.
The vertex associated with q0 is called the initial
vertex, while those labeled with qf Î F are the
final vertices. 35
Language of a DFA
M: off on
36
Examples
0 0
1
q0 q1
1
0 1
1
q0 q1
0
0 1 0,1
q0 1 q1 0 q2
L = {010, 1} ( = {0, 1} )
• Answer
q0 1 q01 0 q010
0
q
1 q1
38
Examples
• Construct a DFA that accepts the language
L = {010, 1} ( = {0, 1} )
• Answer
q0 1 q01 0 q010
0
0 1
q 0, 1
1 q1 0, 1 qdie
0, 1
39
Examples
• Construct a DFA over alphabet {0, 1} that accepts all strings that end
in 101
40
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
41
Reading Assignment
• Mathematical Preliminaries
• sets,
• relations,
• functions,
• sequences,
• graphs,
• trees.
42