Top Banner
THEORY OF COMPUTATION Lecture One: Automata Theory 1 Er. Deepinder Kaur Automata Theory
63
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to fa  and dfa

THEORY OF COMPUTATION

Lecture One:

Automata Theory

1Er. Deepinder KaurAutomata Theory

Page 2: Introduction to fa  and dfa

Theory of Computation

In theoretical computer science and mathematics, the theory

of computation is the branch that deals with 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• computational complexity theory.

Er. Deepinder Kaur 2Automata Theory

Page 3: Introduction to fa  and dfa

Automata theory

• The word “Automata“ is the plural of “automaton" which simply means any machine.

• automata theory is the study of abstract machines and problems they are able to solve.

• Automata theory is closely related to formal language theory as the automata are often classified by the class of formal languages they are able to recognize.

Er. Deepinder KaurAutomata Theory 3

Page 4: Introduction to fa  and dfa

Abstract Machine

• An abstract machine, also called an abstract computer, is a theoretical model of a computer hardware or software system used in Automata theory.

Er. Deepinder KaurAutomata Theory 4

Page 5: Introduction to fa  and dfa

Applications of Automata• A variety of properties concerning the models, grammars, and

languages will be proven.

• These algorithms form the basis of tools for processing languages, e.g., parsers, compilers, assemblers, etc.

• Other algorithms will form the basis of tools that automatically construct language processors, e.g., yacc, lex, etc.– Note that our perspective will be similar to, yet different from a compiler

class.

• Additionally, some things will be proven to be non-computable, e.g., the enhanced compiler.

Automata Theory 5Er. Deepinder Kaur

Page 6: Introduction to fa  and dfa

Automaton

• An automaton is an abstract model of a digital computer

• It has a mechanism to read input (string over a given alphabet, e.g. strings of 0’s and 1’s on = {0,1}) written on an input file.

• A finite automaton has a set of states • Its control moves from state to state in response to

external “inputs”

Automata Theory 6Er. Deepinder Kaur

Page 7: Introduction to fa  and dfa

Automaton

• With every automaton, a transition function is associated which gives the next state in terms of the current state

• An automaton can be represented by a graph in which the vertices give the internal states and the edges transitions

• The labels on the edges show what happens (in terms of input and output) during the transitions

Automata Theory 7Er. Deepinder Kaur

Page 8: Introduction to fa  and dfa

Components of an automaton

• Input file : Contains strings of input symbols

• Storage unit: consists of an unlimited number of cells, each capable of holding a single symbol from an alphabet

• Control unit : can be in any one of a finite number of internal states and can change states in defined manner

Automata Theory 8Er. Deepinder Kaur

Page 9: Introduction to fa  and dfa

Some Terms used in automaton theory

• Alphabets-Everything in mathematics is based on symbols. This is also true for automata theory. Alphabets are defined as a finite set of symbols. An example of alphabet is a set of decimal numbers ∑={0,1,2,3,4,5,6,7,8,9}• Strings- A string is a finite sequence of symbols selected from some

alphabet If ∑ {a,b} is an alphabet then abab is string over alphabet ∑. A

string is generally denoted by w. The length of string is denoted by |w|

• Empty string is string with zero occurrence of symbols . This string is represented by є

Automata Theory 9Er. Deepinder Kaur

Page 10: Introduction to fa  and dfa

• The set of strings, including empty, over an alphabet ∑ is denoted by ∑*.

• ∑+ = ∑* -{є}• Languages-A set of strings which are chosen from some ∑*,

where ∑ is a particular alphabet, is called a language . If ∑ is an alphabet, and L subset of ∑*, then L is said to be language over alphabet ∑. For example the language of all strings consisting of n 0’s followed by n 1’s for some n>=0:

{є,01,0011,000111,-------}

Automata Theory 10Er. Deepinder Kaur

Page 11: Introduction to fa  and dfa

• Langauge in set forms- {w|some logical view about w} e.g {anbn|n>=1}

• Kleene closure- Given an alphabet, a language in which any string of letters from ∑ is a word, even the null string, is called closure of the alphabet . It is denoted by writing a star, after the name of alphabet as a superscript ∑*.

Automata Theory 11Er. Deepinder Kaur

Page 12: Introduction to fa  and dfa

Finite Automaton

• One of the powerful models of computation which are restricted model of actual computer is called finite automata. These machines are very similar to CPU of a computer .They are restricted model as they lack memory.

• Finite automation is called finite because number of possible states and number of letter in alphabet are both finite and automation because the change of state is totally governed by the input.

Automata Theory 12Er. Deepinder Kaur

Page 13: Introduction to fa  and dfa

2.2 Deterministic Finite Automata

– graphic model for a DFA

13Automata Theory Er. Deepinder Kaur

Page 14: Introduction to fa  and dfa

Main parts of pictorial representation of Finite machine

• Strings are fed into device by means of an input tape which is divided into square with each symbol in each square.

• Main part of machine is a black box which serve that what symbol is written at any position on input tape by means of a movable reading head

• P0,p1,p2,p3,p4 are the states in finite control system and x and y are input symbols.

• At regular intervals, the automation reads one symbol from input tape and then enters in a new state that depends only on current state and the symbol just read.

Automata Theory 14Er. Deepinder Kaur

Page 15: Introduction to fa  and dfa

Main parts of pictorial representation of Finite machine

• After reading an input symbol, reading head moves one square to the right on input tape so that on next move, it will read the symbol in next tape square. This process is repeated again and again

• Automation then indicates approval or disapproval• If it winds up in one of the final states, the input string is considered

to be accepted. The language accepted by the machine is the set of strings it accepts.

Automata Theory 15Er. Deepinder Kaur

Page 16: Introduction to fa  and dfa

DFA: Deterministic Finite Automaton

• An informal definition (formal version later):– A diagram with a finite number of states represented

by circles– An arrow points to one of the states, the unique start

state– Double circles mark any number of the states as

accepting states– For every state, for every symbol in , there is exactly

one arrow labeled with that symbol going to another state (or back to the same state)

Automata TheoryEr. Deepinder Kaur

Page 17: Introduction to fa  and dfa

Finite Automata FA• Its goal is to act as a recognizer for specific a

language/pattern.• Any problem can be presented in form of

decidable problem that can be answered by Yes/No.

• Hence FA (machine with limited memory) can solve any problem.

17Automata Theory Er. Deepinder Kaur

Page 18: Introduction to fa  and dfa

Deterministic Finite Automata DFAFA = “a 5-tuple “ (Q, Σ, , q0, F)

1. Q: {q0, q1, q2, …} is set of states.2. Σ: {a, b, …} set of alphabet.3. (delta): represents the set of transitions that FA can

take between its states. : Q x Σ→Q

Q x Σ to Q, this function: Takes a state and input symbol as arguments. Returns a single state. : Q x Σ→Q

4. q0 Q is the start state.5. F Q is the set of final/accepting states.

18

Automata Theory Er. Deepinder Kaur

Page 19: Introduction to fa  and dfa

Transition function : Q x Σ→QMaps from domain of (states, letters) to range

of states.

19

(q0, a)(q2, b)(q1, b)

q1

q2

q3

Automata Theory Er. Deepinder Kaur

Page 20: Introduction to fa  and dfa

Transition function • : Q x Σ→Q• Maps from domain of (states, letters) to range

of states.

20

(q0, a)(q2, b)(q1, b)

q1

q2

q3

Automata Theory Er. Deepinder Kaur

Page 21: Introduction to fa  and dfa

How does FA work?1. Starts from a start state.2. Loop

Reads a sequence of letters3. Until input string finishes4. If the current state is a final state then

Input string is accepted.5. Else

Input string is NOT accepted.• But how can FA be designed and represented?

21Automata Theory Er. Deepinder Kaur

Page 22: Introduction to fa  and dfa

Transition SystemFA = “a 5-tuple “ (Q, Σ, , q0, F)

1. Q: {q0, q1, q2, …} is set of states.2. Σ: {a, b, …} set of alphabet.3. (delta): represents the set of transitions that FA can

take between its states. : Q x Σ→Q

Q x Σ to Q, this function: Takes a state and input symbol as arguments. Returns a single state. : Q x Σ→Q

4. q0 Q is the start state.5. F Q is the set of final/accepting states.

22

Automata Theory Er. Deepinder Kaur

Page 23: Introduction to fa  and dfa

Transition System

Transition Diagrams Transition Tables

23Automata Theory Er. Deepinder Kaur

Page 24: Introduction to fa  and dfa

Transition Diagram Notations

• If any state q in Q is the starting state then it is represented by the circle with arrow as

• Nodes corresponding to accepting states are marked by a double circle

q

Automata Theory 24Er. Deepinder Kaur

Page 25: Introduction to fa  and dfa

Transition DiagramCan be represented by directed labeled graph/Transition tableVertex is a stateStates= nodes

Starting/Initial state denoted by circle and arrow/-Final state(s) denoted by two concentric circles/+Other states with circle

Transition function =directed arrows connecting states.

25

S1

S2b

a a,b

Automata Theory Er. Deepinder Kaur

Page 26: Introduction to fa  and dfa

Alternative Representation: Transition Table

26

0 1

A A BB A CC C C

Rows = states

Columns =input symbols

Final statesstarred

*

*Arrow forstart state

Automata Theory Er. Deepinder Kaur

Page 27: Introduction to fa  and dfa

Acceptability of a stringA string is accepted by a transition system if

• There exist a path from initial state to final state

• Path traversed is equal to w

27Automata Theory Er. Deepinder Kaur

Page 28: Introduction to fa  and dfa

Example1.1• Build an FA that accepts only aab

28

S1-

S3

aS2

a b+S4

a bS1 S2 ?

S2 S3 ?

S3 ? ?

S4 ? ?Automata Theory Er. Deepinder Kaur

Page 29: Introduction to fa  and dfa

Example withTransition Table

29

0 1

A C BB D AC A DD B C

*

Check for 110101

Automata Theory Er. Deepinder Kaur

Page 30: Introduction to fa  and dfa

Example withTransition Table

30

Solution:-

(A,110101)= (B,10101) (A,0101)

(C,101)

(D,01)

(B,1)A*Automata Theory Er. Deepinder Kaur

Page 31: Introduction to fa  and dfa

Automata Theory 31

Properties of transition function1. (q,λ)=q

• It comes back to same state

• It requires an input symbol to change the state of a system.

2. (q,aw)=((q,a),w)

(q,w,a)=((q,w),a)

Er. Deepinder Kaur

Page 32: Introduction to fa  and dfa

Facts in designing FA

First of all we have to analyze set of strings.

Make sure that every state is check for output state and for every input symbol from given set.

No state must have two different outputs for single input symbol

There must be one initial and atleast one final state in FA

32Automata Theory Er. Deepinder Kaur

Page 33: Introduction to fa  and dfa

Language of a DFA

• Automata of all kinds define languages.• If A is an automaton, L(A) is its language.• For a DFA A, L(A) is the set of strings

labeling paths from the start state to a final state.

• Formally: L(A) = the set of strings w such that δ(q0, w) is in F.

33Automata Theory Er. Deepinder Kaur

Page 34: Introduction to fa  and dfa

Language• A language is a set of strings. For example, {0, 1}, {all English words}, {0, 0, 0, ...} are

all languages.

Automata Theory 34Er. Deepinder Kaur

Page 35: Introduction to fa  and dfa

Example #8:

• Let Σ = {0, 1}. Give DFAs for {}, {ε}, Σ*, and Σ+.

For {}:

For Σ*: For Σ+:

Er. Deepinder Kaur

0/1

q0

0/1

q00/1

q0 q1

0/1

Automata Theory 35

Page 36: Introduction to fa  and dfa

Example: Design a FA that accepts set of strings such that every string ends in 00, over the alphabet

{0,1} i,e ∑={0, 1}

Inorder to design any FA, first try to fulfill the minimum condition.

Start 0 0 0

Being DFA, we must check every input symbol for output state from every state. So we have to decide output state at symbol 1 from q0,q1 and q2. Then it will be complete FA

q0 q1 q2

Automata Theory 36Er. Deepinder Kaur

Page 37: Introduction to fa  and dfa

• 1 0 0start 0

1 1

q0 q1 q2q2

Automata Theory 37Er. Deepinder Kaur

Page 38: Introduction to fa  and dfa

Ex 2 –

• Construct a DFA that accepts a’s and b’s and ‘aa’ must be substring

38Automata Theory Er. Deepinder Kaur

Page 39: Introduction to fa  and dfa

Example: String in a Language

39

Start

a20 1

a

Minimal condition : aa

Automata Theory Er. Deepinder Kaur

Page 40: Introduction to fa  and dfa

Example: String in a Language

40

Start

There may be aabbaa.bbbbaa,aa,aab,aabb,….

a20 1

ab

Automata Theory Er. Deepinder Kaur

Page 41: Introduction to fa  and dfa

Example: String in a Language

41

Start

a

b

A CBa

b a,b

.

Automata Theory Er. Deepinder Kaur

Page 42: Introduction to fa  and dfa

Ex : (0+1)*00(0+1)*

• Idea: Suppose the string x1x2 ···xn is on the tape. Then we check x1x2, x2x3, ..., xn-1xn in turn.• Step 1. Build a checker

0 0

Automata Theory 42Er. Deepinder Kaur

Page 43: Introduction to fa  and dfa

• Step 2. Find all edges by the following consideration:

Consider x1x2.• If x1=1, then we give up x1x2 and continue to

check x2x3. So, we have δ(q0, 1) = q0. • If x1x2 = 01, then we also give up x1x2 and

continue to check x2x3. So, δ(q1, 1) = δ(q0, 1) =q0.• If x1x2 = 00, then x1x2··· xn is accepted for any

x3···xn. So, δ(q2,0)=δ(q2,1)=q2.

Automata Theory 43Er. Deepinder Kaur

Page 44: Introduction to fa  and dfa

(0+1)*00(0+1)*

0 0

0

1

1

1

Automata Theory 44Er. Deepinder Kaur

Page 45: Introduction to fa  and dfa

Ex 1All words that start with “a” over the alphabet {a,b}

a(a+b)*

Automata Theory 45

1

2b

a 3

a,b

a,b3

Er. Deepinder Kaur

Page 46: Introduction to fa  and dfa

Ex3• All words that start with triple letter

(aaa+bbb)(a+b)*

Automata Theory 46Er. Deepinder Kaur

Page 47: Introduction to fa  and dfa

Ex3

Automata Theory 47

1-

2a 3

a,b

4b 5b

6+

b

a a

Er. Deepinder Kaur

Page 48: Introduction to fa  and dfa

Ex4• All words with even count of letters having “a” in an

even position from the start, where the first letter is letter number one.(a+b)a((a+b)a)*

Automata Theory 48Er. Deepinder Kaur

Page 49: Introduction to fa  and dfa

Ex4

Automata Theory 49

-

a,b

Er. Deepinder Kaur

Page 50: Introduction to fa  and dfa

EX5:Construct DFA to accept (0+1)*

0

1

Automata Theory 50Er. Deepinder Kaur

Page 51: Introduction to fa  and dfa

Ex 6:Construct DFA to accept 00(0+1)*

0 00

111

0 1

Automata Theory 51Er. Deepinder Kaur

Page 52: Introduction to fa  and dfa

(0+1)*(00+01)

0 0

1

1

1

0

01

Automata Theory 52Er. Deepinder Kaur

Page 53: Introduction to fa  and dfa

Construct a FA that accepts set of strings where the number of 0s in every string is multiple of 3 over alphabet ∑={0,1}

1 1 1 start 0 0

0 As 0 existence of 0 is also multiple of 3, we have to consider starting

state as the final state.

q1 q2q0

Automata Theory 53Er. Deepinder Kaur

Page 54: Introduction to fa  and dfa

Design FA which accepts set of strings containing exactly four 1s in every string over alphabet ∑={0,1}

1

q2q4q0 q1 q21 1

q31

0 0 00 0

q5

0/1

start

1

q5 is called the trap state or dead state. Dead states are those states which transit to themselves for all input symbols.

Automata Theory 54Er. Deepinder Kaur

Page 55: Introduction to fa  and dfa

Design a FA that accepts strings containing exactly one 1 over alphabet {0,1}. Also draw the transition table for the FA generated

q2q2q1

1

0 0

q30/1

1

start

q3 is the dead state

Automata Theory 55Er. Deepinder Kaur

Page 56: Introduction to fa  and dfa

Transition table for previous problem

δ/∑ 0 1

q1 q1 q2

*q2 q2 q3

q3 q3 q3

Non final state that transit in self loop for all inputs

Automata Theory 56Er. Deepinder Kaur

Page 57: Introduction to fa  and dfa

Design an FA that accepts the language

L={w ϵ (0,1)*/ second symbol of w is ‘0’ and fourth input is ‘1’}

q0 q3q1 q20 11/0

1

1/0

0

1/0

q50/1

startq4

Automata Theory 57Er. Deepinder Kaur

Page 58: Introduction to fa  and dfa

Design DFA for the language L={w ϵ (a,b)*/nb(w) mod 3 > 1}

As given in the language, this can be interpreted that number of b mod 3 has to be greater than 1 and there is no restriction on number of a’s. Thus it will accept string with 2 bs,5 bs, 8bs and so on.

q0 q1 q2

b b

a aa

b

start

Q={q0,q1,q2}F={q2}

Automata Theory 58Er. Deepinder Kaur

Page 59: Introduction to fa  and dfa

Design FA over alphabet ∑= {0,1} which accepts the set of strings either start with 01 or end with 01

q0 q1

q3

q4

q20 1

1/0

q5

1

0

1

0

1

00

1

start

Automata Theory 59Er. Deepinder Kaur

Page 60: Introduction to fa  and dfa

Example #4:

• Give a DFA M such that:

L(M) = {x | x is a string of 0’s and 1’s and |x| >= 2}

Er. Deepinder Kaur

q1q0 q20/1

0/1

0/1

Automata Theory 60

Page 61: Introduction to fa  and dfa

Example #5:

• Give a DFA M such that:

L(M) = {x | x is a string of (zero or more) a’s and b’s such that x does not contain the substring aa}

Er. Deepinder Kaur

q2q0

a

a/b

aq1

b

b

Automata Theory 61

Page 62: Introduction to fa  and dfa

Example #6:

• Give a DFA M such that:

L(M) = {x | x is a string of a’s, b’s and c’s such that x contains the substring aba}

Er. Deepinder Kaur

q2q0

a

a/b

bq1

b a

b

q3a

Automata Theory 62

Page 63: Introduction to fa  and dfa

DFA Practice

• Design a FA which accepts the only input 101 over input set {0,1}

• Strings that end in ab

• Strings that contain aba

• String start with 0 and ends with 1 over {0,1}

• Strings made up of letters in word ‘CHARIOT’ and recognize those strings that contain the word ‘CAT’ as a substring

Er. Deepinder Kaur 63Automata Theory