You are on page 1of 36

Central Concepts of Automata

Theory

Ashim Dey
Lecturer, CSE, CUET

1
Slide courtesy: Prof. Dr. M. Moshiul Hoque, CSE, CUET
Reading Books
Introduction to Automata Theory,
Languages, and Computation: John E.
Hopcroft, Rajeev Motwani, Jeffrey D.
Ullman
Introduction to the Theory of
Computation-Michael Sipser
Elements of the Theory of
Computation-Harry R. Lewis, Christos H.
Papadimitriov 2
Alphabets
An alphabet is a finite, nonempty set of
symbols.
: alphabet
Common alphabets include:
1.  = {0, 1}, the binary alphabet
2.  = {a, b, …,z}, the set of all lower-
case letters
3. The set of all ASCII characters, or the
set of all printable ASCII characters 3
Strings
A string (word) is a finite sequence of
symbols chosen from some alphabet.
01101 is a string from the binary
alphabet  = {0, 1}
The string 111 is another string chosen
from this alphabet

4
The Empty String
The empty string is the string with zero
occurrences of symbols.

This string, denoted , is a string that


may be chosen from any alphabet
whatsoever.

5
Length of a String
It is often useful to classify strings by
their length: the number of positions for
symbols in the string.
Number of positions
|011| = 3 and ||=0

6
Powers of an Alphabet
If  is an alphabet, express the set of all
strings of a certain length from that alphabet
by using an exponential notation
k: set of strings of length k, each of whose
symbols is in 
Example: 0-{} length = 0.
={0, 1}  1= {0, 1}, 2= {00, 01, 10, 11}
3 = {000, 001, 010, 011, 100, 101, 110, 111}
: alphabet, members 0, 1 are symbols
 : a set of strings, members 0, 1 are strings
1 7
Powers of an Alphabet
The set of all strings over an alphabet  is
conventionally denoted *
{0, 1}* = {, 0, 1, 00, 01, 10, 11, 000,…}
Another way:
* = 0  1  2 …….
Sometimes, exclude empty string. Set of non-
empty strings from alphabet  is denoted +.
+ = 1  2  3  4  ………
* = +  {} 8
Concatenation of Strings
Let x & y be strings
Then xy denotes the concatenation of x & y
-that is the string formed by making a copy of
x and following it by a copy of y
If x is the string composed of i symbols x =
a1a2….ai and y is the string composed of j
symbols y = b1b2…..bj, then xy is the string
of length i+j: xy = a1a2…..aib1b2….bj
9
Concatenation of Strings
Example:
x = 01101, y = 110, xy=?
xy = 01101110, yx=?
yx = 11001101
For any string w, the equations w=w=w hold
: the identity for concatenations since when
concatenated with any string it yields the other
strings as a result
10
Languages
A set of strings all of which are chosen from
some *, [where  is a particular alphabet] is
called a language
If  is alphabet, L  * , then L is a language
over .
Common languages can be viewed as sets of
strings.
-English: collection of legal English words is a
set of strings over the alphabet that consists
of all the letters 11
Languages
C: the legal programs are a subset of the possible
strings that can be formed from the alphabet of
the language. This subset of the ASCII characters
Many other languages:
1. The language of all strings consisting of n 0’s
followed by n 1’s for some
n0: {, 01, 0011, 000111,….}
The set of strings of 0’s & 1’s with an equal
number of each:
{, 01, 10, 0011, 0101, 1001,….}
12
Languages
3. The set of binary numbers whose value is a prime:
{10, 11, 101, 111, 1011, …}
4. * is a language for any alphabet 
5.  the empty language, is a language over any
alphabet
6. {} the language consisting of only the empty string,
is also a language over any alphabet
-important constraint on what can be a language is that
all alphabets are finite

13
Problems
A problem is the question of deciding
whether a given string is a member of
some particular language
If  is an alphabet, & L is a language
over , problem L is:
 Given a string w is *, decide whether
or not w is in L

14
Set-Formers as a way to
define languages
It is common to describe a language using a
“set-former”:
{w | something about w}
 read “the set of words w such that
(whatever is said about w to the right of the
vertical bar)”
• {w | w consists of an equal number of 0’s & 1’s}
• {w | w is a binary integer that is prime
• {w | w is a syntactically correct C program} 15
Set-Formers as a way to
define languages
It is common to replace w by some expression
with parameters & describe the strings in the
language by stating conditions on the parameters.
Ex: first with parameter n, the second with i & j
1. {0n1n | n1}. Read “the set of 0 to the n 1 to the n such
that n is greater than or equal to 1”
-this language consists of strings {01, 0011,
000111,…}. As with alphabets, we can raise a
single symbol to a power n in order to represent n
copies of that symbol 16
Set-Formers as a way to
define languages
2. {0i1j | 0  i  j}. This language consists
of strings with some 0’s (possibly none)
followed by at least as many 1’s

17
Example: Recognizing Strings
Ending in “ing”
Not i or g

Not i Not i or n i

nothing Saw i Saw in Saw ing


i n g

Start i

18
Automata to Code
 In C/C++, make a piece of code for
each state. This code:
1. Reads the next input.
2. Decides on the next state.
3. Jumps to the beginning of the code for
that state.

19
Example: Automata to Code
2: /* i seen */
c = getNextInput();
if (c == ’n’) goto 3;
else if (c == ’i’) goto 2;
else goto 1;
3: /* ”in” seen */
. . .
20
Automata to Code – Thoughts
How would you do this in Java, which
has no goto?
You don’t really write code like this.
Rather, a code generator takes a
“regular expression” describing the
pattern(s) you are looking for.
 Example: .*ing works in grep.

21
Example: Protocol for Sending
Data

timeout
data in
Ready Sending

Start ack

22
Extended Example
 Thanks to Jay Misra for this example.
 On a distant planet, there are three
species, a, b, and c.
 Any two different species can mate. If
they do:
1. The participants die.
2. Two children of the third species are
born.
23
Strange Planet – (2)
Observation: the number of individuals
never changes.
The planet fails if at some point all
individuals are of the same species.
 Then, no more breeding can take place.
State = sequence of three integers –
the numbers of individuals of species a,
b, and c.
24
Strange Planet – Questions
In a given state, must the planet
eventually fail?
In a given state, is it possible for the
planet to fail, if the wrong breeding
choices are made?

25
Questions – (2)
These questions mirror real ones about
protocols.
 “Can the planet fail?” is like asking whether
a protocol can enter some undesired or
error state.
 “Must the planet fail” is like asking whether
a protocol is guaranteed to terminate.
• Here, “failure” is really the good condition of
termination.
26
Strange Planet – Transitions
An a-event occurs when individuals of
species b and c breed and are replaced
by two a’s.
Analogously: b-events and c-events.
Represent these by symbols a, b, and
c, respectively.

27
Strange Planet with 2 Individuals

200 020 002

a b c

011 101 110

Notice: all states are “must-fail” states.

28
Strange Planet with 3 Individuals
111
a c
b

300 030 003

a a

210 102 021 201 120 012

c b b c

Notice: four states are “must-fail” states.


The others are “can’t-fail” states.
State 111 has several transitions. 29
Strange Planet with 4 Individuals
a b c
211 400 121 040 112 004
c b a c b a
a b c
103 130 310 013 031 301
b c c a a b
022 202 220

Notice: states 400, etc. are must-fail states.


All other states are “might-fail” states.
30
Taking Advantage of Symmetry
The ability to fail depends only on the
set of numbers of the three species, not
on which species has which number.
Let’s represent states by the list of
counts, sorted by largest-first.
Only one transition symbol, x.

31
The Cases 2, 3, 4
x
110 111 211 400
x x x
x
200 300 310
x

210 220
x
Notice: for the case n = 4, there is nondeterminism : different
transitions are possible from 211 on the same input. 32
5 Individuals

500

410 221

320 311

Notice: 500 is a must-fail state; all others


are might-fail states.
33
6 Individuals
600

510 222

420 321

411 330

Notice: 600 is a must-fail state; 510, 420, and


321 are can’t-fail states; 411, 330, and 222 are
“might-fail” states. 34
7 Individuals
700 322

610 331

520 421

511 430

Notice: 700 is a must-fail state; All others


are might-fail states.
35
Questions for Thought
1. Without symmetry, how many states
are there with n individuals?
2. What if we use symmetry?
3. For n individuals, how do you tell
whether a state is “must-fail,” “might-
fail,” or “can’t-fail”?

36

You might also like