& Theory of computation
Why Toc’ ;
This Subject acts as a base For vasiety
OF aveas of computes engineering 0s
Compiler construction , Languoge Processing»
Operating system design and So Many others
Every engineering process has Some
mathematical , scientific base” Theory of
computation ' studies that:
Basic Concepts :
a) Symbol
_ Symbol is any abstract OF User defined entity |
TE Can be anything e-g. letter, digit or symbol
Vike 9,60, 2, y,2, O11, 2,3, t,-, #, Pt
anything
a) Alphabet CE):.
- Tt is Finite get of symbols
Oe i ee
Ye 94b0,$ 65
here D,Y ave Alphabet sets
We con detine Alphabet foo our language —
3) String Cor, Word ) -
A string over on lphabet Ets defined
as any ‘Finite Sequence of symbols fsom
Conventionally Steings are denoted by Smal’
case letkexs.
string] Wosd length = Number of symbols Fn
the wordFor ex. Ze i
_ then €, 4, b, ab, ba, aa, bb, Qaa....
all these are ‘strings 0° over alphabet set
=
_ “there Can be” infinite” _ Strings” over
On alphabet . Ee
_Oxefix of string is any number of ~
leading Symbols of the steing-
@-q. let ‘Xe abe is any string
then its prefixes are €,Q, ab,abc
—
Proper prefix > a,ab +e —¢
suffix of stxtiag is any number 5 7
trai li ng Sy mbols
for ex €, C, be, abc
Proper sulin 2 €,¢, be
Eis Cepsilon) is an ore seeing
with length O [E>
4) Kanguage : fe e
A language is defined as q set of
Strings oF Symbols From some one
alphabet
~ Chul set) £5€3 are also languages
* Set of all Strings over alphabet
is language denoted PY ZF
t 2 - Sat then |
- §€, aq, aad,---- % is langaage _
; _ii) “Let Ls JON} then —
Zt $€,0,', 00, WoL 10,000, U1, -~ =a
is language™
formal language:
') the languages we have define above
Are called as formal lang wa eS
it) Formal language refers to tbe Fact
that all the vules for the language are
explicitly Stated in terms of what strings
of Symbols Can occurs 1 and which are
the valid sentences
H) Tt is to the form of strings oF symbols —
»_N) Tk is not ke expression of rdeay
- - _ like Natural language, CO
_-Fintte State Machine oO
: Machine fs ‘basfeally a tool to Check if
GX Particular Stsing is From fhe given
Language Or Nok
Machine @n be built for @ Paztieulo + langueq
Basic machine.
Tt 1s the machine which wecognizes Qn
input Set Ioand produces an Output
set O,
Where Land 0 are Finite
pt Eesha Output
here we are not fnterested what ts
happening inside but only the output.
Therefore these type of machine can be
_ Niewed as a Punction which “maps Input
Set LT to the output set QO.
this is Called 5 machine Function Cmar)
MAR. TIO SnEx AML logical gates like AND, OR, ¢tc.
for AND gate _
z foo), (0,'), (6,0), cunt
> § 0,15
MAF Table a
Peatuses of Baste Machine —
i) Tt simply accepts in put Fakta Ord
Produces Out put
“Input ¢ Can be Combinational Sof TE
Can be called as Combinational Machine
ex. AND gate
ii) Et only, Performs table Took up Procedure
som MAF Table
m) It doesnt have any memory or
internal state.
— Tt may require large Size Eable
For @ particulas Eask which May Slow
down the machine.
Also that much gpace might not be
available each time.
— Suppose we want to create Basic
machine fos particulor langugge bo.
check whether the given String Ts Prom
giv language “Which is ToFioike and
Psoduce the output as yes of no
= Practically te is tmpossible to create
Sach table with Toffnite word Set a
“— Therefore, we have to Improvise the
toorkirg Pinite State Machines are fntrelacee|PINTITE STATE MACHINE
- It is the machine having inter mediate
Stages
- Which on veceival of Fnput chooses a
Posticulay Path from initial stage Eo
reach to Final stage to produce valid
Output
- Such machine having Rinite Totecnal
States is called a3 finite State machine
—_ONe ofthe simplest model ob computation
cincl has very less memory
:
Finite state machines
Finite Automata
- a
—PA with Oukpub Fh without outpe
LL |
= Gee
Moore Meloy pea NEA E-NEA
Machine Machine
DFA- Deterministic Morte Qubomatq
} S0O@
a ore States
_ 5 JQ is tnitiol
state
wt) 0 is final state
_—_— 7 iv) edges - Transit»
SUPPOSE we axe in State @) < IF T ge inpet |
then my state @ goest to state (B)e NC
a
labelling of iopet edges orf ia puds
Formal def” oF DFA ° =
5 tuples - (Q.Z,t0F 8) eee
Gz seb ob all states ee
Zz: Inputs —_
Jo = Tiitial stole a
+ * nal srote (set ob) we con Powe rs
nstion function that maps __ —t
S + Tso
Oxz=-G _ ee f
Por this example
+ 5 A.8.6 ape pay 4
3+ 40, 4 alc | 6 —~f
: 9, - =) BY, Oo A c
f+ $0} c fa lo] E
co. Qxz-Q_D ] ¥
Exam ple: =
Design @ DEA which Accepts set ob r
all stsings that stort with 6 5
L=$0,00,01,000 O10 ON -- ~~" e&
rr :
“ee 8 Eg- 00]
1 0-6-0
Q"—— eer eg — saeco
Stole
T trap state ox dead
oan e stake
a Initial State G-0-O-O —
— —— aes : Ne final
x a state*& Example 2
“construct DPA Phat accepl Set of all
ksings over [0,14 oF length 2
2+ 90,15 7
b+ $00, ol 11,104
: a +,
paar (A) 2! CO O46 om a
j
Trop state/
deod state
from State D no Way out 40 final
Skate
ey. 00 10.7 _
2DS@ inal | hts tia
Store stole
OolK
P22) LO O)e ded stake
@ Example 3
Constracl a DPA thot accep any strings _
Over 34,65 Hhat does nob contain -the
String Oabb
Z- 444
Try to design @ Simpler problem
Let Gs construct O DPA that Accepts all
skeings over 3.0,b3 that contains the
String Gabb in it Q ; SibEE
Blip the Statessmate the Final Stobe
_ Tato non Final state ; a
Make the non final states into Fraal | nA
shakes 22
= - a = =
&_ Example &
Design DPA that veads strings made
up of letters in the word “CHARIOT
and eG nAZes the Strings that
contain the Word CAT’ aS a
substring -
HAT ROT ae C AGH TSO;T R- :
a \h d 9,)—s((93) aa
Sy eo
HaRTOT
AHLOR
state Eransibion diog sary
‘Jo HART OF
>t [ht & bt bd he fe
Ht | Ge eo 4 Ge Go
be | 4 ee ee
4) [4s ts Gs ds bs he 4sNT Example 5°
Ny Construct OF 4 accepting the Following
“| __ language over the Olphabet $0,1%
y —_(@) Number of 1's ts mattiple of 3
_(b) Number of 1's is not muttiple
7 ob 3
— 7) -
309-08
“og
to
Saar
1 Jo
Transition dae 7. =
qi 14, Gy
For case Z np the States
BX ol
S0-5@) 9) = GREE?
Ss or | Gy
! tdlds Go -Non deterministic PA (NFA)
- A non determinist! © finite autoMaty—
can be Wn mutti le stokes at the | ip
- same time . ; _
NPA can guess abou ife sequen 1
_ Tk can be can be pene 3
4 state attes vedval "
so the move cannot 5& determ E
_ uniquely | oo
ppag
Oe a ea
Q 4. Je | ae yo 4 > pes.
4 qb on
Thus the Stsin ag BNolg” ae
by ven) ize is Accepted
e “An. NPA with” States l-& 5 and Fn)
__alphabet 4 ay byt has Follow :
___Eronsi fen m table 7
at
eee
hase oe aa,
ares a
Se
Af eg gp
4 of 455g
5 bog. >>
a) Ds row Q _ Eeansitien dvoa
b) Calcaloke Ss Caty— —
ee aac : 341,243, 0b 3Examp) ft: oe ae
convert the NPA given into its
equivalent DFA: : a
On Z
[oOo 7.
=F) =
ek 8+ lb 99.93
_ Lh £95 AMIS $05.
step 1.
Starting Stoters $4aF
O34, is 34.5. 7 oO |
L>4, is @ $9.8 144.5 4
}—fi 3
4
ae ;
step 2 A new subset 94% is generated.
OS is F405 :
th is 34.5_ Step 4.
4 New subset $4.,4,% is generated
“ O Successor of 4 4o i424
SCP4A3 03
~~ = $0460) UV § (4,0)
99.4645
| Successoy of 3 04,3
8 (444,01)
= $901) 0 § (42,1)
=P U4,
“Steps a
A nee subset 99444. 45 1S_generated
Successov of F
+ 8(44, 4,85 04
= $(4.,9)0 $74.0) 0 § (4,0)
*—S4ei,) 3—4,——4
= 40,4, 4,3
in
| Successox of Soa. 4 3
nae 6 ( 2% Se, fl | oe eee
$41) 0 $41) $a)
——+—$9,5 U > pigqrq3.
Eh
“Since now no new subset Is Generated
Psocess of subset generation stop §
°step 3: A new subset S4e04,% Fs
= Generated ~
O- “Successor of 3 904,% _
2S C8404,5,03 = 8(4.0% OE (9, 0% se
= 3930 — = $43
| - Successor of $455.3
. SIC Sa) 0a (4.1)
*~__c JU 34,,4.,%NY AS Fa was Final state of NFA
Qa\\ the states Contain aq_ a, should be
___token os Final stokes
final DFA transition table .
Ona
| er
| 343 [4% EL
—4404f | a5 240
_¢ A4ed§? 1940 9,4.5 —__405____
940 9,3-7 49 904,,4,5 140 F
4 | _@ pe
Example 220
Convert to a DPA the following NFA:
’ fo!
jor aad 303
ws
| qs3_ 6
S'] 355 35
1 479] aPa3 a | nn ao
2 $745 | GPar53 3PA5o _
3 4rd] SPawsté FAP y
4 P4s¢ 5 9P$ Lo
qParss § ppus5 7
FPgs75 TPS SR
§ P33 TPS98las
NFA with Epsilon
€ stands Fer a null symbol \
ANE transition allows transition one
_ Cor noi/p), the emply String
a This Implies that the Machine can mak,
A transition clthotct any i]/p
st Pormal Notation for an € -NFA
M=39,5,%o)F, 83
- GX {ZU 5GF5 > 28
a [es[sag] @ [4
Oe thy 6 $481
até $ | 5955
* E closure
E Closure oF state 4; is the set of —o—
states induding gf eohith
are reachable by @ move from 4;
Tt includes
— State 4;
— Set of States reachable From 43 on e-mrove,
- Set of States reachable From @yisti ing
a Stakes, in € € closure , Using eninouesaaeeea
and So on5) xe closuse ob Je + 4934 a 4.3
olay
7) @ Closure ob g > 94 924,5
_ Equivalence of @ NFA and NFA.
An NPA with © move can be |
Convested into an equivalent NFA
voithour € moves
et: Ae O12 aN ieee
GOS LS
Ci)
= = fae
TP there fs € Move betWeen any
too States 4 4%) then © reve
Can be removed as
0) Al) moves fens 45 should also
“Osiginate From gy -
For en. if Qe) oe
aeSO
o) rf 4; is a Fidal state then L
/ mate 7 08 a Pinal stake 7 b
qi Con tains Fi na
Tf € closuse ob
state then i! ts Cilso considered g
final State _______—
Example °
convert C-NFA to an NFA
—
— ° | —
23-36
Ca) NFA with EG move
Convest: EG NFA — DEA
Example: 7
consider the Followin a ena
Ea bo
PPR 993 Gq
$3 143 ey
Wd 993
¢) Compute | the a
- closure oF each
_ Skate
a states —e) closure a
(a —
tt __ 3P, P45
nnn Semone ay ee
(6) Convest given G-NFA to DPA.
Step C1). @ closure 6 initial state
Pts taken as a first Subsel
C closave CP): 973
Q Successor oF 7pZ . eC Closuve (6 CP,a) )
> © closase (1?)
4p
_b successor oF 4°3> closure Cte)
-¢ closure DH
AGS
successor oF tP3- C conve (580)
a 2 © closare eS)
ean oisa success oF of. $04 37
2 € closuse( i P30 o)
-e@ closure CEP-44) |
Fea osure £3 U ec closure $43
b Successox aE $P.43> @ closure ( 8( Fb) Us (35) )
= € closuse(s U $x3 ) =
Two new Subsets TP. 43 and Pay
are generated: worl Calcedote thd
Succes Sot +
= € closuse 4q3 U € closure oy}
PAF U_ GPG
LP. ys
C Successo¥
(2) f.4.+F
A Successor ob GPqxf -C* fone 9)
-€ closuse ( $P5 U $ethes)
2 € Closuve P_ UE dosure 4 U @ closuse ¥
iaimie feeno lrg ncmenS closuse(8(P.<) v $(4,0))
E closure (ar U¢)
E Closure fx3
GP5 UGPSS DIPS
5 Pg ts—_b_ successor ob GPav3. € closure
VT C SCP,b) HEC CB)
=—- aS lesure( $45 p gx5 UF
a 2€ € closure $43. aiencr -Closuve Gy3_ So
ere A) FP ¥F5
ame gape eves
Ce arn ot
{Pg 63 =
- . ¢
Closure tSTEENS) O §(C4,c) Us Cr.c))
2 € closwe (343 UO dV RP)
= @ closuve(r) U_ €-closure (a>)
> 2P403 U 8P3
2 GegrtMinimization of DPA:
State equivalence : When two states
_ gqiand 4; on same i/p yietds
identical O/P then two stetes Fi + 4
are said to be jeentical-
Fox ex.
for minimization of DPA
we MN geplace eqguivalert States by
“each Othe
Rules for replace ment:
4) woe can replace Non-final States by
TH eguivalent Nnon-final Stee, only,
ii) we con replace final slate by tts
equivalent Fraal skate only.
is) We cen not replace foitial’ state hyethes
Ww We Can not replace Non- Final stafe by -
final state
v) Replacing state A by Bo means
deleting entries re lated to ‘A? From —
table,
whereves woe Find symbol ‘A’ replace
thee Symbol by ©B7 -gegt| (PTT
“spai| Spans 4h
“ges| gras 1P8
_hP938| § e943 P.983 ]
spars] J P4753 1 P83
4Pas3| $P.4,55 4 P55
4 Ps3*| $[Link] 40.33
seplace State ¢P
) 4rsi b
meplace State P55 ae
PAS)
sar °
$0.44 TP :
4P9h | 3 P4 13 on
1.45] §tast- fPap
$Px3| §P 485 4P%
{P4SF IPH s>- FPos5
g P5319 Pas3
Py 5%.Equivalence of DEA
—Two foite automata M, and My are Said
+o be equivalent if they accept Same _
tanguage ee
—~ TE too DEAS are eqeivalent then —
On the application vo
(i) eithet both M] 4 M2 will be in final
State or -
Gi )Both Ml and M2 wii be 7
: Sete Simultaneously
nena ye
Testing equivalence ef +00 DFAS |
Equivalence of +00 DPAS Con be.
established by Constsucting a Combined
DPA for two DRA's M) < M2
-~— M)< M2 ill be equal if
Por every state
both Si «4; are non nal stake;
Example . -
Show cohether the Qutomoata My anc M2
__ fn given Fig. ate equiva eat or not
- i q -Constructton
tep 4-
amen Tay
EB (449 i):
— let us expand Lhtal
C5, 5607
= 2 Lat
8, (44.34), d) L8,C4,.
a
= <4.) er
od) 8,
db Combinecl DFA m3
Start stale ot my is 4,
Stost state af M tsa
let as Stavk totth combised stake
(4 wD
fey
ee (ag
E424 ——> (S
a (Id olde
: CaP
Step 2: State <4,4.7 fs Selected for
©X pansion
Sa Fai Fe7, ©) = C810) 62.0450)
, = C447 :
—_85((%4,2,d) = 6,(9,,4) $4 ted
- €459,9 - -
Step 3: State C4,,457 15 _ Selected For
expansion -
Os (S454, 0) * << (45:¢) ena
2 4a
2457
3 (U44,4,2,4) = 25, hd), 839, ,d)7
<4.
> <4, 4,9
step 428 » state 24, Gat is aclected For
_ expan si ODS5(I2:45 6) 265,40), bal
4 2 L44,)4,7 =
= at 2h) 42 28,4), AGA? Ss
44.9 -
Sto
<4 4u7_- both © Ge are Final
States
C ta4ay ~ both F945 are TP
fioa) states
La tery © both are Mon Final states
4,,4:7 — both are Non tinal states
* We Can Conclude that M4 M2 are
edaivalent:|— Rroite Qutomata vith Outputs
Meaty Machine,
CQie.a Sd, )
tohere
B+ Noite set ob skates
Zs Rinite Non emp
__ Set ot Up “alphabets
A+ Sethog Output alchabell
§ + Pransition anction |
7 @x —
A= Ousput function’?
ZxXQ.
Moore machine
(G,Z,A,8.0, 40)
Where
Y= Finite set ob stotes
Zz = Rinite non-empty
Set of Tp alphabets
J = Set ob Ofp alphabets
YUP String length :4
__OfP String lengtn 34
seer <7!)
BLYA)SB
o bab
TP string length » 4
O(p Steing length on
— nant
a
Construction of Mealy Maching —
Ex. | :
10100 > Olol |)
construck g mealy Machine that produces.
VWs complement of any binary i/p stringprints 6a! whenever +he SOguence ‘ol?
ts encountesed tn any i/p binary stain
SE r$ore A-F 963
Ex. 2) Construct a mealy machine that
_ey-3) Mealy | Machine |, where is Labs —o—
and the strings should end with either
‘ad or bb
aa Sy j
bb SIR] a/|
In XS
yo / | o/o
by
¢
ty bi
EX. 4) Construct a mealy Machine that
Bives 2'S complement of any binarys/p _
2's Complement = 15 complement + |
Ff lo 1 00 11100 Lis ye
Olotrt Oool] 0000
oan | + | +
oO! loo Ool1aod 000 |
after _|'st_one (1) from Ls pail bits
Qte veversedlOle
Cuprant .
siete yg, WP \ Oakput
|
A ~
= B
Present Next stake
Stat oO
| state [o/p | a
A A |[o |. 2 -
Se | ei 2
; Cons teuction oF Moose prochine
_ &% construct G mosge machine that
PHOES Sa? Whenever the sequence ‘Ol
ante in any foput tay
Stria
ESOT TAS abhtN
2) Construct a Moore Machine - That
COUMES fhe occaxences of +he gegquence
‘Abb? in any i/p sLaing overs $0,bF
T= Faby A -F0,1F
as aa Q —
—&g. a bb - . 7
Sere for the Following Mo Moose Machine
the T/p _alphobet is [+9465 aed the
O/p Alphabet fs A- Son :
Run the following ip sequence § ©
Frad tespectty ec oct puts
States | ab folp I) AaAbah
so | 4 % |o WHE-OLHD
4 4e 4g | 0 OOOO}
Ar | 45 te |) abt b
G2 | 44 94 | 0 b
e ga a. a | 0 es *“ b, Geb
eo 00
eae schgaHO 6)78 ‘eNcountere 4 in
“and then convest
Whenevey
aching that
the Sequence ‘oy?
| ifp bina sy String
Meals [ Moth
any
‘tbo
0 |e |>le!
P|
oe 2
et 45
Sanaa
4 b/0
fs
A OV;
W/O #
La
5/0
V0
|
mH |__|
3 S70
a)
|x
ea i\tuaqs |
ne
a
> Osa Q |
|
J ey 2) co) 2)
Ze
- a
|
wv
AIS ayo
=
oO |Convert given
_ tote | 0 |
Ge | % Ga
G1 Ys z Go
| Fa 1
43 | So Gy
ofp
Incr
Moore poaching fess
meoly
Zod
A> $e.1%
Next ° —
Go 4, | © | Go
% [45 | Tb 14 -
Qo do | dy
4s | eel eae eeConvert Mealy machine 40 Moore
tal)?
Ch tbo
@
i
i —S Moore Macldag
“Moore —> Meloy =) No- ob States were Same
Mealy ~3 Moore 7 No. ot Stokes increcwec(,
t Scan have max (x*Y) $ ghabos
J ‘
- states —O} p— - —
“~_} Convest given Mealy mach
ine Jo Moore .
b
Sy | 1
43
Yo
qo |
20
Yo