You are on page 1of 28

TIC 2151 – Theory of

Computation

Lecture 1
Finite Automat I

TIC 2151 – Theory of Computation


11/24/20
15 1
Lecture 1 - Outline

 A first look at an application.


 Examples of Deterministic Finite Automaton (DFA).
 Other kinds of automata: finite state transducers,
automata with garbage collectors, automata with no
reaction on inputs.
 Non-deterministic finite automata (NFA).
 Non-deterministic finite automata with e-transition.

11/24/2015 2
What is Theory of computation?

 What is Theory of computation (TOC)?


 In theoretical computer science, the theory of
computation is the branch that deals with whether and
how efficiently problems can be solved on a model of
computation, using an algorithm.
 The field is divided into three major branches: automata
theory, computability theory and computational
complexity theory.

11/24/2015 3
Why study theory of computation?

 Pre-requisite for understanding, designing, and processing


formal languages. (Examples of formal languages are Java,
C++, HTML, XML, etc.
 Foundation for technologies used in real-world applications
such as natural language processing, handwriting recognition.
 So that you can understand which problems are computable,
and which are not.
 Abstract models of computation independent of
implementations.
 You need some theoretical foundation to develop technology.
 Improve your problem solving skills!

11/24/2015 4
A first look at an application

Consider the problem of designing a


“computer” that Controll an auto-door Front Pad Rear Pad
 Two states: OPEN, CLOSED.
 Events: Front, Rear, Both, Neither. door
Top view of an automatic door

There are four possible input conditions:


o "FRONT" (meaning that a person is standing on the pad in front of the
doorway).
o "REAR" (meaning that a person is standing on the pad to the rear of the
doorway).
o "BOTH" (meaning that people are standing on both pads).
o "NEITHER" (meaning that no one is standing on either pad).

11/24/2015 5
A first look at an application

Consider the problem of designing a


“computer” that Controll an auto-door Front Pad Rear Pad
 Two states: OPEN, CLOSED.
 Events: Front, Rear, Both, Neither door
Top view of an automatic door

The state diagram (for the controller)


Rear, Both
Front
Neither Front, Rear,
Both

CLOSED OPEN

Neither
11/24/2015 6
A first look at an application

Consider the problem of designing a


“computer” that Controll an auto-door Front Pad Rear Pad
 Two states: OPEN, CLOSED.
 Events: Front, Rear, Both, Neither. door
Top view of an automatic door

The state transition table


 First column: write the states here
 First row: write the events here (formally called symbols).

Neither Front Rear Both

CLOSED CLOSED OPEN CLOSED CLOSED

OPEN CLOSED OPEN OPEN OPEN

11/24/2015 7
Software for TCS3511

 There is a software that can facilitate your learning:


JFLAP (http://www.jflap.org)
 Demonstrations in the course will be using JFLAP.

11/24/2015 8
What is automata theory?

 In theoretical computer science, automata theory is the study of


abstract machines (or more appropriately, abstract 'mathematical'
machines or systems) and the computational problems that can be
solved using these machines. These abstract machines are called
automata. (singular : automaton)
Automata theory deals with the definitions and properties of
mathematical models of computation.
 These models play a role in several applied areas of computer
science. One model, called the finite automaton, is used in text
processing, compilers, and hardware design. Another model, called
the context-free grammar, is used in programming languages and
artificial intelligence.
 Finite automata are good models for computers with an extremely
limited amount of memory.
 This automaton (abstract machines) consists of
 states (represented in the figure by circles),
 transitions (represented by arrows).
11/24/2015 9
Your First Automaton
1. The state diagram of a finite automaton M1

2. The formal definition of the finite automaton

11/25/2015 TCS3511 10
Your First Automaton
1. The state diagram of a finite automaton M1

2. The formal description of the finite automaton M1


M1 = (Q, S, d, po, F)
with Q = {q1, q2, q3} d is given by the following table:
S = {0,1}
d: Q x S  Q
p0 = q1
F = {q2}
3. The accepted language
L(M) = {w | w contains at least one 1 and an even number of 0s
following the last 1}

If A is the set of all strings that machine M accepts, we say that A is the
language of machine M and write L(M) = A. We say that M recognizes or
accepts
11/25/2015 A. TCS3511 11
Your second Automaton

1. The state diagram of a finite automaton M2

2. The formal description of the finite automaton M2


M2 = (Q, S, d, po, F)
with Q = {q1, q2} d is described as
S = {0,1} d
d: Q x S  Q
p0 = q1
F = {q2}
3. The accepted language L = {w | w ends with a 1}

NOTE: the state diagram of M2 and the formal description of M2 contain


the same information. You can always go from one to the other.

12
Your Third Automaton

1. The state diagram of a finite automaton M3

2. The formal description of the finite automaton M3


M3 = (Q, S, d, po, F)

with Q = {q1, q2}


d is described as
S = {0,1}
d: Q x S  Q
p0 = q1
F = {q1}
3. The accepted language
L = {w | w is the empty string or ends in a 0}

Note: in M3 we only changed the accepting state of M2.


13
Your Fourth Automaton

1. The state diagram of a finite automaton M4

2. The formal description of the finite automaton


M4 = (Q, S, d, po, F)
with Q = {q,q0,q1,q2} d 0 1
S = {0,1} q q0 q
q0 q1 q
d: Q x S  Q
q1 q1 q2
p0 = q q2 q2 q2
F = {q2}

3. The accepted language


L (M4)= {w | w contains the string 001}

14
Your Fifth Automaton

1. The state diagram of a finite automaton M5

2. The formal description of the finite automaton


M5 = (Q, S, d, po, F)
with Q = {s,q1,q2,r1,r2} d a b
S = {a,b} s q1 r1
q1 q1 q2
d: Q x S  Q
q2 q1 q2
p0 = s
r1 r2 r1
F = {q1,r1} r2 r2 r1

3. The accepted language


L (M5) = {w | w starts and ends with the same symbol}
Note: More than one accepting state. 15
Your sixth Automaton

1. The state diagram of an finite automaton

M6 = (Q, S, d, po, F)
with Q = {q0,q1,q2}
S = {0,1,2}
d: Q x S  Q
p0 = q 0
F = {q0}

3. The accepted language


L(M6) = {w | the sum of the symbols in w is a multiple of 3 }

Describing a finite automaton by state diagram is not possible in some


cases. That may occur when the diagram would be too big to draw or if
the description depends on some unspecified parameter. In these cases,
we resort to a formal description to specify the machine. 16
Defining an accepting computation

 An automaton will accept an input string if:


 The automaton has entered an accepting state, AND
 The input string has been exhausted (i.e. completely processed).

 In other cases, the automaton will arrive at a rejecting


computation.

17
Defining an accepting computation

The formal definition of finite automata


 Let N = (Q, S, d, q0, F) be a DFA.
 Then N accepts w if we have
 w = y1y2…ym (The input word is a sequence of symbols from S)
 r0, r1, …, rm (a sequence of states from Q)

 Satisfying three conditions:


1. r0 = q0
2. ri+1  d(ri, yi+1), for i = 0,…, m-1,
3. rm  F (we say N accepts w).
 In other words
1. the machine starts in the start state
2. the machine goes from state to state according to the transition function
3. the machine accepts its input if it ends up in an accept state.
18
Deterministic finite automata (DFA)

The state diagram of a finite automaton

1 0,1
q1 q2 q3
0
0 1
Language? All words having first the 0s and at least one 1.
0
1 1
q1 q2 q3
1
0 0
Language? All words having an even number of 1’s.

So far in our discussion, every step of a computation follows in a


unique way from the preceding step we call this deterministic
computation. 19
NonDeterministic finite automata (NFA)

deterministic computation. So far in our discussion, every step of


a computation follows in a unique way from the preceding step.
When the machine is in a given state and reads the next input
symbol, we know what the next state will be—it is determined.

In a nondeterministic machine, several choices may exist for the


next state at any point. Nondeterminism is a generalization of
determinism, so every deterministic finite automaton is
automatically a nondeterministic finite automaton.

20
NonDeterministic finite automata (NFA)
1. The state diagram of a finite automaton

2. The formal definition of NFA

Every state of a DFA always has exactly one exiting transition arrow for
each symbol in the alphabet. The NFA shown in Figure above violates that
rule. Ex: State q1 has one exiting arrow for 0, but it has two for 1. q2 has
one arrow for 0, but it has none for 1. In an NFA, a state may have zero,
one, or many exiting arrows for each alphabet symbol. 21
NonDeterministic finite automata (NFA)

1. The state diagram of a finite automaton

2. The formal description of the finite automaton


d 0 1
A = (Q, S, d, po, F) q1 {q1} {q1,q2}
with Q = {q1,q2,q3,q4} q2 {q3} {q3}
q3 {q4} {q4}
S = {0,1}
q4  
d: Q x S  Pow(Q)
p0 = q1
F = {q4}

3. The accepted language


L = {w | w contains a 1 in the third position from the end} e.g., 000100

22
NonDeterministic finite automata (NFA)

1. The state diagram of a finite automaton

2. The formal description of the finite automaton


A = (Q, S, d, po, F)
with Q = {q1,q2} d 0 1
S = {0,1} q1 {q1,q2} {q2}
d: Q x S  Pow(Q) q2  {q1,q2}
p0 = q1
F = {q2}

3. The accepted language


L = {w | w does not Start with 10}

Nondeterministic automata are good for shorter descriptions, good for building an
automaton accepting or not accepting special cases.

23
(NFA) with e -transitions (e-NFA)

Why is it comfortable to use e -transitions?

The automaton accepts {0k | where k is multiple of 2 or 3}

(Remember that the superscript denotes repetition, not numerical exponentiation.) For
example, This NFA accepts the strings e, 00, 000, 0000, and 000000, … but not 0 or
00000.

NOTE: The above NFA has an input alphabet {0} consisting of a single symbol. An
alphabet containing only one symbol is called a unary alphabet. 24
DFA vs. NFA
 Important: the NFA is defined in the same way as the DFA but with
the following two exceptions:
o Multiple next state.
o e- transitions.

 Multiple next state. in a DFA there is exactly one start state and exactly
one transition out of every state for each symbol in Ʃ. In contrast to a DFA,
the next state is not necessarily uniquely determined by the current state and
input symbol in case of an NFA. In an NFA, a state may have zero, one, or
many (including e- transitions) exiting arrows for each alphabet symbol.

 e- transitions. In an e-transition, the state of the automata can be changed


and go to next state without consuming the next input. d(q, e) = {q1,q2….qk}
implying that with e-transition the next state could by any one of
{q1,q2….qk}
25
Why an NFA?
 Every NFA can be converted into an equivalent DFA; but sometimes that
DFA may have many more states.
 Furthermore, understanding the functioning of the NFA is much easier, as
you may see by examining the following figure for the DFA.
NFA and DFA that recognize the language A
A = {w | w contains a 1 in the third position from the end}

Two machines
are equivalent if
they recognize
the same
language
Finite automata and regular language RL
 Finite automata are good models for computers with an extremely
limited amount of memory.
 A machine may accept several strings, but it always recognizes only
one language. If the machine accepts no strings, it still recognizes
one language namely, the empty language q.
 language of machine M and write L(M) = A. We say that M
recognizes language A
 We say that M recognizes language A if A = {w | M accepts w}.
Learning Outcomes

You should be able to:


 Give a DFA/NFA for a given (Regular) language.
 Explain the differences between a DFA and NFA.
 Understand and describe the different kinds of
automata.

Next lecture: Are NFAs more powerful than DFAs???

28

You might also like