146
{ For Private Circulation-11 } TCS Notes Compiled By Prof.: GANESH SIR Notes SET-I Sem – V (COMP) CHOPRA ACADEMY Degree & Diploma Office Timing : 10.30a.m to 7.30p.m (Monday to Saturday) 10.30a.m to 3.30pm (Sunday) Bandra (W) Thane (W) Vashi 201 & 305, Off No 1 & 2Gnd Flr, 350 C- Wing Hill Road, Gangadhar Apt, Sector – 17 Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 Navi-Mumbai Call : 2655 9366. Call : 6579 4001. Call : 26421927 9967 843 854 9967 843 853 9967 843 852

CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

Embed Size (px)

Citation preview

Page 1: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

{ For Private Circulation-11 }

TCS Notes Compiled By Prof.:

GANESH SIR

Notes SET-I

Sem – V (COMP)

CHOPRA ACADEMY Degree & Diploma

Office Timing : 10.30a.m to 7.30p.m (Monday to Saturday) 10.30a.m to 3.30pm (Sunday)

Bandra (W) Thane (W) Vashi

201 & 305, Off No 1 & 2Gnd Flr, 350 C- Wing Hill Road, Gangadhar Apt, Sector – 17 Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 Navi-Mumbai

Call : 2655 9366. Call : 6579 4001. Call : 26421927 9967 843 854 9967 843 853 9967 843 852

Page 2: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

About GANESH SIR: Sir has completed his B.E(Comp) from Mumbai university, M.E (Comp-IT) from Pune University. He was working for Infosys and Oracle for 3 years. Currently he is pursuing his Ph.D in Theory of Computer Science (TCS). He has expertise in Model checking and Formal Method, which are the advance part of TCS.

Dear Students,

Welcome to the world of Theory in computation. For any doubts you can contact me at 83 84 82 05 75 between 9:00 pm to 1:00 am. I will also be posting important question and exam solution on my blog before the examination.

Page 3: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

Syllabus: Chapter No.

Chapter Name Contents

1 Finite Automata/Finite State Machine Alphabets, Strings and Languages, automata and Grammars. Finite Automata (FA) −its behaviour; DFA − Formal definition, simplified notations (state transition diagram, transition table), Language of a DFA. NFA−Formal de inition, Language of an NFA. An Application: Text Search, FA with epsilon−transitions, Eliminating epsilon−transitions, Eliminating epsilon−transitions, Equivalence of DFAs and NFAs. 2 Regular expressions (RE) Definition, FA and RE, RE to FA, FA to RE, algebraic laws for RE, applications of REs, Regular grammars and FA, FA for regular grammar, Regular grammar for FA. 3 Proving languages to be non−regular Pumping Lemma, and its applications. Some closure properties of Regular languages − Closure under Boolean operations, reversal homomorphism, inverse homomorphism, etc. Mhill−Nerode Theorem. 4 DFA Minimization Some decision properties of Regular languages − emptiness, finiteness, membership, equivalence of two DFAs or REs, Finite automata with output.

Page 4: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

5 Context−free Grammars (CFGs) Formal definition, sentential forms, leftmost and rightmost derivations, the language of a CFG. Derivation tree or Parse tree−Definition, Relationship between parse trees and derivations. Parsing and ambiguity, Applications of CFGs, Ambiguity in grammars and Languages. Simplification of CFGs − Removing useless symbols, epsilon−Productions, and unit productions, Normal forms −CNF and GNF. Proving that some languages are not context free −Pumping lemma for CFLs, applications. Some closure Properties of CFLs − Closure under union, concatenation, Kleene closure, substitution, Inverse homomorphism, reversal, intersection with regular set, etc. Some more decision properties of CFLs, Review of some undecidable CFL problems. 6 Pushdown Automata (PDA) Formal definition, behaviour and graphical notation, Instantaneous descriptions (Ids), The language of PDA (acceptance by final state and empty stack). Equivalence of acceptance by final state and empty stack, Equivalence of PDAs and CFGs, CFG to PDA, PDA to CFG. DPDAs − De inition, DPDAs and Regular Languages, DPDAs, Multistack DPDAs & NPDAs and CFLs. Languages of DPDAs, NPDAs, and ambiguous grammars. 7 Turing Machines TM Formal definition and behaviour, Transition diagrams, Language of a TM, TM as accepters deciding and generators. TM as a computer of integer functions, Design of TMs, Programming techniques for TMs − Storage in state, multiple tracks, subroutines, etc. Universal TMs, Variants of TMs − Multitape TMs,

Page 5: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

Nondeterministic TMs. TMs with semi−in inite tapes, Multistack machines, Simulating TM by computer, Simulating a Computer by a TM, Equivalence of the various variants with the basic model. Recursive and recursively enumerable languages, Properties of recursive and recursively enumerable languages, A language that is non-recursively enumerable (the diagonalization language). The universal language, Undecidability of the universal language, The Halting problem, Rice’s Theorem, Greibach Theorem, Post’s Correspondence Problem (PCP) − De inition, Undecidability of PCP. Context sensitive language and linear bounded automata. Chomsky hierarchy. 8 Intractable Problems The classes P and NP, an NP−complete problem, A Restricted Satisfiability problem, Additional NP−complete problems, Complements of languages in NP, Problems Solvable in polynomial space, A problem that is complete for PS, Language Classes based on randomization, The complexity of primality testing.  

 

 

 

 

 

Page 6: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

Subject Taken by Ganesh Sir: 

Semester  Subject  Batch 

SEM‐VI 

(Computer) 

SPCC (System 

Programming and 

Compiler Construction) 

Vacation + 

Regular 

ALL  OCAJP 1.7 (Oracle Certified 

Associate JAVA 

Programmer) 

Vacation + 

Regular 

ALL  OCPJP 1.7 (Oracle Certified 

Professional JAVA 

Programmer) 

Vacation + 

Regular 

 

 

Page 7: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

Chapter1

FiniteAutomata/FiniteStateMachine

HistoryofAutomata:

Automatatheoryisthestudyofabstractcomputingdevices,or"machines." Abstractmachine ‐Aprocedure for executing a set of instructions in some formal

language, possibly also taking in input data and producing output. Such abstractmachinesarenot intended tobeconstructedashardwarebutareused in thoughtexperimentsaboutcomputability.

Beforetherewerecomputers, inthe1930's,A.Turingstudiedanabstractmachinethathadallthecapabilitiesoftoday'scomputers,atleastasfarasinwhattheycouldcompute.

Turing's goal as to describe precisely the boundary between what a computingmachinecoulddoandwhatitcouldnotdo.

In the 1940's and 1950's, simpler kinds of machines, which we today call "finiteautomata,"werestudiedbyanumberofresearchers.

These automata, originally proposed to model brain function, turned out to beextremelyusefulforavarietyofotherpurposes.

Also in the late 1950's, the linguist N. Chomsky began the study of formal"grammars."

While not strictly machines, these grammars have close relationships to abstractautomata and serve today as the basis of some important software components,includingpartsofcompilers.

In 1969, S. Cook extended Turing's study of what could and what could not becomputed.

Page 8: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

Cook was able to Separate those problems that cannot be solved efficiently by

computerfromthoseproblemsthatcaninprinciplebesolved,butinpracticetakesomuch time that computers are useless for all but very small instances of theproblem.

Thelatterclassofproblemsiscalled"intractable,"or"NP‐hard."Itishighlyunlikelythateventheexponentialimprovementincomputingspeedthatcomputerhardwarehasbeenfollowing("Moore'sLaw")willhavesignificantimpactourabilitytosolvelargeinstancesofintractableproblems.

Anyofthesetheoreticaldevelopmentsbeardirectlyonwhatcomputerscientistsdotoday.

Someoftheconcepts,likefiniteautomataandcertainkindsofformalgrammars,are

usedinthedesignandconstructionofimportantkindsofsoftware.

Other concepts, like the Turingmachine, help us understandwhat we can expectfromoursoftware.

Especially,thetheoryofintractableproblemsletsusdeducewhetherwearelikelyto

beabletomeetaproblem"head‐on"andwriteaprogramtosolveit(becauseitisnot intheintractableclass),orwhetherwehavetofindsomewaytoworkaroundthe intractableproblem: findanapproximation,useaheuristic, oruse someothermethodtolimittheamountoftimetheprogramwillspendsolvingtheproblem.

WhyStudyAutomataTheory?Thereare several reasonswhy the studyof automataand complexity is an importantpartofthecoreofComputerScience.Introductionto FiniteAutomata:Definition:Afiniteautomatonhasasetofstates,andits"control''movesfromstatetostateinresponsetoexternal"inputs".

Page 9: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

Finite automata are a useful model for many important kinds of hardware and

software. We shall see some examples of how the concepts are used. For themoment,letusjustlistsomeofthemostimportantkinds:

1. Softwarefordesigningandcheckingthebehaviourofdigitalcircuits.

2. The"lexicalanalyzer”ofa typicalcompiler, that is, thecompilercomponent

thatbreakstheinputtextintologicalunits,suchasidentifiers,keywords,andpunctuation.

3. Softwareforscanninglargebodiesoftext,suchascollectionsofWebpages,tofindoccurrencesofwords,phrases,orotherpatterns.

4. Software for verifying systems of all types that have a finite number of

distinct states, such as communications protocols or protocols for secureexchangeofinformation.

Therearemanysystemsorcomponents,suchasthoseenumeratedabove,thatmaybeviewedasbeingatalltimesinoneofafinitenumberof"states."

Thepurposeofastateistoremembertherelevantportionofthesystem'shistory.

Sincethereareonlyafinitenumberofstates,theentirehistorygenerallycannotberemembered, so the system must be designed carefully, to remember what isimportantandforgetwhatisnot.

Theadvantageofhavingonlyafinitenumberofstatesisthatwecanimplementthe

systemwithafixedsetofresources.

Forexample,wecouldimplementitinhardwareasacircuit,orasasimpleformofprogramthatcanmakedecisionslookingonlyata limitedamountofdataorusingthepositioninthecodeitselftomakethedecision.

Example1:Perhapsthesimplestnontrivialfiniteautomatonisanon/offswitch.Thedevicerememberswhetheritisinthe"on"stateorthe"off"state,anditallowstheusertopressabuttonwhoseeffectisdifferent,dependingonthestateoftheswitch.Thatis,iftheswitchisintheoffstate,thenpressingthebuttonchangesittotheon

Page 10: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

 

statoffs

The

Asf

havrepPuswhistat

One

placthe

It is

EntseqFig.opewe

Exathanlexi

CHndra:986

CHndra:986

te,andifthstate.

efinite‐auto

forallfinitvenamedthresentextesh,whichricheverstate.

eofthestacedinitiallystartstate

softennectering oneuenceisgo.asacceptierate.Itischavenotm

ample2:Sonanon/officalanalyze

HOP67 843 85

HO67 843 85 F

heswitchis

Figure:A

omatonmo

teautomatahestatesonernalinflueepresentsaatethesyst

ates isdesy.Inourexbythewor

cessary toof these soodinsomng,becauseconventionmadeanysu

ometimes,wfchoice.Figer.

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

sintheons

finiteautom

odelforthe

a,thestatenandoff.Aencesonthauserpushtemisin,w

signatedthxample,therdStartand

indicateonstates after

meway.Foreinthatstaltodesignuchdesigna

whatisremgure,show

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

state,then

Push

Push

matonmode

eswitchiss

esarereprArcsbetwehesystem.HhingthebuwhenthePu

e"start stestartstatdanarrow

neormorer a sequenrinstance,wtate,thedenateaccepationinFig

memberedwsanotherf

CAD843 853 @act Ganes

ACA843 853 @act Ganes

pressingth

h

h

elinganon/

showninF

resentedbyeenstatesaHere,bothutton.Theushinputis

tate," thesteisoff,anwleadingto

estatesasnce of inpwecouldhevicebeingtingstatesg.

byastatefiniteautom

DEM@Vashi :9sh Sir@83

ADE@Vashi :9sh Sir@83

hesamebu

/offswitch

ig.

ycircles;inarelabeledarcsarelaintentofthsreceivedi

state inwdweconvethatstate.

"final"oruts indicathaveregardgcontrolledbyadoub

canbemumatonthat

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

uttonturns

nthisexamby"inputsabeledbythhetwoarcitgoestoth

whichthesyentionally.

"acceptingtes that thdedthestatdbytheswblecircle,a

uchmorectcouldbep

3 852 05 75

Y 3 852 05 75

ittothe

mple,we,"whichheinputsisthatheother

ystemisindicate

" states.he inputteonin

witchwillalthough

complexpartofa

Page 11: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

 

Theeachsof

Thestri

InF

tolproinpu

Thethestat

Sinccon

Auto

Autinth

1. Whpro

CHndra:986

CHndra:986

ejobofthishofwhichfar.ese positiong(i.e.,not

F

Fig,thefiveetters.Wegramthatuttothea

estartstatnextlettertenamedtceitisthensiderthat

omata

tomataareheintroduc

hat can ablemsthat

HOP67 843 85

HO67 843 85 F

sautomatorepresents

ons correspthingofthe

igure 1.2: A

estatesareemayimagtitiscomputomaton.

tecorresporofthentothenisente

jobofthisstatethel

aandC

essentialfctiontothe

computertcanbesol

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

nistorecsadifferen

pond to thewordhas

Afinite autom

enamedbyginethatthpilingatat

ondstotheothestateeredwhen

sautomatooneaccept

Comple

forthestudechapter,t

r do at alvedbycom

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

ognizethentpositioni

he prefixesbeenseen

matonmod

ytheprefixhelexicalatime,andth

eemptystthatcorretheinput

ontorecogntingstate.

exity:

dyofthelitherearetw

ll? This stmputerare

CAD843 853 @act Ganes

ACA843 853 @act Ganes

keywordtintheword

s of thewosofar)tot

delingrecogn

xofthenseanalyzerexhenextcha

ring,andeespondstohasspelled

nizewhent

imitsofcomwoimporta

tudy is cacalled"dec

DEM@Vashi :9sh Sir@83

ADE@Vashi :9sh Sir@83

then.Itthusdthenthat

ord, ranginthecomple

nitionofthe

eensofar.Ixaminesonaractertob

eachstatehthenext‐ldtheword

thenhasbe

mputation.antissues:

alled "decidcidable."

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

sneedsfivthasbeen

ng from theeteword.

en

Inputscorrnecharactebeexamine

hasatranslargerpredthen.

eenseen,w

.Asweme

dability," a

3 852 05 75

Y 3 852 05 75

vestates,reached

e empty

responderoftheedisthe

sitiononfix.The

wecould

entioned

and the

Page 12: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

2. Whatcanacomputerdoefficiently?Thisstudy is called "intractability,"and theproblems that canbe solvedby a computerusingnomore time than some slowlygrowing function of the size of the input are called "tractable." Often, we take allpolynomial functionstobe"slowlygrowing,"while functionsthatgrowfaster thananypolynomialaredeemedtogrowtoofast.

TheCentralConceptsofAutomataTheory

Inthissectionweshallintroducethemostimportantdefinitionsoftermsthatpervadethe theory of automata. These concepts include the "alphabet" (a set of symbols),"strings"(alistofsymbolsfromanalphabet),and"language"(asetofstringsfromthesamealphabet).

1. Alphabets

Analphabet is a finite, nonempty set of symbols. Conventionally, we use thesymbol ∑ foran alphabet.Commonalphabetsinclude:

a. ∑={0,1},thebinaryalphabet.b. ∑={a,b,...,z}, theset ofall lower‐caseletters.c. The set ofall ASCIIcharacters or theset ofallprintableASCIIcharacters.

2. Strings

A string (or sometimes word) is a finite sequence of symbols chosen from somealphabet.Forexample,01101isastringfromthebinaryalphabet∑={0,1}.

Thestring111isanotherstringchosenfromthisalphabet.

3. TheEmptyString:

Page 13: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

Theemptystringisthestringwithzerooccurrencesofsymbols.Thisstring,denotedεisastringthatmaybechosenfromanyalphabetwhatsoever.

4. LengthofaString

Itisoftenusefultoclassifystringsbytheirlength,thatis,thenumberofpositionsforsymbolsinthestring.

For instance,01101has length5. It is common to say that the length of astring is"the numberofsymbols" inthestring; thisstatementiscolloquiallyacceptedbutnotstrictlycorrect.

Thus,therearconlytwosymbols,0and1,inthestring01101,buttherearefivepositionsforsymbols,anditslengthis5.

However,youshouldgenerallyexpectthat"thenumberofsymbols"canbeusedwhen"numberofpositions"ismeant.

Thestandardnotationforthelengthofastringwislwl.Forexample,

|011|=3and|ε|=0.

5. PowersofanAlphabet

IfΣisanalphabet,wecanexpressthesetofallstringsofacertainlengthfromthat alphabet by using an exponential notation. We define Σk to be the set ofstringsoflengthk,eachofwhosesymbolsisinE.

Example:NotethatΣ0={ε},regardlessofwhatalphabetΣis.Thatis,εistheonlystringwhoselengthis0.

If Σ={0,1},thenΣ1={0,1}, Σ2={00,01,10,11},Σ3={000,001,010,011,100,101,110,111}and soon.

NotethatthereisaslightconfusionbetweenΣandΣ1.Theformerisanalphabet;itsmembers0and1aresymbols.Thelatterisasetofstrings;itsmembersarethestrings0and1,eachofwhichisoflength1.

Page 14: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

 

6. Con

Lang

A salph

CHndra:986

CHndra:986

The set ofinstance,{

Sometimesof nonempequivalencΣ+=Σ1∪ΣΣ*=Σ+U{ε

ncatenatio

LetxandthestringMoreprecstringcomxy=a1a2…Example: 11001101Foranystrconcatenatstringasaaddedtoa

guages:set of strinhabet,isca

HOP67 843 85

HO67 843 85 F

f all string0,1}*={ε,

s,wewishpty stringscesare:Σ2∪Σ3…ε}

onofString

ybestringformedbyisely,ifxis

mposedofj…aib1b2…bLet x =.ringw,thetion, sincearesult (aanynumbe

:ngs all of walledalangu

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

gs over an0,1,00,01

toexcludes from alp

gs

gs.Thenymakingasthestringsymbolsybj.01101 an

eequationswhen con

analogouslyrxandyie

which areuage.

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

alphabet1,10,11,00

etheemptyphabet Σ is

xydenotesacopyofxagcomposed=b1b2…bj

d y = 11

sεw=wεncatenatedytotheweldsxasar

chosen fr

CAD843 853 @act Ganes

ACA843 853 @act Ganes

Σ is conve00,...}.Puta

ystringfros denoted

stheconcandfollowdofisymbj,thenxyi

0. Then

=whold.d with anyway0,theiresult).

rom some

DEM@Vashi :9sh Sir@83

ADE@Vashi :9sh Sir@83

entionally anotherwa

mtheseto Σ+. Thus,

catenationwingitbyabolsx=a1aisthestrin

xy = 011

Thatis,εisy string itidentityfo

Σ*, where

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

denoted ay,

ofstrings., two appr

ofxandycopyofy.a2…aiandngoflength

101110 an

stheidentt yields thoraddition

Σ is a pa

3 852 05 75

Y 3 852 05 75

Σ*. For

Thesetropriate

,thatis,

yisthehi+jand

nd yx =

tityfor·he other,canbe

articular

Page 15: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

IfΣisanalphabet,andL⊆Σ*,thenLisalanguageoverΣ. NoticethatalanguageoverΣneednotincludestringswithallthesymbolsofΣ,so

oncewehaveestablishedthatLisalanguageoverΣ,wealsoknowitisalanguageoveranyalphabetthatisasupersetofΣ.

Thechoiceoftheterm"language"mayseemstrange.However,commonlanguages

canbeviewedassetsofstrings. AnexampleisEnglish,wherethecollectionoflegalEnglishwordsisasetofstrings

overthealphabetthatconsistsofalltheletters. Another example is C, or any other programming language, where the legal

programsareasubsetofthepossiblestringsthatcanbeformedfromthealphabetof the language. This alphabet is a subset of the ASCII characters. The exactalphabetmaydifferslightlyamongdifferentprogramminglanguages,butgenerallyincludes the upper‐ and lower‐case letters, the digits, punctuation, andmathematicalsymbols.

However,therearealsomanyotherlanguagesthatappearwhenwestudyautomata.

Someareabstractexamples,suchas:1. Thelanguageofallstringsconsistingofn0'sfollowedbyn1's,forsomen≥0

L={ε,01,0011,000111,...}.2. Thesetofstringsof0'sand1'swithanequalnumberofeach:

L={ε,01,10,0011,0101,1001,...}3. Thesetofbinarynumberswhosevalueisaprime:

L={10,11,101,111,1011,..}4. L*isalanguageforanyalphabetΣ.5. ∅,theemptylanguage,isalanguageoveranyalphabet.6. {ε},thelanguageconsistingofonlytheemptystring,isalsoalanguageover

anyalphabet.Noticethat∅≠{ε};theformerhasnostrings andthelatterhasonestring.

Theonly important constraint onwhat canbe a language is that all alphabets are

finite. Thus languages, although they can have an infinite number of strings, arerestrictedtoconsistofstringsdrawnfromonefixed,finitealphabet.

Page 16: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

Set‐FormersasaWaytoDefineLanguages Itiscommontodescribealanguageusinga"set‐former":

{ωIsomethingaboutω}

Thisexpressionisread"thesetofwordsωsuchthat(whateverissaidaboutωtotherightoftheverticalbar)."Examplesare:1.{ωIωconsistsofanequalnumberof0'sand1's}.2.{ωIωisabinaryintegerthatisprime}.3.{ωIωisasyntacticallycorrectCprogram}.

Itisalsocommontoreplaceωbysomeexpressionwithparametersanddescribethestrings in the language by stating conditions on the parameters. Here are someexamples;thefirstwithparametern,thesecondwithparametersIandj:1.{0n1nln≥1}.Read"thesetof0tothen1tothensuchthatnisgreaterthanorequalto1,"thislanguageconsistsofthestrings{01,0011,000111,...}.2. {0i1j I0≤ i≤ j}. This languageconsistsofstringswithsome0's(possiblynone)followedbyatleastasmany1's.

Problems:

Inautomatatheory,aproblemisthequestionofdecidingwhetheragivenstringisamemberofsomeparticularlanguage.

Itturnsout,asweshallsee,thatanythingwemorecolloquiallycalla"problem"canbeexpressedasmembershipinalanguage.Moreprecisely,ifΣisanalphabet,andLisalanguageoverΣ,thentheproblemLis:

GivenastringωinΣ*,decidewhetherornotωisinL.

Page 17: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

 

Desi

Mod(FSMTheMo

1. Inp2. Rea3. Fin

1. Inp

CHndra:986

CHndra:986

ignstep

del ofM):odelconsist

putTapeadingHeaditeControl

putTape:a. The in

symbol

b. Theenendma

HOP67 843 85

HO67 843 85 F

psforF

a Finit

tsofthree

d

put tape ilfromthei

ndsquareorker$atth

Block D

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

FiniteA

te Aut

mainparts

s dividedinputalpha

of the tapeherightend

Diagram of Fi

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

Automa

tomata

s,asfollows

into squarabet∑.

contain thd.

nite State Ma

CAD843 853 @act Ganes

ACA843 853 @act Ganes

ata:Ref

/ Finit

s:

res, each s

heendmark

achine

DEM@Vashi :9sh Sir@83

ADE@Vashi :9sh Sir@83

ferclas

te Stat

square con

ker₵at th

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

ssnotes

te Mac

ntaining th

he leftend

3 852 05 75

Y 3 852 05 75

s.

chine

he input

andthe

Page 18: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

c. Theabsenceof endmarkers indicates that the tape isof infinite length.Theleft to right sequence of symbol between the two endmarkers is the inputstringtobeprocessed.

2. ReadingHead:a. Theheadexaminesonlyonesquareatatimeandcanmoveonesquareeither

toleftortotheright.

b. We restrict themovement of the Reading head only to the right side. TheheadreadtheinputdatafromtheinputtapeandgiveittotheFiniteControl.

3. FiniteControl:a. FiniteControlhastheactuallogicofthemodel.

b. TheinputtothefinitecontrolwillusuallybethesymbolundertheReading

Head,say‘∑i’andthepresentstateofthemachinesay‘Qi’thenthenextstateofthemachinewillbegivenbyδ(Qi,∑i)Qj.

OperationofFiniteAutomata/FiniteStateMachineisgivenbelow:

1. Inputstringis fedtothemachinethroughatape.Tapeisdividedintosquaresandeachsquarecontainsaninputsymbol.

2. ThemainmachineisshownasaboxcalledastheFiniteControl.Thefinitecontrolhasthemathematicallogicofthemodel.

3. Initially the machine is in the starting state (q0). Reading head is placed at theleftmostsquareofthetape.

4. Atregularintervals,themachinereadsonesymbolfromthetapeandthenentersanew state. Transition to a state depends only on the current state and the inputsymbol.

Page 19: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

δ(Qi,∑i)QjMachinetransitsfromQitoQjoninput∑i.

5. Afterreadinganinputsymbol,thereadingheadmovesrighttothenextsquare.6. Thisprocessisrepeatedagainandagain,i.e.

a. Asymbolisread.b. Stateofthemachine(finitecontrol)changes.c. Readingheadmovestotheright.

7. Eventually,thereadingheadreachestheendoftheinputstring.Thelastcellintheinputtapeisrepresentedby$.

8. Now,theautomatonhastosay‘yes’or‘no’.Ifthemachineendsupinoneofasetoffinialstates(q1)thentheansweris‘yes’otherwisetheansweris‘no’.

TypesofFiniteAutomata: Aswasmentionedearlier,afiniteautomatonhasasetofstates,andits"control''

movesfromstatetostateinresponsetoexternal"inputs."

One of the crucial distinctions among classes of finite automata is whether thatcontrolis"deterministic,"meaningthattheautomatoncannotbeinmorethanonestate at anyone time, or "nondeterministic,"meaning that it maybe in severalstatesatonce.

TypesofFiniteAutomata:1. DeterministicFiniteAutomata(DFA)2. Non‐DeterministicFiniteAutomata(NFA)

DeterministicFiniteAutomata Theterm"deterministic"referstothefactthatoneachinputthereisoneandonly

onestatetowhichtheautomatoncantransitionfromitscurrentstate.

Page 20: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

The term "finite automatonor finite statemachine"will refer to the deterministicvariety,althoughweshalluse"deterministic"ortheabbreviationDFAnormally.

Note:IfyouasktodesignFSMorFA,thenyoushoulddesignDFA.DefinitionofaDeterministicFiniteAutomaton

Adeterministicfiniteautomatonconsistsof:

1. Afinitesetofstates,oftendenotedQ.

2. Afinitesetofinputsymbols,oftendenotedΣ.

3. Atransitionfunctionthattakesasargumentsastateandaninputsymbolandreturns a state.The transition functionwill commonlybedenotedδ. Inourinformal graph representation of automata, δ was represented by arcsbetween states and the labels on the arcs. Ifq is a state, anda is an inputsymbol,thenδ(q,a)isthatstatepsuchthatthereisanarclabelledafromqtop.

4. Astartstate,oneofthestatesinQ.5. AsetoffinaloracceptingstatesF.ThesetFisasubsetofQ.

ThemostbriefrepresentationofaDFAisalistingofthefivecomponentsabove.In

proofsweoftentalkaboutaDFAin"five‐tuple"notation:

A=(Q,Σ,δ,qo,F)where A is the name of theDFA, Q is its set of states, Σ its input symbols, δ itstransitionfunction,q0itsstartstate,andFitssetofacceptingstates.

SimplerNotationsforDFA's:

Therearetwopreferrednotationsforrepresentingtransitionfunctionforautomata:1. Atransitiondiagram,whichisagraph.

Page 21: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

2. A transition table, which is a tabular listing of the δ function, which by

implicationtellsusthesetofstatesandtheinputalphabet.

1. TransitionDiagramsAtransitiondiagramforaDFAA=(Q,Σ,δ,qo,F)isagraphdefinedasfollows:

1. ForeachstateinQthereisanode.

2. For each state q in Q and each input symbol a in Σ, let δ(q,a) = p, then thetransition diagram has an arc from node q to node p, labelled a. If there areseveral input symbols that cause transitions from q to p, then the transitiondiagramcanhaveonearc,labelledbythelistofthesesymbols.

3. There is an arrow into the start state qo, labelled Start. This arrow does notoriginateatanynode.

4. Nodescorresponding toacceptingstates (those inF) aremarkedbyadoublecircle.StatesnotinFhaveasinglecircle.

00,1

Figure:Thetransitiondiagram for theDFAaccepting allstrings withasubstring 01

2. TransitionTables

A transition table is a conventional, tabular representationof a function likeδthattakestwoargumentsandreturnsavalue.

Therowsofthetablecorrespondtothestates,andthecolumnscorrespondtotheinputs.

Page 22: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

 

F0

Extennotes

TheL

Nond A"n

onc

CHndra:986

CHndra:986

Theentryfinputaist

Figure:Tra01

nding the

anguage

Now,we cdenotedL

Thatis,theoftheacce

determ

nondetermce.Thisabil

HOP67 843 85

HO67 843 85 F

fortherowthestateδ(

ansitionta

e Transi

ofaDFA

can defineL(A),andis

elanguageeptingstate

ministic

ministic"finilityisoften

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

wcorrespon(q,a).

ableforthe

ition Fun

A:

the languadefinedby

ofAisthees.

cFinite

iteautomanexpressed

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

ndingtosta

DFAaccep

nction to

age of a DFy

setofstrin

eAutom

aton(NFA)dasanabil

CAD843 853 @act Ganes

ACA843 853 @act Ganes

ateqandt

ptingallstr

o Strings

FAA= (Q,

ngsωthat

mata

hasthepowityto"gues

DEM@Vashi :9sh Sir@83

ADE@Vashi :9sh Sir@83

thecolumn

ingswitha

s: Refer

Σ, δ, qo, F)

takethest

wertobeiss'somethi

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

ncorrespon

asubstring

class

). This lang

tartstateq0

inseveralsingaboutit

3 852 05 75

Y 3 852 05 75

ndingto

guage is

0toone

statesattsinput.

Page 23: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

 

Likestat

It abetw

For

the{rat

Exa

allacanwhethatq0m

How

Anlabe

Theshanex

Not

Intsim

CHndra:986

CHndra:986

etheDFA,teandaset

also has aweentheD

rtheNFA,δDFA 's trtherthan

ample:Figuandonlyth think ofeneverithtthenextsmaytransit

Figure:An

wever,iftharc labelleelled0out

eNFAhastllseewhenxtsymbolis

ticethatththesesituatmply"dies,"

HOP67 843 85

HO67 843 85 F

anNFAhatofaccepti

transitionDFAandthe

δisafunctiransition fureturninge

ure,showshestringsof the automhasnotyetsymboldoetiontoitsel

NFAaccep

henextsymed 0 thusofq0.

theoptionnwemakes1,andifs

hereisnoations,thet"although

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

safinitesengstates.

function, weNFAisin

ionthattaunction), bexactlyone

anondeterf0'sand1'maton as b"guessed"esnotbegilfonboth0

ptingallstr

mbolis0,thleads from

ofgoingeitthedefinito,itgoesto

arcoutofqthreadofthotherthre

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

etofstates

which wethetypeof

akesastatebut returnestate,ast

rministicfi'sthatendbeing in sthatthefinnthefinal0and1.

ringsthate

hisNFAalsm q0 to sta

thertoq0otionspreciostateq2a

q1labeled0heNFA'seeadsmayc

CAD843 853 @act Ganes

ACA843 853 @act Ganes

,afinitese

shall commfδ.

eandinputns a set otheDFAmu

initeautomin01.Stattate q0 (penal01has01,evenif

endin01

soguessesate q1. Not

ortoq1,anise.Instateandaccepts

0,andthereexistencecocontinueto

DEM@Vashi :9sh Sir@83

ADE@Vashi :9sh Sir@83

etofinput

monly call

tsymbolaf zero, onust).

maton,whoteq0istheerhaps ambegun.Itfthatsymb

thattheftice that th

ndinfactiteQ1,theNs.

earenoarorrespondioexist.

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

symbols,o

δ. The di

asargumenne, or mor

osejobistostartstate,

mong otherisalwayspbolis0.Thu

final01hashere are tw

tdoesbothFAchecks

rcsatallouingtothos

3 852 05 75

Y 3 852 05 75

onestart

fference

nts{likere states

oaccept,andwer states)possibleus,state

sbegun.wo arcs

h,aswethatthe

utofq2.sestates

Page 24: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

 

Whnosand

Belo

wheonlystatbeloThestatmus1,w

001

Thu

the

CHndra:986

CHndra:986

ileaDFAhsuchconstrdtwo,forex

owfiguresen the autoyitsstartsteq1,soitowFig.

en,thesecteq1hasnstconsidewhileq1go

Figure: Th101

us,afterreaNFAaccep

HOP67 843 85

HO67 843 85 F

hasexactlyraint;wehxample.

suggestshomatonofstate,q0.Wtdoesboth

cond0isrno transitiortransitioesonlytoq

he states

ading001,pts001.

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

onearcouhaveseeni

owanNFAaboveFig.

Whenthefirh.Thesetw

read.Stateonon0, soonsfromboq2.

anNFA is

theNFAis

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

utofeachstnFig.cases

Aprocesses. receives trst0isreawothreads

q0may it "dies."Wothq0and

s in durin

sinstatesq

CAD843 853 @act Ganes

ACA843 853 @act Ganes

tateforeaswherethe

sinputs.Wthe input ad,theNFAaresugges

againgotoWhen the tdq1·Wefin

ng the pro

q0andq2.S

DEM@Vashi :9sh Sir@83

ADE@Vashi :9sh Sir@83

chinputsyenumbero

ehaveshosequence0Amaygotostedbythe

obothq0third inputndthatq0

ocessing of

Sinceq2isa

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

ymbol,anNofarcsisze

ownwhath00101. It soeitherstaesecondco

andq1.Ht, a1,occugoesonly

f input se

anacceptin

3 852 05 75

Y 3 852 05 75

NFAhasero,one,

happensstarts inteq0orolumnin

owever,urs, wetoq0on

equence

ngstate,

Page 25: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

However, the input isnot finished.The fourth input, a0, causesq2's thread todie,

whileq0goestobothq0andq1.Thelastinput,a1,sendsq0toq0andq1,toq2.Sinceweareagaininanacceptingstate,00101isaccepted.

DefinitionofNondeterministicFiniteAutomata

Now, let us introduce the formal notions associated with nondeterministic finiteautomata.ThedifferencesbetweenDFA'sandNFA'swillbepointedoutaswedo.AnNFAisrepresentedessentiallylikeaDFA:

A=(Q,Σ,δ,q0,F)

where:1. Qisafinitesetofstates.

2. Σisafinitesetofinputsymbols.3. q0,amemberofQ,isthestartstate.4. F,asubsetofQ,isthesetoffinal(oraccepting)states.5. δ,thetransitionfunctionthattakesastateinQandaninputsymbolinΣas

argumentsandreturnsasubsetofQ.NoticethattheonlydifferencebetweenanNFAandaDFAisinthetypeofvaluethatδreturns:asetofstatesinthecaseofanNFAandasinglestateinthecaseofaDFA.

TheExtendedTransitionFunction:ReferClassNotes.

TheLanguageofanNFA:

As we have suggested, an NFA accepts a string ω if it is possible to make anysequenceofchoicesofnextstate,whilereadingthecharactersofω,andgofromthestartstatetoanyacceptingstate.

Page 26: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

 

Thestatpre

For

Tha

acceRefer

EquiFinit

AnA1. Fin

Acofollo

CHndra:986

CHndra:986

e fact thatte,ordonoventωfromrmally,ifA=

at is, L(A)eptingstat

ClassNo

ivalencteAuto

Applica

ndingStr

ommonprowing.1. Givena

words.enginewordaofallthamounallowin

HOP67 843 85

HO67 843 85 F

other choiot leadtoambeingacc

=(Q,Σ,δ,q

is the sete.

otesforE

ce of Domata:

tion:T

ingsinT

obleminth

asetofwo A searchusesapar

appearingoheplaceswts of mainngmanype

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

ices usinganystateaceptedbyt

o,F)isanN

of strings

xamples

DetermReferC

extSea

Text

heageofth

ords,findah engine isrticular tecontheWewherethatn memoryeopletosea

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

the inputatall(i.e., ttheNFAas

NFA,then

ω in Σ* su

s.

ministicClassN

arch

heWeban

alldocumes a populachnology, cb(thereawordoccukeep thearchfordoc

CAD843 853 @act Ganes

ACA843 853 @act Ganes

symbols othesequenawhole.

uch that δ(

and Notes

ndotheron

entsthatr examplecalled inverare100,000ursisstoremost commcumentsat

DEM@Vashi :9sh Sir@83

ADE@Vashi :9sh Sir@83

of ω lead tceofstate

(q0 ,ω) con

Nondet

n‐linetext

containonof this prrted indexe0,000differed.Machinmon of thetonce.

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

to a non‐acs"dies"),d

ntains at le

termin

repositorie

ne(orall)rocess. Thees,where frentwordneswithveese lists av

3 852 05 75

Y 3 852 05 75

cceptingdoesnot

east one

istic:

esisthe

ofthosee searchforeachds),alisterylargevailable,

Page 27: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

2. Inverted‐indextechniquesdonotmakeuseof finiteautomata,but theyalsotakeverylargeamountsoftimeforcrawlerstocopytheWebandsetuptheindexes.Thereareanumberofrelatedapplicationsthatareunsuitedforin‐vettedindexes,butaregoodapplicationsforautomaton‐basedtechniques.

The characteristics that make an application suitable for searches that use

automataare:

1. The repository onwhich the search is conducted is rapidly changing. Forexample: Every day, news analysts want to search the day's on‐line news

articles for relevant topics. For example, a financial analyst mightsearchforcertainstocktickersymbolsornamesofcompanies.

A"shoppingrobot"wantstosearchforthecurrentpriceschargedforthe items that its clients request. The robot will retrieve currentcatalog pages fromtheWebandthensearch thosepages forwordsthatsuggestapriceforaparticularitem.

2. The documents to be searched cannot be cataloged. For example,

Amazon.comdoesnotmakeiteasyforcrawlerstofindallthepagesforallthebooksthatthecompanysells.Rather,thesepagesaregenerated"onthefly"inresponsetoqueries.However,wecouldsendaqueryforbooksonacertaintopic, say "finite automata," and then search thepages retrieved for certainwords,e.g.,“excellent"inareviewportion.

2. NondeterministicFiniteAutomataforTextSearch

Supposewearegivenasetofwords,whichweshallcallthekeywords,andwewanttofindoccurrencesofanyofthesewords.Inapplicationssuchasthese,ausefulwayto proceed is to design a nondeterministic finite automaton, which signals, byenteringanacceptingstate,thatithasseenoneofthekeywords.

The text of a document is fed, one character at a time to this NFA, which thenrecognizesoccurrencesof thekeywords in this text. There isa simple form to anNFAthatrecognizesasetofkeywords.

1. There is a start statewith a transition to itself on every input symbol, e.g.

everyprintableASCIIcharacterifweareexaminingtext.Intuitively,thestart

Page 28: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

 

Exa

webin bprinstat

We

Som

(egrpurofs

CHndra:986

CHndra:986

state rkeywor

2. For eactransitionsymthekey

ample:Suppbandebaybelow Fig.ntableASCtes5throug

havetwom1. Writea

afterre

2. Conversimulat

Figu

metext‐prorepandfgrrposes,contates.

HOP67 843 85

HO67 843 85 F

representsrds,evenif

ch keyworionfromthmbola2,anyworda1a2

posewewy.ThetransState 1 is

CIIcharactegh8recog

majorchoicaprogramteadingeach

rttheNFAtetheDFA

ure:AnNFA

ocessingprrep)actualversionto

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

a "guess"fwehaves

d a1a2…ak,hestartstadsoon.Th…akhasbe

anttodesisitiondiagrs the starters.States2gnizeebay.

cesforanithatsimulahinputsym

toanequidirectly.

that search

ograms,sullyuseamaDFAisea

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

that we heensomel

there areatetoq1onhestateqkeenfound.

ignanNFAramforthestate, and2through4

implementatesthisNFmbol.Thesi

ivalent DF

hesforthew

uchasadvamixtureofthasyandis

CAD843 853 @act Ganes

ACA843 853 @act Ganes

have not yettersofon

k states, nsymbolaisanaccep

AtorecogneNFAdesigd we use Σ4havethej

tationofthFAbycompimulationw

FAusingth

wordsweba

ancedformhesetwoaguaranteed

DEM@Vashi :9sh Sir@83

ADE@Vashi :9sh Sir@83

yet begun tneofthese

say q1, q2,1,atransitptingstate

izeoccurregnedusingΣ to standjobofrecog

isNFA.putingtheswassugges

esubset c

and ebay

softheUNpproachesdnottoinc

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

to see onewords.

... , qk· Thtionfromqandindica

encesofthgtherulesafor the segnizingwe

setofstatestedinbelo

constructio

NIXgrepco.However,creasethe

3 852 05 75

Y 3 852 05 75

e of the

here is aq1toq2atesthat

ewordsaboveiset of alleb,while

esitisinowFig.

on.Then

ommand,forournumber

Page 29: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

FiniteAutomataWithEpsilon‐Transitions:ReferClassNotes

FSMproperties:1. Periodicity:

a. The limitations of FSM is that it does not have the capacity to rememberarbitrarilylargeamountofinformation,becauseithasonlyafixednumberofstatesandthissetalimittothelengthofthesequenceitcanremember.

b. Also,wehaveseena finite control representationofFSM,where readheadmovesalwaysonepositiontotherightafterreadinganinputsymbol.

c. Head can never move in reverse direction, therefore, FSM cannot retrieve

whatitreadpreviously,beforecomingtocurrentpositionoftape.d. As it cannot retrievewe cannot say, it can remember something. This also

means that FSM eventually will always repeat a state produce a periodicsequenceofstates.

2. StateDetermination:

a. Since, the initial states of an FSM and the input sequence given to it,determinestheoutputsequence.

Page 30: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

b. Itisalwayspossibletodiscovertheunknownstate,inwhichtheFSMresidesataparticularinstance.

3. ImpossibilityofMultiplication:

a. AnFSMcannotrememberarbitrarilylongsequences.

b. Hence for multiplication operation it is required to remember two fullsequencescorrespondingtomultiplierandmultiplicand,whilemultiplying,itis also required to store the partial sums that we obtain normally atintermediatestagesofmultiplication.

c. Therefore,noFSMcanmultiplytwogivenarbitrarilylargenumbers.

4. Impossibility of palindrome recognition: FSM can recognizing a palindrome,

because itdoesnothavethatcapabilitytorememberall thesymbols itreadsuntilhalfthewaypointofinputsequence,inordertomatchtheminreverseorder,withthesymbolsinsecondhalfofthesequence.

5. Impossibilitytocheckwell‐formednessofparenthesis:

AsFSMhasnocapabilitytorememberalltheearlierinputstoit,cannotcomparewiththeremainingtocheckwell‐formedness.ItisanimpossibletaskforanyFSM.ProblemsonFiniteAutomata/FiniteStateMachine:ReferclassNotesforbelowproblems:Divisibility:1. Designamachinewhichcheckswhetheragivendecimalnumberisdivisibleby3.

2. Designamachinewhichcheckswhetheragivendecimalnumberisdivisibleby4.3. Designamachinewhichcheckswhetherthegivenbinarynumberisdivisibleby3.(May‐01,

May‐02,Dec‐02,June‐07)

Page 31: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

4. DesignaFSMtocheckwhetheragivenunarynumberisdivisibleby3.(May‐03)5. DesignaFSMtocheckwhetheragivenunarynumberisdivisibleby4.(Dec‐05)

6. DesigndivisibilitybyfourtestersFSMforbinarynumbers.(Dec‐05)7. Designamachinewhichcheckswhetherthegiventernarynumber isdivisibleby4.(Dec‐

02)

8. Designamachinewhichcheckswhetherthegiventernarynumberisdivisibleby5ornot.(May‐03)

Endingwith:

9. DesignFSMthatacceptssetofallstringsendingwith101.

10. DesignFSMthatacceptssetofallstringsendingwith‘aab’.

11. DesignFSMthatacceptssetofallstringsendingwith‘110’or‘101’.

12. DesignFSMthatacceptssetofallstringsendingwith‘abb’or‘bba’.

13. DesignFSMthatacceptssetofallstringswithsecondlastsymbolis‘a’over{a,b}.

Contains:

14. DesignFSMinwhichinputisvalidifitcontains‘1101’over{0,1}.

15. DesignFSM thataccepts setof all strings, if it containsatlestoneoccurrenceof substring‘bba’over{a,b}.

16. DesignanFSMinwhichinputisvalidifitdoesnotcontainanyoccurrenceof3consecutiveb’sover{a,b}.

Adder:

Page 32: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

17. DesignFSMtoimplementBinaryAdder.(Jun‐08)

ExtraProblems:

18. DesignFSM,whichhasoddnumberof0’sandanynumberof1’s.

19. DesignFSMwhichacceptsastringifitcontainsevennumberof0’sandoddnumberof1’s.

20. DesignFSMwhichacceptsallstringwhichendwith00.

21. DesignFSMthatacceptssetofallstringscontainingwith1001.22. DesignFSMwhichacceptsthestringifitisendingwith‘aa’.

23. DesignFSMforthelanguageinwhichthestringisacceptableifthesecondlastsymbolis‘a’

overthe∑={a,b}

24. Designamachinewhichcheckswhetheragivendecimalnumberiseven.

25. DesignFSMforthelanguageoverthe∑={a,b}andthestringisacceptableifitcontains

a. Atmost3a’sb. Atleast3a’sc. Exactly3a’s

26. Design FSM for the languageover the∑={ a, b} and the string is acceptable if it doesnot

contain‘bbb’.

27. DesignFSMtorecognizesubstringCATfromtheset∑={C,H,A,R,I,O,T}.

28. DesignFSMtoadd2binarynumbersofequallengths.(May‐00,Dec‐01)

29. DesignFSMwhichgeneratestheremainderwhenthegivendecimalnumberisdividedby3.

(Dec‐01)

Page 33: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

30. DesignFSMwhichgeneratestheremainderwhenthegivenbinarynumberisdividedby4.

31. DesignFSMwhichgeneratestheremainderwhenthegiventernarynumberisdividedby3.

Problems:

ReferclassNotesforbelowproblems:1. GiveDFAacceptingthefollowinglanguageover∑={0,1}

a. Numberof1’sismultipleof3.b. Numberof1’sisnotmultipleof3.

2. GiveDFAacceptingthefollowinglanguageover∑={0,1}

a. Numberof1’sisevenandnumberof0’siseven.b. Numberof1’sisoddandnumberof0’sisodd.

3. DesignaDFAforasetofstringsover∑={0,1}suchthatthenumberof0’sisdivisibleby5,

andnumberof1’sdivisibleby3.

4. DrawDFAforthefollowinglanguageover∑={0,1}a. Allstringsoflengthatmost5.b. Allstringswithexactlytwo1’s.c. Allstringscontainingatleasttwo0’s.d. Allstringscontainingatmosttwo0’s.e. Allstringsstartingwith1andlengthofthestringisdivisibleby3.

5. DrawDFAforthefollowinglanguageover∑={0,1}

a. Allstringsstartingwith‘abb’.b. Allstringswith‘abb’asasubstringi.e.,‘abb’anywhereinthestring.c. Allstringsendingin‘abb’.

6. DesignDFAforalanguageofstring0and1,suchthat:

a. Endingwith‘10’.b. Endingwith‘11’.c. Endingwith‘1’.

Page 34: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

7. Design the DFA which accepts set of strings such that every string containing ‘00’ as asubstringbutnot‘000’asasubstring. (Dec‐2007)

8. Design theDFA for the language, containing strings inwhich leftmost symbol differ fromrightmostsymbol.∑={0,1}. (May‐2008,Dec‐2008)

9. DesignaDFAforsetofstringsover∑={0,1}inwhichthereareatleasttwooccurrencesof‘b’betweenanytwooccurrencesof‘a’.

10. DesignaDFAforsetofallstringsover∑={0,1}endingineither‘ab’or‘ba’.

11. DesignaDFAforsetofallstringsover∑={0,1}containingboth‘ab’and‘ba’assubstrings.

12. DesignaFAthatreadsstringdefinedover∑={0,1}andacceptsonlythosestringswhich

endupineither‘aa’or‘bb’.

13. Design a DFA for set of all strings over ∑ = {0, 1} containing neither ‘aa’ nor ‘bb’ as a

substring.

14. Design aDFA for set of all strings over∑ = {0, 1} such that each ‘a’ inω is immediatelyprecededandimmediatelyfollowedbya‘b’.

15. DesignaDFAforsetofallstringsover∑={0,1}suchthateveryblockoffiveconsecutivesymbolscontainsatleasttwo0’s.

16. DesignaDFAforsetofallstringsover∑={0,1}suchthatstringseitherbeginorendwith‘01’.

17. DesignaDFAforsetofallstringsover∑={0,1}suchthatthethirdsymbolfromtherightendis‘1’. (Dec‐2008)

18. ConstructaDFAforsetofstringscontainingeitherthesubstring‘aaa’or‘bbb’.

Page 35: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

19. ConstructaDFAforacceptingasetofstringsover∑={0,1}notendingin‘010’.

20. DesignaDFAthatreadsstringsmadeupof letters in theword ‘CHARIOT’andrecognizesthesestringsthatcontaintheword‘CAT’asasubstring.

Subjects Taken by Ganesh Sir: 

Semester  Subject  Batch SEM‐VI (Computer) 

SPCC (System 

Programming and Compiler Construction)

Vacation + Regular 

ALL  OCAJP 1.7 (Oracle Certified Associate JAVA Programmer)

Vacation + Regular 

ALL  OCPJP 1.7 (Oracle Certified Professional JAVA Programmer)

Vacation + Regular 

Page 36: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

Cha

Reg

WeThe

Regwhior c

Regu Now

detdes

Howdec

CHndra:986

CHndra:986

apter2

gular

begin thiseseexpress

gular expreichweexpcompiler c

ularExw, we switterministicscription:t

wever, regclarativew

HOP67 843 85

HO67 843 85 F

2

Exp

s chapter sionsare

essions alsresssomeomponents

xpresstch our atc and nthe "regula

gular exprway toexpr

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

pressio

by introduanotherty

so may beimportants.

sionsttention frnondetermar express

essions ofressthest

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

ons

ucing the nypeof lan

e thoughtt applicati

from machministic finion."

ffer somettringswe

CAD843 853 @act Ganes

ACA843 853 @ct Ganes

notation cguage‐defin

of as a "pions,such

ine‐like denite autom

thing thatwanttoa

DEM@Vashi :9sh Sir@83

ADE@Vashi :9h Sir@83

called "reguning notat

programmias text‐sea

escriptionsmata ‐

automaaccept.

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

ular expretion.

ing languarchappli

of languato an a

ata do n

3 852 05 75

Y 3 852 5 75

essions."

age," inications

ages ‐lgebraic

not: a

Page 37: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

OperatorsoftheRegularExpression:

1. Union:SayL1andL2arethetwoLanguage,thenL1UL2={a,b|aЄL1andbЄL2}Example:L1={a,b}over∑={a,b}andL2={aa,bb}over∑={a,b}ThenL1UL2={a,b,aa,bb}

2. Concatenation:SayL1andL2arethetwoLanguage,thenL1.L2={ab|aЄL1andbЄL2}Example:L1={a,b}over∑={a,b}andL2={aa,bb}over∑={a,b}ThenL1.L2={aaa,abb,baa,bbb}

3. Closure(zeroormore):SayLisaLanguage,thenlanguageclosure(L*)isdenotedas:

L*=L0UL1UL2UL3…………………..Example:If∑={0,1}ThenL*over∑={ɛ,0,1,00,01,10,11,000,001…}

4. PositiveClosure(oneormore):SayLisaLanguage,thenLanguagepositiveclosure(L+)isdenotedas:

L+=L1UL2UL3…………………..Example:If∑={0,1}ThenL+over∑={0,1,00,01,10,11,000,001…}L+=L.L*

BuildingRegularExpressions: Algebras of all kinds start with some elementary expressions, usually

constantsand/or variables.

Page 38: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Algebras then allow us to construct more expressions by applying acertain set of operators to these elementary expressionsand to previouslyconstructed expressions.

Usually,somemethod ofgroupingoperatorswith their operands, such as

parentheses,is required aswell.

For instance, the familiar arithmetic algebra starts with constants such asintegers and real numbers, plus variables, and builds more complexexpressionswitharithmeticoperators suchas +and x.

The algebra of regular expressionsfollowsthis pattern, usingconstants and

variaibles that denote languages, and operators for the three operationsunion, dot,and star.

We can describe the regular expressions recursively, as follows. In this

definition, wenot only describe what the legalregular expressionsare, butforeach regularexpressionE,wedescribethelanguage it represents,whichwedenote L(E).

The basisconsistsofthree parts:1.Theconstantsεandϕareregularexpressions,denotingthelanguages{ε}andϕ,respectively.Thatis,L(ε)={ε},andL(ϕ)=ϕ.2. Ifaisanysymbol,thena isaregularexpression.Thisexpressiondenotesthe language {a}. That is, L(a) = {a}. Note thatwe use boldface font todenote an expression corresponding to a symbol. The correspondence, e.g.that areferstocl,shouldbeobvious.3. A variable, usually capitalized and italic such as L, is a variable,representinganylanguage.

Page 39: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

Prece Like

ordthei

Weexpbefoandopey)‐

Forope

1.

2.

j

CHndra:986

CHndra:986

edence

e other algder of "preiroperand

are familipressions. Fore the sumd not to therators fro‐z,and nor regular eerators:

The star to the smregularex

Next in Aftergrouoperatorsjuxtaposedtogether. matter inthere isainstance,0

HOP67 843 85

HO67 843 85 F

ofRegu

gebras, thecedence,"ds inapart

iar with thFor instanm, so it ishe expressom theleftt tox‐(y

expressions

operatormallest seqxpression.

precedencuping all ss to their(adjacentSince conwhat ordchoice to b012isgrou

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

ular‐Exp

he regular‐which meticularord

he notionnce, we knequivalentsion x(y+zt inarithm‐z).

s, the follo

is of higheuence of s

ce comesstars to th operand

t, with ncatenationer wegrobemade, yuped(01)2

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

ression

‐expressioneans thatder.

of precedenow thatt to the paz). Similarlmetic,so

owing is th

est precedsymbols to

the concaheir operads. Thatno interven is an assoupconsecuyou should2.

CAD843 853 @act Ganes

ACA843 853 @ct Ganes

Operat

n operatooperators

ence fromxy+z groarenthesizely, we groux‐ y‐ z

he order o

dence. Tho its left t

atenationands, we gt is, all exening opesociative outiveconcad group the

DEM@Vashi :9sh Sir@83

ADE@Vashi :9h Sir@83

tors

rs have a are assoc

ordinaryups the ped expressup two ofzisequival

of preceden

at is, it ahat is a w

or "dot"group conxpressionserator) arperator itatenations,em from th

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

an assumedciated with

arithmetiproduct xysion (xy)+f the samlentto(x

nce for th

applies onlwell‐formed

operatorncatenation that arre groupet does noalthoughhe left. Fo

3 852 05 75

Y 3 852 5 75

dh

cyzex‐

e

yd

r.nredotifor

Page 40: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

3. Finally, all unions (+operators) are groupedwith their operands. Sinceunionisalsoassociative,itagainmatters little inwhichorderconsecutiveunionsaregrouped,but weshallassumegroupingfromtheleft.

FiniteAutomataandRegularExpressions While the regular‐expression approach to describing languages is

fundamentally different from the finite‐automaton approach, these twonotations turnout torepresent exactly the same set of languages,whichwehave termed the"regularlanguages."

Wehave already shown that deterministic finite automata, and the twokinds of nondeterministic finite automata ‐ with and without ε‐transitions‐accept the same class of languages. In order to show thattheregular expressions definethesame class,wemust showthat:

1. Everylanguagedefinedby oneof theseautomata is also

definedby aregularexpression.Forthisproof,wecanassume thelanguage isacceptedbysomeDFA.

2. Every language defined by a regular expression is defined by oneof these automata. For this part of the proof, the easiest is toshow that thereisanNFAwith:‐transitions accepting the samelanguage.

Figure: shows all the equivalences wehave proved or will prove. An arc fromclass Xto classYmeans that weprove every language defined by class Xisalso defined byclassY. Since the graph is strongly connected (i.e., wecan getfrom eachofthe four nodes toany othernode)weseethatall fourclassesarereally the same.

Page 41: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

FromExp The

DFAsets

Howthethethrindupro

Finawethe

Theoresuchth

Refe

CHndra:986

CHndra:986

Figure: notation

mressio

e construcA is surprs ofstrings

wever, thestates. Insimplest eough anyuctively gressivelyally, thepagenerate aproofofth

em: IfL=hatL=L(R

erClass

HOP67 843 85

HO67 843 85 F

Plan fors forregu

DFA'sons:

ction of arisingly tristhat labe

paths aren an inducexpressionstates (build thelarger sets

aths arealatthe endhe followin

L(A)forsR).

sNotes

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

r showingular langua

s t

regular eicky. Rougel certainp

e allowedctivedefinins thatde‐(i.e., theyexpressio

s ofstates

llowedto grepresent

ngtheorem

someDFA

forPro

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

g the equages

to

expressionghly, we bupathsin th

to pass thition of the‐scribe patare singleons thats.

gothrougtallpossibm.

AA, thenth

oof.

CAD843 853 @act Ganes

ACA843 853 @ct Ganes

uivalence

Regul

to defineuild exprehe DFA's t

hrough onlese expresthsthatare nodes let the

hany stateble paths.

here isar

DEM@Vashi :9sh Sir@83

ADE@Vashi :9h Sir@83

of four

lar

the langussions thatransition

y a limitedsions, werenotallowor singlee paths g

e; i.e., the eThese idea

regularex

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

differen

uage of anat describdiagram.

d subset ostart withwedtopasarcs), andgo through

expressionasappearin

xpressionR

3 852 05 75

Y 3 852 5 75

nt

ye

ofhssdh

nsn

R

Page 42: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Converting DFA's to RegularExpressions by Eliminating States:ReferClassNotes.

Converting Regular Expressions toAutomata:Theorem:Everylanguagedefinedbyaregularexpressionisalsodefinedbyafiniteautomaton.

PROOF:SupposeL =L(R) foraregularexpressionR.WeshowthatL=L(E)forsome

ε‐NFAEwith:

1.Exactlyoneacceptingstate.

2.Noarcsinto the initialstate.

3.Noarcsout oftheacceptingstate.TheproofisbystructuralinductiononR, followingthe recursivedefinitionofregularexpressionsthat wehadbefore.

Page 43: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

r

In pautotoa

Parstat

Finalangalso(2),

CHndra:986

CHndra:986

Figure 1:regularexp

part (a) womaton isan acceptin

rt(b)showte to accepally, partguage of thoL(a). It i, and (3).

HOP67 843 85

HO67 843 85 F

The baspression

we see hows easilyseengstateis

wstheconspting state

(c) giveshis automaiseasy to c

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

sis of the

w to handen to be {ε}labeledE.

struction fo, soϕ is t

the automaton evidecheckthat

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

constructi

dle the exp},since the.

orϕ.Clearthe languag

maton forently consistheseaut

CAD843 853 @act Ganes

ACA843 853 @ct Ganes

ion of an

pression E.e only path

ly thereargeof this

r a regulasts of theomataall

DEM@Vashi :9sh Sir@83

ADE@Vashi :9h Sir@83

automato

The langh from the

re nopathsautomaton

ar expressone stringsatisfy con

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

on from

guage of the start stat

sfrom starn.

sion a. Tha,which

nditions (1

3 852 05 75

Y 3 852 5 75

a

hete

rt

heis),

Page 44: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

The fo

1.

CHndra:986

CHndra:986

Figure: construct

ourcasesa

The exprethe automstate,wecautomatonautomata

HOP67 843 85

HO67 843 85 F

The indution

are:

ssion isRmaton of Fcangoto tn for S.W, following

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

uctive step

+S for somFig. (a) serthestartsWe then reg a path l

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

p in the

me smallerrves. Thatstateofeiteach the aabeled by

CAD843 853 @act Ganes

ACA843 853 @ct Ganes

regular‐e

r expressio is, startithertheauaccepting sy some stri

DEM@Vashi :9sh Sir@83

ADE@Vashi :9h Sir@83

expression

ons R aning at theutomatonstate of oning in L(R

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

n‐to‐ε‐FA

nd S. The new starforRor thne of t.hesR)or L(S)

3 852 05 75

Y 3 852 5 75

A

nrthee),

Page 45: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

respectively.Oncewe reach the acceptingstate of the automaton forRor S,wecan follow one of the ε‐arcs to the accepting state of thenew automaton.

Thus, the languageofthe automatonin Fig.{a) isL(R)UL(S).

2. The expression is RS for some smaller expressions R and S. The

automaton for the concatenation is shown in Fig. (b). Note that thestart state of the first automaton becomes the start state of thewhole,and theacceptingstate of the secondautomaton becomes theacceptingstateofthewhole.The idea isthat theonlypaths fromstarttoacceptingstategofirst throughtheautomatonforR,whereitmustfollow a path labeled by a string in L(R ),and t hen through theautomaton forS,where it followsa path labeled by a string inL(S).Thus, the paths in the automaton of Fig. (b) are all and only thoselabeledbystringsinL(R)L(S).

3. The expression is R* for some smaller expression R.Then we use

theautomatonofFig.(c).Thatautomaton allowsustogoeither:

(a)Directly fromthestart state to theacceptingstate alongapath labeledε.That pathlets us acceptε,which is inL(R*)nomatterwhatexpressionRis.

(b) To the start state of the automaton for R, through thatautomaton one or more times, and then to the acceptingstate. This set of paths allows us to accept strings inL(R),L(R)L(R),L()L(R)L(R),andsoon,thuscovering allstringsinL(R*)except perhaps ε,whichwas covered by the direct arcto theacceptingstatementionedin (1a).

4. The expression is (R) for some smaller expression R. Theautomaton for R also serves as the automaton for (R), since theparenthesesdonotchange the language definedby theexpression.

Page 46: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

CHndra:986

CHndra:986

HOP67 843 85

HO67 843 85 F

Figure:A

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

Automatac

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

constructe

CAD843 853 @act Ganes

ACA843 853 @ct Ganes

d for(0+

DEM@Vashi :9sh Sir@83

ADE@Vashi :9h Sir@83

1)*1(0+

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

1)

3 852 05 75

Y 3 852 5 75

Page 47: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

CHndra:986

CHndra:986

HOP67 843 85

HO67 843 85 F

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

CAD843 853 @act Ganes

ACA843 853 @ct Ganes

DEM@Vashi :9sh Sir@83

ADE@Vashi :9h Sir@83

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

3 852 05 75

Y 3 852 5 75

Page 48: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

CHndra:986

CHndra:986

HOP67 843 85

HO67 843 85 F

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

CAD843 853 @act Ganes

ACA843 853 @ct Ganes

DEM@Vashi :9sh Sir@83

ADE@Vashi :9h Sir@83

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

3 852 05 75

Y 3 852 5 75

Page 49: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

LawsFollowi

1. AssopeExa

CHndra:986

CHndra:986

sforReingarethe

sociativityerandswheample:

HOP67 843 85

HO67 843 85 F

egularalgebraicl

:Associativentheoper

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

ExpreslawsforRe

vityisthepatorisapp

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

ssion:egularexpr

propertyofpliedtwice.

CAD843 853 @act Ganes

ACA843 853 @ct Ganes

ressions:

fanoperat

DEM@Vashi :9sh Sir@83

ADE@Vashi :9h Sir@83

orthatallo

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

owstoregr

3 852 05 75

Y 3 852 5 75

roupthe

Page 50: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Associativitylawofmultiplication: (A*B)*C=A*(B*C)AssociativitylawofUnion: (A+B)+C=A+(B+C)

2. Commutative:Commutativeisthepropertyofanoperatorthatsayswecanswitchtheorderofoperandsandgetthesameresult.Example:Commutativelawofunion:A+B=B+A

3. Identity: An identity for an operator is a value such that when the operator isappliedtotheidentityandsomeothervalue,theresultistheothervalue.Example:0istheidentityforaddition:0+X=X+0=X,here0istheidentity.1istheidentityforMultiplication:1*X=X*1=X,here1istheidentity.ᶲistheidentityforunionᶲUL=LUᶲ=L,hereᶲistheidentity.ɛistheidentityforconcatenationɛ.L=L.ɛ=L,hereɛistheidentity.

4. Annihilators:Anannihilatorforanoperatorisavaluesuchthatwhentheoperatorisappliedtotheannihilatorandsomeothervalue,theresultistheannihilator.Example:0istheannihilatorformultiplication.0*X=X*0=0,here0istheannihilator.ᶲistheannihilatorforconcatenation.ᶲ.L=L.ᶲ=L,hereᶲistheannihilator.

5. DistributiveLaw: A distributive law involves two operators and asserts that oneoperator can be pushed down to be applied to each argument of other operatorindividually.Example:X*(Y+Z)=X*Y+Y*Z

Page 51: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

(X+Y)*Z=X*Z+Y*Z

6. IdempotentLaw:Anoperatorissaidtobeidempotentiftheresultofapplyingittotwoofthesamevaluesasargumentsisthatvalue.Example:Lawofidempotentforunion:LUL=L

7. Lawsinvolvingclosures:(L*)*=L*ᶲ*=ɛɛ*=ɛL+=LL*L*=L++ɛ

Problems:ReferclassNotesforbelowproblems:1. DescribethefollowingsetsbyRegularexpression.

a. {abb}b. {1010}c. {ab,ba}d. {ɛ,aa}e. {011,0,1,110}

2. Writetheregularexpressionforthefollowing:

a. Setofallstringson{a,b}terminatedbyeitheran‘a’ora‘bb’.b. Setofallstringson{0,1}startingwith10andendingwith‘111’.c. Setofallstringson{a,b}withanevennumberofa’sfollowedbyanodd

numberofb’s.(Dec‐00)

3. Writeregularexpressionsforthefollowinglanguages:a. L={anbm|n>=4,m<=3}b. L={w|(|w|mod3=0),wЄ{a,b}}

(June‐08)4. Writeregularexpressionsforthefollowinglanguages:

a. L={anbm|(n+m)iseven}

Page 52: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

b. L={wЄ{a,b}*|(|numberofa’sinw|mod3=0)}(Dec‐07)

5. Writetheregularexpressiontogeneratestringsoflength6orlessover{0,1}

6. Findaregularexpressioncorrespondingtoeachofthefollowingsubsetof{0,1}:a. Thelanguageofallstringscontainingexactlytwo0’sb. Thelanguageofallstringsthatbeginorendwith00or11.c. Thelanguageofallstringscontainingboth11and010assubstrings.

(Dec‐06)7. WhatisthelanguagerepresentedbytheregularexpressionL((aUb)*a).

8. Expressinwordsthelanguagerepresentedbythefollowingregularexpression

(a*bc)*a.

9. Writearegularexpression for thesetofallstringsof0’sand1’scontainingnomorethan2consecutive1’s.

10. Writeregularexpressionforthefollowing:a. Setofallstringson{a,b}whichendina‘a’or‘bb’b. Setofallstringson{0,1}startingwith10andendingwith111.c. Setofallstringson{0,1}containingnomorethan2consecutive1’s.

11. Writea regularexpressioncorresponding toeachof the followingsubsetof {a,

b}*:a. Setofallstringshavingevennumberofa’sandnob’s.b. Setofallstringsthatcontainevennumberofa’sandb’s.c. Setofallstringsthatcontainoddnumberofa’sandb’s.

12. Writeregularexpressionforthefollowing:

a. Setofallstrings0’sand1’ssuchthat10thsymbolfromtherightendis1.b. Set of all string in (0+1)* such that some of two 0’s are separated by a

stringwhoselengthis4i,forsomei>=0.13. Define the languagesuch thatallwordsbeginandendwith ‘a’ and inbetween

anywordusing‘b’.

14. Definelanguagesuchthatitcouldcontainatleastonedoubleletter.

15. Definelanguagesuchthatitcouldcontainnooccurrenceofadoubleletter.

Page 53: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

16. Provethefollowingidentitiesforregularexpressionsr,sandt.a. r+s=s+rb. (r+s)+t=r+(s+t)c. (rs)t=r(st) (Dec‐03)d. r(s+t)=rt+st (Dec‐03)e. (r*)*=r*f. (ɛ+r)*=r*g. (r*s*)*=(r+s)*

17. Verifythefollowingidentitiesinvolvingregularexpressions:a. (r+s)+t=r+(s+t)b. (rs)t=r(st)

(May‐06)

18. Proveordisprovethefollowingregularexpressionsr,sandt:a. (rs+r)*r=r(sr+r)*b. s(rs+s)*r=rr*s(r*s)*c. (r+s)*=r*+s*

19. Provetheformula: (111*)*=(11+111)*20. Showthat(1+00*1)+(1+00*1)(0+10*1)*(0+10*1)=0*1(0+10*1)*.(May‐06)

21. Showthat0(0+1)*+(0+1)*00(0+1)*=(1*0)*(01*)* (Dec‐07)

Page 54: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Subjects Taken by Ganesh Sir: 

Semester  Subject  Batch SEM‐VI (Computer) 

SPCC (System 

Programming and Compiler Construction)

Vacation + Regular 

ALL  OCAJP 1.7 (Oracle Certified Associate JAVA Programmer)

Vacation + Regular 

ALL  OCPJP 1.7 (Oracle Certified Professional JAVA Programmer)

Vacation + Regular 

 

 

Page 55: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Chapter3

Provinglanguagestobenon−regular

We have established that the class of languages known as the regularlanguages has at least four different descriptions. They are thelanguages accepted by DFA's, by NFA's, and by ε‐NFA's; they are also thelanguagesdefinedbyregularexpressions.

Not everylanguageisa regularlanguage.Weshall introducea powerfultechnique, known as the "pumping lemma," for showing certainlanguages not to be regular. We then give several examples ofnon‐regularlanguages.ThePumpingLemma forRegularLanguages

Let us consider the languageL01 = {0n1nI n >=1}. This languagecontainsallstrings01,0011,000111,andsoon, thatconsist ofoneormore0'sfollowedbyanequalnumberof1's.WeclaimthatL01isnotaregularlanguage.

TheintuitiveargumentisthatifL01wereregular,thenL01wouldbethelanguageofsomeDFAA.Thisautomatonhassomeparticularnumberofstates,saykstates.Imaginethisautomatonreceivingk0'sasinput.Itisinsomestateafterconsumingeachofthek+1prefixesoftheinput:0,0,00,...,0k.

Sincethereareonlykdifferentstates,thepigeonholeprincipletellsus

thatafterreadingtwodifferentprefixes,say0iand0j,Amustbeinthesamestate,saystateq.

However,supposeinsteadthatafterreadingiorj0's,theautomatonAstarts receiving1'sas input.After receiving i1's, itmust accept if itpreviouslyreceivedi0's,butnotifitreceivedj0's.Sinceitwasinstate

Page 56: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

qwhenthe1'sstarted,itcannot"remember"whetheritreceivediorj0's,sowecan "fool"Aandmake itdo the wrongthing ‐acceptif itshouldnot,orfailtoacceptwhenitshould.

Theaboveargumentisinformal,butcanbemadeprecise. However,the same conclusion, that the language L01 is not regular, can bereachedusingageneralresult,asfollows.

Theorem: {The pumping lemma for regular languages) Let L be aregularlanguage.Thenthereexistsaconstantn{whichdependsonL)suchthatforeverystringωinLsuchthatlωl>=n,wecanbreakωintothreestrings,ω=xyz,suchthat:1.y!=ε2.lxyl<=n.3.Forallk>=0,thestringxykzisalsoinL.

That is, we can always find a nonempty stringy not too far from thebeginningofwthatcanbe"pumped";thatis,repeatingyanynumberoftimes,ordeleting it {thecase k=0) ,keeps the resultingstring in thelanguageL.

Page 57: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

Figurestatet

CHndra:986

CHndra:986

e4.1: Eveorepeat.

HOP67 843 85

HO67 843 85 F

ery string

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

g longer t

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

than the

CAD843 853 @act Ganes

ACA843 853 @ct Ganes

numbero

DEM@Vashi :9sh Sir@83

ADE@Vashi :9h Sir@83

ofstatesm

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

mustcaus

3 852 05 75

Y 3 852 5 75

e

Page 58: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

Appl

Leteaclem

CHndra:986

CHndra:986

ications

tusSeesch case. wmmatopr

HOP67 843 85

HO67 843 85 F

sof the

someexamwe shall rovethat

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

Pumpi

mplesofhproposethelangu

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

ingLem

howthe a languauageisnot

CAD843 853 @act Ganes

ACA843 853 @ct Ganes

mma:

pumpingage and tregular.

DEM@Vashi :9sh Sir@83

ADE@Vashi :9h Sir@83

lemmaisuse the

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

sused.I pumpin

3 852 05 75

Y 3 852 5 75

nng

Page 59: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

CHndra:986

CHndra:986

HOP67 843 85

HO67 843 85 F

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

CAD843 853 @act Ganes

ACA843 853 @ct Ganes

DEM@Vashi :9sh Sir@83

ADE@Vashi :9h Sir@83

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

3 852 05 75

Y 3 852 5 75

Page 60: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

CHndra:986

CHndra:986

HOP67 843 85

HO67 843 85 F

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

CAD843 853 @act Ganes

ACA843 853 @ct Ganes

DEM@Vashi :9sh Sir@83

ADE@Vashi :9h Sir@83

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

3 852 05 75

Y 3 852 5 75

Page 61: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

Closu In

langoperegu

CHndra:986

CHndra:986

ureProp

this sectioguages areerations (eular." The

HOP67 843 85

HO67 843 85 F

pertieso

on, we shae regular, ae.g.,L is these theore

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

ofRegul

all prove sand a langhe union oems are of

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

larLang

several thguage L iof two reguften called

CAD843 853 @act Ganes

ACA843 853 @ct Ganes

guages:

eorems ofs formedular languad closure pr

DEM@Vashi :9sh Sir@83

ADE@Vashi :9h Sir@83

f the formfrom themages), thenopertiesof

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

m "if certaim by certain L is alsthe regula

3 852 05 75

Y 3 852 5 75

ininoar

Page 62: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

langund

Closareservof teachrepclosfor

1.

2.

3.

4.

5.

6.

7.

8.

9.

ClosuOperOur finterse1. Let

that

2. Letthat

3. Let

the

CHndra:986

CHndra:986

guages, sinder theope

sureproperegular,veasan inthe regularh otherinpresentatiosure properegular lan

The union

The inters

The compl

The differe

The revers

The closur

The conca

Ahomomoisregular.

The invers

ure ofations

first closurection, and

LandMbtcontains

LandMtcontains

tLbealesetofstri

HOP67 843 85

HO67 843 85 F

nce they serationme

ertiesexprthen certanterestingr languagenourundeon is far berty. Herenguages:

noftworeg

sectionoft

lement ofa

enceoftwo

salofa reg

re(star)o

atenationo

orphism(s.

sehomomo

Regula

re propertd complem

belanguagallstrings

belanguagallstrings

languageoingsin·tha

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

how thatntioned.

resstheidain relateillustratioes (automerstandingetter thane is a summ

gular langu

tworegular

a regular l

oregular l

gular langu

fa regular

ofregular l

substitutio

orphismof

ar Lang

ties arementation:

ges overalpsthatarc

gesoverals thatare

overalphaatarenot

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

the class

deathatwd languageon ofhowmata andgof theclan the othmary of t

uages isre

r language

language is

anguagesi

uage isreg

r language

languages

onofstring

faregular

guages

the three

phabet.Tineithero

lphabet.inboth L

abet.TheinL.

CAD843 853 @act Ganes

ACA843 853 @ct Ganes

of regula

when one (es arc alsthe equivaregular exassof languers in supthe princip

egular.

es isregula

sregular.

isregular.

gular.

isregular

isregular.

gsforsym

language

Under

e boolean

ThenLUMorbothofL

ThenLnMandM.

en ,the

DEM@Vashi :9sh Sir@83

ADE@Vashi :9h Sir@83

r language

(or several)o regular.alentreprexpressionsuages, sincpporting apal closure

ar.

.

.

mbols)ofa

isregular.

Bool

n operatio

Misthe laLandM.

M isthe la

compleme

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

es is close

)language They alsesentation) reinforcceoften ona proof ofe propertie

regularla

.

lean

ons: union

anguage

anguage

entofL,is

3 852 05 75

Y 3 852 5 75

ed

essonsceneaes

anguage

n,

s

Page 63: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

It tthe

Hom

ForEx

CHndra:986

CHndra:986

turnsouteboolean o

momorp

xamples

HOP67 843 85

HO67 843 85 F

that theoperations

phism:

Refercla

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

regular l.

assNotes

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

languages

s.

CAD843 853 @act Ganes

ACA843 853 @ct Ganes

are closed

DEM@Vashi :9sh Sir@83

ADE@Vashi :9h Sir@83

dundera

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

all threeo

3 852 05 75

Y 3 852 5 75

of

Page 64: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

Inve

ForEx

CHndra:986

CHndra:986

erseHo

Figu

xamples

HOP67 843 85

HO67 843 85 F

momor

re 4.5: Ah

Refercla

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

rphism

homomorinve

assNotes

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

m:

rphism appersedirec

s.

CAD843 853 @act Ganes

ACA843 853 @ct Ganes

pliedin thction

DEM@Vashi :9sh Sir@83

ADE@Vashi :9h Sir@83

he forward

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

dand

3 852 05 75

Y 3 852 5 75

Page 65: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Subjects Taken by Ganesh Sir: 

Semester  Subject  Batch SEM‐VI (Computer) 

SPCC (System 

Programming and Compiler Construction)

Vacation + Regular 

ALL  OCAJP 1.7 (Oracle Certified Associate JAVA Programmer)

Vacation + Regular 

ALL  OCPJP 1.7 (Oracle Certified Professional JAVA Programmer)

Vacation + Regular 

 

 

Page 66: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Chapter4

DFAMinimization

DecisionPropertiesof RegularLanguages: In this sectionweconsider howone answers important questions about

regularlanguages.

First, we must consider what it means to ask a question about alanguage.

The typical language is infinite, so you cannot present the strings of the

language to someone and ask a question that requires them to inspecttheinfinitesetofstrings.

Rather, wepresent a language by givingone of the finite representations

for it that we have developed: a DFA, an NFA, an €‐NFA, or a regularexpression.

Ofcourse the language sodescribedwillberegular, and in factthere isno

wayat all to representcompletelyarbitrary languages.

However,formanyof thequestionsweask,algorithmsexistonly for theclass of regular languages. The same questions become "undecidable" (noalgorithm to answer them exists) when posed using more "expressive"notations (i.e., notations that can be used to express a larger set oflanguages) than the representations we have developed for the regularlanguages.W

We begin our study of algorithms for questions about regular languages

byreviewingthewayswecan convertonerepresentationinto anotherforthesamelanguage.

Inparticular,wewant to observe the time complexityof the algorithms

that perform the conversions. We then consider someof the fundamentalquestionsaboutlanguages:

Page 67: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

1. Is the language described empty?

2. Isaparticularstringwin thedescribed language?

3.Do twodescriptionsofa language actuallydescribethe same language?

This questionisoften called "equivalence"oflanguages.TestingEmptinessofRegularLanguages

At first glance theanswer to thequestion "is regular language L

empty?"isobvious:ϕisempty,andallotherregularlanguagesarenot.

The problem is not statedwith an explicit list of the strings inL.Rather,we are given some representation for L and need to decidewhetherthatrepresentationdenotesthelanguageϕ.

If our representation is any kind of finite automaton, the emptiness

questioniswhetherthereisanypathwhatsoeverfromthestartstatetosomeacceptingstate.

Ifso,thelanguageisnonempty,whileiftheacceptingstatesareall

separatedfromthestartstate,thenthelanguageisempty.

Deciding whether we can reach an accepting state from the startstateisasimpleinstanceofgraph‐reachability,similarinspirittothecalculationoftheε‐closure.

Page 68: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

Testin

The

lanrep

IfLDFAstat

Ifth

thethedimreq

IfLaDise|w|

Howmo

CHndra:986

CHndra:986

ngMemb

enext quguage L,presented

LisrepresAprocesste.

heDFAeneanswer ie DFA is rmensionalquirescon

LhasanyDFAandrexponentia.wever,iftre efficie

HOP67 843 85

HO67 843 85 F

bership

uestion ois w inbyanaut

sentedbyingthest

ndsinanis "no."Threpresentearray thastanttim

otherreprunthetalinthes

therepresnt to sim

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

inaReg

f importaL. Whileomatono

yaDFA,ttringofin

acceptinghisalgorited by a suat is the t

me,andthe

resentatioestaboveizeofthe

sentationmulate the

A ACne:9867 8bts Conta

RA Ane:9867 8bts Conta

gularLan

nce is,give w is rrregular

thealgornputsymb

gstate,ththm isexuitable datransitioneentirete

onbesidee.Thatarepresen

isanNFe NFA di

CAD843 853 @act Ganes

ACA843 853 @ct Ganes

nguage

ven a strepresenteexpressio

ithmissibolsw,beg

heanswerxtremely ata structn table, tsttakesO

saDFA,approchcntation,alt

Aorε‐NFrectly. Th

DEM@Vashi :9sh Sir@83

ADE@Vashi :9h Sir@83

ingwanded explin.

imple.Simginningi

is"yes";fast. If |wure, suchhen eachO(n)time.

wecouldouldtakethoughiti

FA,itissihat is, w

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

daregulaicitly, L i

mulatethnthestar

otherwisw|=n, anh as a twotransitio.

converttetimethaislineari

impleranwe proces

3 852 05 75

Y 3 852 5 75

aris

ert

edo‐n

oatn

dss

Page 69: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

)

symbolsofwoneatatime,maintainingthesetofstatestheNFAcanbeinafterfollowinganypathlabeledwiththatprefixofw.

Ifwisoflengthn,andtheNFAhassstates,thentherunningtimeof

this algorithm is O(ns2 ) . Each input symbol can be processed bytakingtheprevioussetofstates,whichnumbersatmostsstates,andlookingatthesuccessorsofeachofthesestates.

Wetaketheunionofatmostssetsofat most sstateseach ,which

requiresO(s2)time. IftheNFAhas€‐transitions,thenwemustcomputethe€‐closure

before starting the simulation. Then the processing of each inputsymbolahastwostages,eachofwhichrequiresO(s2)time.

First,wetaketheprevioussetofstatesandfindtheirsuccessorson

inputsymbola.

Next,wecomputetheε‐closureofthissetofstates.Theinitialsetofstatesforthesimulationistheε‐closureoftheinitialstateoftheNFA.

Lastly, if the representation of L is a regular expression of size.WecanconverttoanNFAwithatmost2sstates,inO(s)time.Wethenperform the simulation above, taking O(ns2) time on an input w oflengthn.

MinimizationofDFA's

Another important consequence of the test for equivalence of states is thatwecan"minimize" DFA's. That is, foreachDFAwecanfindanequivalentDFAthathasasfewstatesasanyDFAacceptingthesamelanguage.

Moreover,exceptforourabilitytocallthestatesbywhatevernameswechoose,thisminimum‐stateDFAisuniqueforthelanguage.Thealgorithmisasfollows:1. First,eliminateanystatethatcannotbereachedfromthestartstate.

Page 70: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

2. Then,partitiontheremainingstatesintoblocks,sotha.tallstatesinthe

sameblockareequivalent,andnopairofstatesfromdifferentblocksareequivalent. Theorem, below, shows that we can always make such apartition.

ReferClassNotesforExamples.

MooreandMealyMachine FAisthemathematicalmodelofamachineandisdefinedbya5‐tuple(Q,∑,δ,q₀,F)

whichdoesnotincludetheinformationaboutoutput.

AfterreadingastringifFAresidesinfinalstate,itsaysthat,thestringis“accepted”byFAelseitsaysthat,thestringis“rejected”.

But ifweneedtoproducesomemoreprecise informationandnotonly ‘accept’or

‘reject’; there are twodifferent types ofmachines,which canbe formulated as FAwithoutput,viz.

1. MooreMachine.2. MealyMachine.

1. MooreMachine: Itisthemachinewithfinitenumberofstatesandforwhich,theoutputsymbolata

giventimedependsonlyuponthepresentstateofthemachine.

In Moore Machine, an output symbol is associated with each state. When themachineisinaparticularstate,itproducestheoutput,irrespectiveofwhattheinputonwhichthetransitionismade.

Page 71: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

ForMooreMachine,If the lengthof the inputsequence isn, thenthe lengthof theoutputsequenceisn+1.

MooreMachineisasix‐tuple: M=(Q,∑,Δ,δ,λ,q₀)Where, Q‐Finitesetofstates ∑‐Finiteinputalphabet Δ‐Finiteoutputalphabet δ‐Statefunction,δ:QX∑→Q λ‐Machinefunction,λ:Q→Δ q₀‐initialstateofthemachine.q₀ЄQ

2. MealyMachine: Itisthemachinewithfinitenumberofstatesandforwhich,theoutputsymbolata

giventimeisa functionofthepresent inputsymbolaswellasthepresentstateofthemachine.

Thus,forthistypeofmachineoutputdependsonbothcurrentstateandthecurrentinputsymbol.

ForMealyMachine, if the lengthof the input sequence isn, then the lengthof the

outputsequenceisn.

Mealymachineisdenotedbyasix‐tuple: M=(Q,∑,Δ,δ,λ,q₀)Where, Q‐finitesetofstates ∑‐finiteinputalphabet Δ‐finiteoutputalphabet δ‐statefunction,δ:QX∑→Q λ‐machinefunction,λ:Q→Δ q₀‐initialstateofthemachine.q₀ЄQ

Page 72: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

ProcedurefortransformingMooreMachinetoMealyMachine:If M₁ =(Q,∑,Δ,δ,λ,q₀) is Moore Macchine, then equivalent Mealy Machine isM₂=(Q,∑,Δ,δ,λ’,q₀)where,

λ’(q,a)=λ(δ(q,a))forallstatesQandinputsymbolsa.ProcedurefortransformingMealyMachinetoMooreMachine:(Dec‐2003,May–2004,Nov–2004)IfgivenMealyMachineis,M₁=(Q,∑,Δ,δ,λ,q₀)then,anequivalentMooremachineis:

M₂=([QXΔ],∑,Δ,δ’,Δ’,[q₀,b₀]),

Where, ‘b₀’is an arbitrarily selectedmember of Δ and δ’([q,b],a) = [δ(q,a),λ(q,a)] and([q,b])=b

Problems:UniversityquestionswillbesolvedinClass:1. GiveMealyandMooremachineforthefollowingprocess:

Forinputfrom(0+1)*,Ifinputendsin101output=AIfinputendsin110output=BOtherwiseoutput=C

(Dec‐2003,May‐2004,May‐2005)

2. DesignMooreandMealymachineforbinaryinputsequencewhichproducesanoutputAif101arerecognizedotherwiseoutputB.

3. ConstructaMealyMachinewhichcanoutputEVENandODDaccordingasthetotalnumberof1’sencounteredisevenorodd.Theinputsymbolsare0and1.

(Nov‐2004)

Page 73: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

4. DesignMooreandMealyMachinetofind1’scomplementofgivenbinarynumber.

(May‐2003)

5. DesignMooreandMealyMachinetoincrementbinarynumberby1

6. DesignMooreandMealyMachinetofind2’scomplementofgivenbinarynumber.(May‐2003,Dec‐2006,Dec‐2007,

June‐2008)

7. DesignMooreandMealymachineforabinaryinputstringgivingoutputastheremainderwhendividedby3.

8. DesignMooreMachineforthefollowingprocess: Forinputfrombinary(0+1)*printtheresiduemodulo3oftheinput.

(Dec‐1999)9. GiveMealyandMooremachineforthefollowing: Forinputfrom∑*,where∑,printtheresiduemodulo5oftheinputtreatedasaternary(base3,withdigits0,1and2number.

(May‐2006)

10. DesignaMooreMachinethatwillreadsequencesmadeupoflettersa,e,I,o,uandwillgiveasoutput,samecharactersexceptwhenan‘i’isfollowedby‘e’,itwillbechangedto‘u’.

11. DesigntheMealymachinefortheabove.12. DesignMooreMachinetoconverteachoccurrenceof100to101.

(Dec‐2000)

13. DesignMealyMachinetoconverteachoccurrenceofsubstringaddbyabaover∑={a,B}.

(Dec‐2006,Dec‐2000)

14. DesignMooreMachinetoconverteachoccurrenceof101to100.

Page 74: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

15. DesignMooreMachinetoconverteachoccurrenceof1000to1001.

(Dec‐2002,Jun‐2008)16. DesignMooreMachinetoconverteachoccurrenceof121to120.

17. DesignMooreMachinetoconverteachoccurrenceof121to021.18. DesignMooreandMealymachinestoconvertsubstring121to122forstringsof

languageshaving∑={0,1,2} (Dec‐2002)

19. DesignMealyMachinetoconvertHEXnumberstoOCTALnumbers.

(Dec‐2005)

20. DesignMooreMachinetoconvertHEXnumberstoOCTALnumbers. (Dec‐2005)

21. ConstructtheMealyMachinetoacceptthelanguage(0+1)*(00+11). (Dec‐2003)

22. ConvertthisMealyMachinetoMooreMachine.

(Dec‐2003)

23. ExplaintheequivalenceofMooreandMealyMachine.DesignaMealyMachineforthelanguage(0+1)*(00+11)andconvertthisMealymachinetoMooreMachine.

(May‐2005)

24. DesignaMooreMachinewhichcountstheoccurrenceofsubstringaabinalonginputstringover{a,b}

(Nov‐2004)

Page 75: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Subjects Taken by Ganesh Sir: 

Semester  Subject  Batch SEM‐VI (Computer) 

SPCC (System 

Programming and Compiler Construction)

Vacation + Regular 

ALL  OCAJP 1.7 (Oracle Certified Associate JAVA Programmer)

Vacation + Regular 

ALL  OCPJP 1.7 (Oracle Certified Professional JAVA Programmer)

Vacation + Regular 

 

Page 76: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Chapter5

Context−freeGrammars We have seen that every finite automata M accepts a language L, which is

representedbyL(M).

Wehaveseenthataregularlanguagecanbedescribedbyaregularexpression. Wehaveseenthatthereareseverallanguageswhicharenotregular.

1. L1={ap|pisaprime}isnotregular.2. L2={anbn|n>=0}isnotregular.

Wehaveseentwowaysofrepresentingalanguage.

1. Usingfiniteautomata.2. Usingaregularexpression.

If a language is not‐regular, it cannot be represented either using a FA or using a

regularexpression.Hencetherewasaneedforrepresentingsuchlanguages.

Grammarisanotherapproachforrepresentingalanguage:1. Inthisapproach,alanguageisrepresentedusingasetofequations.2. Equationsarerecursiveinnature.3. FiniteAutomatahaveasetofstates;agrammarhassetofvariables.4. FiniteAutomataaredefinedoveranalphabet; a grammar isdefinedovera

setofterminals.5. FiniteAutomatahaveasetof transitions;agrammarhasasetofequations

(Productions).

Forbuildinganymodel,weshouldconsidertwoaspectsofthegivengrammar:1. The generative capacity of the grammar i.e., the grammar used should

generateallandonlythesentenceofthelanguageforwhichitiswritten.2. Grammaticalconstituentsliketerminalsandnon‐terminals.

Definition: Grammar is used for specifying the syntax of a language and forrepresentinganon‐regularlanguage.

1. AparsestructuregrammarisdenotedbyaquadrupleoftheformG=(V,T,P,S)

Page 77: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Where, V–isasetofVariables. T–isasetofTerminals. P–isasetofProductions. S–isaspecialvariablecalledthatstartsymbolSЄV.Notations:

1. Terminalsaredenotedbylowercaselettersa,b,c…ordigits0,1,2…etc.2. Variables(Non‐Terminals)aredenotedbycapitallettersA,B…V,W,X….3. AstringofterminalsorawordωЄLisrepresentedusingu,v,w,x,y,z.4. Asententialformisastringofterminalsandvariablesanditisdenotedbyα,β,ϒ…

etc.

Variables:Variablesare those symbols that takepart in thederivationof a sentence,butarenotthepartofderivedsentence.

Terminals:Terminalsarethosesymbolsthatarethepartofderivedsentence.

TheLanguageofAGrammar:

Everygrammargeneratesalanguage.Awordofalanguageisgeneratedbyapplyingproductionsafinitenumberoftimes.

Derivationofastringshouldstartfromthestartsymbolandthefinalstringshouldconsistofterminals.

IfGisagrammarwithstartsymbolSandsetofterminalsT,thenthelanguageofGistheset:

L(G)={ω|ωЄT*andSω}

The*representthat,productioncanbeappliedmultipletime.

Astringcanbederivedfromstartsymbolofthegrammar,usingtheproductionsofthegrammar.

Derivationsarerepresentedeitherinthe:

1. SententialFormOR

*

G

Page 78: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

2. ParseTreeForm

SententialForm:

Letusconsideragrammargivenbelow: SA1B A0A|ɛ B0B|1B|ɛWhereGrammarGisgivenby(V,T,P,S) V={S,A,B} T={0,1} P={SA1B,A0A|ɛ,B0B|1B|ɛ} S={S}Letustrytogeneratethestring‘00101’withabovegrammar.Therearetwodifferentderivationspossible:

1. LeftmostDerivation.2. RightmostDerivation.

LeftmostDerivation: If at each step in a derivation, a production is applied to theleftmostvariable(non‐terminal),thenthederivationiscalledasleftmostderivation.

Example: SA1B (StartVariable) S0A1B (usingA0A)

S00A1B (usingA0A) S001B (usingAɛ)

S0010B (usingB0B)S00101B (usingB1B)S00101 (usingBɛ)

RightmostDerivation: If at each step in a derivation, a production is applied to therightmostvariable(non‐terminal),thenthederivationiscalledasrightmostderivation.

Example:

Page 79: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

SA1B (StartVariable) SA10B (usingB0B)

SA101B (usingB1B) SA101 (usingBɛ)

S0A101 (usingA0A)S00A101 (usingA0A)S00101 (usingAɛ)

ParseTreeForm:

Asetofderivationsappliedtogenerateawordcanberepresentedusingatree.Suchatreeisknownasaparsetree.Aparsetreeisconstructedwiththefollowingcondition:

1. Rootofthetreeisrepresentedbystartsymbol.2. EachinteriormodeisrepresentedbyavariablebelongingtoV.3. Eachleafnodeisrepresentedbyaterminalorɛ.

Theparsetreeisalsocreatedintwoways:

1. Usingleftmostderivations.2. Usingrightmostderivations.

Problems:UniversityquestionswillbesolvedinClass:1. Forthegrammargivenbelow:

SA1BA0A|ɛB0B|1B|ɛ

Giveparsetreeforleftmostandrightmostderivationofthestring‘1001’and‘00101’.2. Forthegrammargivenbelow:

S0S1|01Givederivationof‘000111’.

3. Considerthegrammargivenas:

G=({S,A},{a,b},P,S)WherePconsistsof– SaAS|a

Page 80: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

ASbA|SS|baDerive‘aabaaabbaaa’usingtheleftmostderivationandrightmostderivation.Derive‘aabbaa’usingtheleftmostderivationandrightmostderivation.4. Considerthefollowinggrammar:

SaB|bAAa|aS|bAABb|bS|aBB

Find the leftmost and rightmost derivation for the string: ‘bbaaba’, ‘aaabbabbba’,‘aaabbb’and‘aaaba’.5. Considerthefollowinggrammar:

SXbbaaX|aXXXa|Xb|ɛ

Constructleftmostderivationandrightmostderivationforthestring‘abaabb’.

ContextFreeGrammar(CFG):AcontextfreegrammarGisaquadruple(V,T,P,S)Where, V–isasetofvariable. T‐isasetofterminals. P–isasetofproductions. S–isastartsymbolSЄV.AproductionisoftheformViαwhereViЄVandαisastringofterminalsandvariables.ORDefinition:AGrammarissaidtobeCFGifalltheproductionareoftheform: Aα Where, A‐isavariableand α–issententialform.(Sententialformsmeans,thecombinationofVariablesandTerminals).

Page 81: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Problems:

UniversityquestionswillbesolvedinClass:

1. LetG=(V,T,P,S)betheCFGhavingfollowingsetofproductions.Derivethestring‘aabbaa’usingleftmostderivationandrightmostderivation.

SaAS|aASbA|SS|ba

2. Forthegrammargivenbelow:EE+T|TTT*F|FF(E)|a|b

Givethederivationof(a+b)*a+b.

3. WriteCFGtogenerate:i. Setofallstringsthatstartwith‘a’over∑={a,b}ii. Setofallstringsthatstartandendwithdifferentsymbolover{0,1}iii. Setofallstringsthatstartandendwithsamesymbolover{0,1}iv. Setofallstringsthatcontainover∑={a,b}:

i. Atleast3a’sii. Exactly2a’siii. Atmost1a

4. Drivethegrammarforthegivenlanguages:

i. L={ɛ,a,aa,aaa…}ii. L={a,aa,aaa,aaaa…}iii. L={b,ab,aab,aaab…}

5. Drivethegrammarforthegivenlanguages:

i. L={ωЄ{a,b}*}ii. L={ɛ,ab,aabb,…,anbn}iii. L={ab,aabb,…,anbn}iv. L={ωЄ{a,b}*|ωisapalindromeofoddlength}v. L={ωЄ{a,b}*|ωisapalindromeofevenlengthwith|ω|>0}vi. L={ωЄ{a,b}*|ωisapalindromeofevenandoddlengthwith|ω|>0}

RulesforGrammar:

Page 82: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

1. UnionruleforGrammar:IfalanguageL1isgeneratedbyagrammarwithstartsymbolS1andL2isgeneratedbyagrammarwithstartsymbolS2thentheunionofthelanguagesL1UL2canbegeneratedwithstartsymbolS,where SS1|S2Example:LetthelanguageL1andL2aregivenasbelow: L1={an|n>0} L2={bn|n>0}ProductionsforL1are: S1aS|aProductionsforL2are: S2bS|bThentheproductionsforL=L1UL2canbewrittenas: SS1|S2 S1aS|a S2bS|b

2. ConcatenationruleforGrammar:

IfalanguageL1isgeneratedbyagrammarwithstartsymbolS1andL2isgeneratedbyagrammarwithstartsymbolS2thentheconcatenation(product)ofthelanguagesL1.L2canbegeneratedwithstartsymbolS,where

SS1S2

Example:

LetthelanguageL1andL2aregivenasbelow: L1={an|n>0} L2={bn|n>0}

Page 83: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

ProductionsforL1are: S1aS|aProductionsforL2are: S2bS|bThentheproductionsforL=L1.L2canbewrittenas: SS1|S2 S1aS|a S2bS|b

Problems:

UniversityquestionswillbesolvedinClass:

1. Giveacontextfreegrammarforthefollowinglanguage:0(0+1)*01(0+1)*1

2. Constructthecontextfreegrammarcorrespondingtotheregularexpression:R=(0+1)1*(1+(01)*)

3. GivetheCFGforL={aibj,i<=j<=2i,i>=1}

4. GivetheCFGforL={aibjcq,i+j=q;(i,j)>=1}

5. Findcontextfreegrammarsgeneratingeachoftheselanguages:a. L={aibjck|i=j+k}b. L={aibjck|j=i+k}c. L={aibjck|i=jorj=k}

6. Givethecontextfreegrammarforthefollowinglanguages:

a. (011+1)*(01)*b. 0i1i+k0kwherei,k>=0

Page 84: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

7. Showthatthelanguages:a. L={aibicj|i,j>=1}andb. L={aibjcj|i,j>=1}arecontextfreelanguages.

8. GiveCFGformatchingparenthesis.

9. GiveCFGforallstringswithatleasttwo0’s,∑={0,1}10. GiveCFGforsetofoddlengthstringsin{0,1}*withmiddlesymbol‘1’.

11. GiveCFGforsetofevenlengthstringsin{a,b,c,d}*withtwomiddlesymbolequal.

12. GiveCFGforL={x|xcontainsequalnumberofa’sandb’s}

13. GiveCFGforstringsinab*.

14. GiveCFGforstringsina*b*.

15. FindCFGforgenerating: (Dec‐06,May‐09,Dec‐09)a. Stringcontainingalternatesequenceof0’sand1’s,∑={0,1}b. Thestringcontainingnoconsecutiveb’sbuta’scanbeconsecutivec. Thesetofallstringoveralphabet{a,b}withexactlytwiceasmanya’sasb’s.d. Languagehavingnumberofa’sgreaterthennumberofb’s

16. WriteCFGforthelanguage

∑={a,b}numberofa’sisamultipleof3.

AmbiguousGrammar:

Page 85: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Definition:Agrammarissaidtobeambiguousifthelanguagegeneratedbythegrammarcontainssomestringthathastwodifferentparsetrees.

Example:Letusconsiderthegrammargivenbelow:

EE+E|a|b

Astring(a+b+a)isgeneratedbythegivengrammar.

E

E

EE 

Ea + 

b a

a EE

+

ba

+

+

Fig: Parse Trees considered for ambiguity

(a) 

(b)

Page 86: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Thegrammargenerates(a+b+a)intwodifferentways.ThetwoderivationsareshowninFig(a)and(b).

ThefirstderivationFig(a)saysthat(b+a)isevaluatedfirstandthentheevaluatedvalueisaddedtoa.Thustherightside+operatorgetsaprecedenceovertheleftside+operator.Theexpression(a+b+a)istreatedas(a+(b+a)).

ThesecondderivationFig(b)saysthat(a+b)isevaluatedfirstandthentheevaluatedvalueisaddedtoa.Thustheleftside+operatorgetsaprecedenceovertherightside+operator.Theexpression(a+b+a)istreatedas((a+b)+a).

Removingambiguity:

ThereisnogeneralruleforremovingambiguityfromCFG.RemovingambiguityfromagrammarinvolvesrewritingofgrammarsothatthereisonlyonederivationtreeforeverystringbelongingtoL(G)i.e.,languagegeneratedbygrammarG.

Ambiguityfromthegrammar

EE+E|a|b

Canberemovedbystrictlyassigninghigherprecedencetoleftside+operatoroverrightside+operator.Thiswillmeanevaluationofanexpressionoftheform(a+b+a),fromlefttoright.

Thispropertycanbeincorporatedinthegrammaritselfbysuitablymodifyingthegrammar.

ParsetreeofFig(b)isbasedonlefttorightevaluation.

LefttorightevaluationinGrammarcanbeenforcedbyintroducingonemorevariableT.VariableTcannotbebrokenby+operator.

Anunambiguousgrammarforthegrammarisgivenas:EE+T|TTa|b

Page 87: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

AproductionoftheformEE+Tprovidesabinding.E+T,impliesthatEmustbe

evaluatedfirstbeforeanatomicTcanbeaddedtoit.EcanbebrokendowninE+TbutTcannotbebrokenfurther.Thisensureshigherprecedencetoleftside+operatoroverrightside+operator.

ParsetreeinFig.givenbelowisbasedonunambiguousgrammarforthestring(a+b+a).

Problems:

UniversityquestionswillbesolvedinClass:

1. Considerthegrammar:EE+E|E*E|(E)|IIa|b

Showthatthegrammarisambiguous.Removeambiguity.

E

E  T

aTT 

ba 

+

Fig: A Parse tree for (a+ b +c) using an unambiguous grammar 

Page 88: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

2. ShowthattheCFGgivenbelow.Whichgeneratesallstringsofbalancedparenthesesisambiguous.Giveanequivalentunambiguousgrammar.

SSS|(S)|ɛ

3. WriteanunambiguousCFGforarithmeticexpressionswithoperators:+,*,/,^,unaryminusandoperanda,b,c,d,eandf.Also,ifshouldbepossibletogeneratebracketswithyourgrammar.Derive(a+b)^d/e+(‐f)fromyourgrammar. (Dec2005)

4. IsthefollowingCFGambiguous?SaB|abAaAB|aBABb|bIfso,showmultiplederivationtreesforthesamestring.

5. IsthefollowingCFGambiguous?G=({S,A},{a,b},P,S)Where,PconsistsofSaAS|aASbA|SS|ba

6. Considerthegrammarhavingproductions:SaS|ɛSaSbSThegrammarisambiguous.i. Showinparticularthatthestring‘aab’hastwoparsetrees.ii. Findanunambiguousgrammarforthesame.

7. LetGbethegrammar

SaB|bAAa|aS|bAABb|bS|aBBForstring‘aaabbabbba’findi. Leftmostderivationii. Rightmostderivationiii. ParseTree

Page 89: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

iv. Isthegrammarunambiguous? (Dec‐2009)

8. Ineachcase,showthatthegrammarisambiguous,andfindtheequivalentunambiguousgrammar:i. SSS|a|bii. SABA,AaA|ɛ,BbB|ɛiii. SaSb|aaSb|ɛ

9. Considerthegrammar:

G=({V={E,F}},{T={a,b,‐}},E,P)WherePconsistsofrules:EF–EFaEE–FFbEFi. ShowthatGisambiguousii. Removetheambiguity.

10. Testwhetherthefollowinggrammarsareambiguous:

i. S0S1S|1S0S|ɛii. SAA,AaAb|bAa|ɛ

SimplificationofCFG:

Agrammarwritteninasimpleformiseasytoanalyse.Certainrestrictionsareimposedonsimplifiedgrammar.

SimplificationofCFGinvolvestransformingCFGintoanequivalentformthatsatisfiescertainrestrictionsonitsform.ACFGcanbesimplifiedbyeliminating:1. Uselesssymbols.2. ɛ‐Productions.3. Unitproductions.

Page 90: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

1. Eliminationofuselesssymbols:Agrammarmaycontainsymbolsandproductionswhicharenotusefulforderivationofstrings.Twotypesofsymbolsareuseless.

a. Non–generatingsymbolsb. Nonreachablesymbol.

Non–generatingsymbols:AsymbolXЄV(Setofvariables)isageneratingsymbolif:

Xw

Where,wЄT*i.e.everyvariablemustgenerateastringofterminals.

Example:ConsiderthefollowingGrammar:

SAa|Bb|a|b

AAa|a

BbB

RequiressimplificationasthesymbolBisnon‐generating.OnlyproductionforBis

BbB

anditcannotgenerateastringofterminals.TheGrammarcanbesimplifiedbydeletingeveryproductioncontainingtheuselesssymbolB.Asimplifiedgrammarisgivenas:

SAa|a|b

AAa|a

Agrammarcontaininganon‐generatingsymbolVishouldbesimplifiedbydeletingeveryproductioncontainingthenon‐generatingsymbolVi.

Findingnon‐generatingsymbols:

Therearetworulesforfindingasetofgeneratingsymbolsforthegivengrammar.

1. EverysymbolinT(terminal)isgenerating.2. IfthereisaproductionAαandeverysymbolinαisgenerating,thenAis

generating.Where,αЄ(V+T)*

Page 91: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Asymbolnotinasetofgeneratingsymbolsissaidtobenon‐generating.

ProblemsonNon‐generatingsymbols:UniversityquestionswillbesolvedinClass:1. Findnon‐generatingsymbolsinthegrammargivenbelow

SAB|CABBC|ABAaCaB|b

2. Findnon‐generatingsymbolsinthegrammargivenbelowSaAaASb|bCCCabbEaC

3. Findnon‐generatingsymbolsinthegrammargivenbelowSaAaASb|bCC|DaACabb|DDEaCDaDa

Non‐reachableSymbols:AsymbolXisreachableifitcanbereachedfromthestartsymbolS.i.e.if:

andαcontainsavariableXthenXisreachable.

Agrammarcontaininganon‐reachablesymbolVishouldbesimplifiedbydeletingeveryproductioncontainingthenon‐reachablesymbolVi.

Page 92: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Findingnon‐reachablesymbols:

Non‐reachablesymbolscanbelocatedwiththehelpofadependentlygraph.AvariableXissaidtobedependentonSifthereisaproduction:

Sα1Xα2

Wemustdrawadependencygraphforallproductions.IfthereisnopathfromthestartsymbolStoavariableX,thenXisnon‐reachable.

ProblemsonNon‐reachablesymbols:

UniversityquestionswillbesolvedinClass:

1. Eliminatenon‐reachablesymbolsfromthegivengrammar:SaAaASb|bCCCabbEaC

2. Eliminatenon‐reachablesymbolsfromthegivengrammar:SaBa|BCAaC|BCCCaBbCCDEEd

3. Eliminatenon‐reachablesymbolsfromthegivengrammar:SaAaAbBBBabCaB

4. Eliminatenon‐reachablesymbolsfromthegivengrammar:

Page 93: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

SaS|ABAbABAA

2. Eliminationofɛ‐productions:

AproductionoftheformAɛ,iscalledanullproductionsorɛ‐production.ForeverycontextfreegrammarGwithɛ‐productions,wecanfindacontext‐freegrammarG1havingnoɛ‐productionssuchthat

L(G1)=L(G)–{ɛ}

TheprocedureforfindingG1isasfollows:

Step1:Findnullablevariables.

Step2:Additionofproductionswithnullablevariablesremoved.

Step3:Removeɛ‐productions.

Problemsoneliminationofɛ‐productions:

UniversityquestionswillbesolvedinClass:

1. Eliminatetheɛ‐productionfromthegrammargivenbelow:SaSSɛ

2. Eliminatetheɛ‐productionfromthegrammargivenbelow:SABAAɛBɛ

3. Eliminatetheɛ‐productionfromthegrammargivenbelow:SaS|ABAɛ

Page 94: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

4. Eliminatetheɛ‐productionfromthegrammargivenbelow:SABAAaA|ɛBbB|ɛ

5. Eliminatetheɛ‐productionfromthegrammargivenbelow:SABAaAA|ɛBbBB|ɛ

3. EliminationofUnitProductions:

AproductionoftheformABisknownastheunitproductionwhereAandBarevariables.

ForeverycontextfreegrammarGwithunitproductions,wecanfindacontextfreegrammarG1havingnounitproductionssuchthat

L(G1)=L(G)

TheprocedureforfindingG1isasfollows:

Thetechniqueisbasedonexpansionofunitproductionuntilitdisappears.Thistechniqueworksinmostofthecases.ThistechniquedoesnotworkifthereisacycleofunitproductionssuchasA1A2A2A3A3A4A4A1

Thestepsforeliminationofunitproductionsareasfollows:

STEP1:Addallnon‐unitproductionofGtoG1.

STEP2:Locateeverypairofvariables(Ai,Aj)suchthat

AiAj

G * 

Page 95: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

STEP3:Frompairsconstructedinstep2,wecanconstructachainlikeA1A2…Ajαisanon‐unitproduction.

EachvariableAitoAjwillderiveα.

ProblemsonEliminationofUnitProductions:

UniversityquestionswillbesolvedinClass:

1. Eliminateunitproductionsform:SABA|BA|AA|AB|A|BAaA|aBbB|b

2. Eliminateunitproductionsfromthegrammar:EE+T|TTT*F|FF(E)|IIa|b|Ia|Ib|I0|I1

3. Simplifythefollowinggrammar:SASB|ɛAaAS|aBSbS|A|bb

4. Simplifythefollowinggrammar:S0A0|1B1|BBACBS|ACS|ɛ

5. Simplifythefollowinggrammar:SAbAaBC|bCD

Page 96: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

DEEa

6. Findareducedgrammarequivalentto:SaC|SBAbSCaBaSB|bBCCaBC|ad

NormalformsforCFG:ProductionsinG,satisfyingcertainrestrictionsaresaidtobeinnormalform.TherearetwonormalformsforCFG.

1. ChomskyNormalForm(CNF)2. GreibachNormalForm(GNF)

1. ChomskyNormalForm(CNF): (Dec‐

2009)

Acontextfreegrammar(CFG)withoutɛ‐productionissaidtobeinCNFifeveryproductionisoftheform:

1. ABC,whereA,B,CЄV.2. Aa,whereAЄVandaЄT.

Thegrammarshouldhavenouselesssymbols.EveryCFGwithoutɛ‐productionscanbeconvertedintoanequivalentCNFform.

AlgorithmforCFGtoCNFConversion:

1. Eliminateɛ‐productions,unitproductionsanduselesssymbolsfromthegrammar.

2. Everyvariablederivingastringoflength2ormoreshouldconsistonlyofvariables.i.e.everyproductionoftheformAαwith|α|≥2,αshouldconsistonlyofvariables.

Page 97: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Examples:ConsideraproductionAV1V2aV3bV4.Terminalsymbols‘a’and‘b’canberemovedbyrewritingtheproduction AV1V2aV3bV4as AV1V2CaV3CbV4

Andaddingtwoproductions

Caa and

Cbb

3. Everyproductionderiving2ormorevariables(Aαwith|α|≥3)canbebrokendownintoacascadeofproductionswitheachderivingastringoftwovariables.Examples:ConsideraproductionAX1X2…Xnwheren≥3andasXi’sarevariables.TheproductionAX1X2…Xnshouldbebrokendownasgivenbelow: AX1C1 C1X2C2 C2X3C3 : Cn‐2Xn‐1Xneachwithtwovariablesontheright.ProblemsonCFGtoCNFconversion:UniversityquestionswillbesolvedinClass:1. FindtheCNFequivalentto:

SaAbBAaABbB|b

2. ConvertthegrammargivenbelowtoitsequivalentCNF:SPQPP0P|ɛQ1Q|ɛ

3. CheckwhetherthegivengrammarisinCNF:

Page 98: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

SbA|aBAbAA|aS|aBaBB|bS|b

IfitisnotinCNF,findtheequivalentCNF.

4. DesignaCNFgrammarforthesetofstringsofbalancedparenthesis.

5. ConvertthefollowinggrammartoCNF:

SAbaSaabBAc

6. ConvertthefollowinggrammartoCNF:SAACDAaAb|ɛCaC|aDaDa|bDb|ɛ

7. GivenaCFGG,findG’inCNFgeneratingL(G)‐ɛ (May‐2006,May‐2009)

SASB|ɛ

AAaS|a

BSbS|A|bb

8. ConvertthegivengrammartoCNFSaSB|aAAAa|Sa|a

2. GreibachNormalForm(GNF):(Dec‐2005,May‐2007,Dec‐2008,Dec‐2009)

AContextfreegrammarG=(V,T,P,S)issaidtobeinGNFifeveryproductionisoftheform:

Aaα

Page 99: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Where,aЄTisaterminalandαisastringofzeroormorevariables.ThelanguageL(G)shouldbewithoutɛ.Righthandsideofeachproductionshouldstartwithaterminalfollowedbyastringofnon‐terminalsoflengthzeroormore.

RemovingLeftRecursion:

EliminationofleftrecursionisanimportantstepinalgorithmusedinconversionofaCFGintoGNFform.

Leftrecursivegrammar:AproductionoftheformAAαiscalledleftrecursiveasthelefthandsidevariableappearsasthefirstsymbolontherighthandside.

Languagegeneratedbyleftrecursivegrammar:LetusconsideraCFGcontainingproductionsoftheform

AAα …[Leftrecursive]

Aβ …[Forterminationofrecursion]

Thelanguagegeneratedbyaboveproductionsis:

AAα

AAαα …usingAAα

AAααα …usingAAα

:

AAαn …usingAAα

Aβαn …usingAβ

Rightrecursivegrammarforβαn:Arightrecursivegrammarforβαncanbewrittenas:

AβB|β

BαB|α

Thusaleftrecursivegrammar

AAα|β

Page 100: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

canbewrittenusingarightrecursivegrammaras:

AβB|β

BαB|α

ProblemsonconversionofLeftRecursivegrammartoRightRecursivegrammar:

1. AAa|b2. AAa|b|c3. AABC|BC4. AABC|DA|EC5. SS10|0

AlgorithmforconversionfromCFGtoGNF:

1. Eliminateɛ‐productions,unitproductionsanduselesssymbolsfromthegrammar.

2. InproductionoftheformAX1X2…Xi…Xn,otherthanX1,everyothersymbolshouldbeavariable.X1couldbeaterminal.Example:consideraproduction AV1V2aV3bV4 as AV1V2CaV3CbV4 andaddingtwoproductions

Caa and

Cbb

Thus,attheendofstep2allproductionsmustbeoftheforms:

Aa

Aaα

Where,‘a’isaterminalandαisastringofnon‐terminals.

3. RenamevariablesasA1,A2,A3…AntocreateA‐productions.Example:Consideragrammargivenbelow

Page 101: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

SaXSY|YSX|b

ThevariablesS,XandYcanberenamedasA1,A2andA3respectively.Thenthebecomes

A1aA1A2A3|A1A2A3|b

4. ModifytheproductionstoensurethatifthereisaproductionAi>AjαthenIshouldbe≤j.IfthereisaproductionAiAjαwithi>j,thenwemustgenerateproductionssubstitutingforAj.

5. Repeatingstep4,severaltimeswillguaranteethatforeveryproductionAiAjα,i≤j.

6. RemoveleftrecursionfromeveryproductionoftheformAkAkα.B‐productionsshouldbeaddedtoremoveleftrecursion.

7. ModifyAi‐productiontotheformAiaα,where‘a’isaterminalandαisastringofnon‐terminals.

8. ModifyBi‐productionstotheformBiaα,where‘a’isaterminallandαisastringofnon‐terminals.

ProblemsonCFGtoGNFconversion:

UniversityquestionswillbesolvedinClass:

1. ConstructagrammarinGNFwhichisequivalenttothegrammar

SAA|a

ASS|b

2. FindthegrammarinGNFforthegivenCFGEE+T|TTT*F|FF(E)|a

3. GivetheGNFforfollowingCFG

Page 102: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

SABABS|bBSA|a

4. ReducethefollowinggrammartoGNFSABABSB|BB|bBaAb|a

5. ConvertthefollowinggrammartoGreibachNormalForm(GNF)SBSSAaAbcBAc

6. FindGNFofthegrammargivenbelow (Dec‐2008)SABAb|abBABA|aAa|b

7. FindtheGNFequivalenttotheCFGSABAaA|bB|bBb

8. FindaGNFgrammarequivalenttothefollowingCFG (May‐2009)

SBA|ab

BAB|a

ABb|BB

9. ConvertthegivengrammartoGNF (Dec‐2009)

SSS|aSb|ab

10. ConvertthefollowinggrammarintoGNF (May‐2006)

SXY1|0X00X|Y

Page 103: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Y1X111. ConvertthefollowingCFGtoGNF (Dec‐

2005)

SaSa|bSb|c

RegularGrammar

Definition:Thelanguageacceptedbyfiniteautomatacanbedescribedusingasetofproductionsknownasregulargrammar.Theproductionsofaregulargrammarareofthefollowingform:

Aa

AaB

ABa

Where,aЄTandA,BЄV.

Alanguagegeneratedbyaregulargrammarisknownasregularlanguage.Aregulargrammarcouldbewrittenintwoforms:

1. Right‐linearform2. Left‐linearform

Right‐LinearForm:Arightlinearregulargrammarwillhaveproductionofthegivenform.

Aa

AaB

Page 104: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Note:VariableBinAaBisthesecondsymbolontheright.

Left‐LinearForm:Aleftlinearregulargrammarwillhaveproductionsofthefollowingform:

Aa

ABa

Note:VariableBinABaisthefirstsymbolontheleft.

DFAtoRightLinearRegularGrammar:

EveryDFAcanbedescribedusingasetofproductionusingthefollowingsteps:

1. LettheDFA,M=(Q,∑,δ,q0,F)LetthecorrespondingrightlineargrammarbeG=(V,T,P,S).

2. Renameq0ЄQasSЄV,relatingstartstateofMwithstartingsymbolofG.

3. RenamestatesofQasA,B,C,D…where,A,B,C,D…ЄV.4. CreatingasetofproductionP.

a. Ifq0ЄFthenaddaproductionSɛtoP.

b. Foreverytransitionoftheform,AddaproductionBaC,whereCisanon‐acceptingstate.

c. Foreverytransitionoftheform,

B a 

B  C a 

Page 105: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

AddtwoproductionsBaC,Ba,whereCisanacceptingstate.

DFAtoLeftLinearRegularGrammar:

FollowingstepsarerequiredtowritealeftlineargrammarcorrespondingtoaDFA.1. Interchangestartingstateandthefinalstate.2. Reversethedirectionofallthetransitions.3. Writethegrammarfromthetransitiongraphinleft‐linearform.

RightLinearGrammartoDFA:

EveryrightlineargrammarcanberepresentedusingaDFA:

1. AproductionoftheformAaBwillgenerateatransition

fortheDFA.

2. AproductionoftheformAaB|awillgenerateatransition

providedeverytransitionenteringBterminatesinB.

3. AProductionoftheformAɛwillmakeAafinalstate.

A a 

A  B a 

Page 106: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

4. AnindependentproductionoftheformAb,willgenerateatransition

Where,Fisanewstateanditshouldbeafinalstate.

LeftLinearGrammartoDFA:

EveryleftlineargrammarcanberepresentedusinganequivalentDFA.FollowingstepsarerequiredtodrawaDFAforagivenleftlineargrammar.

1. Drawatransitiongraphfromthegivenleftlineargrammar.2. Reversethedirectionofallthetransitions.3. Interchangestartingstateandthefinalstate.4. CarryoutconversionfromFAtoDFA.

RightLinearGrammartoLeftLinearGrammar:

Fig:FromRightLinearGrammartoLeftLinearGrammar.

Everyrightlineargrammarcanberepresentedbyanequivalentleftlineargrammar.Theconversionprocessinvolvesdrawingofanintermediatetransitiongraph.Followingstepsarerequired:

A  F b 

ɛ 

Right Linear Grammar

Transition Graph

Left Linear Grammar

Page 107: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

1. Representtherightgrammarusingatransitiongraph.Markthefinalstateas2. Interchangethestartandthefinalstate.3. Reversethedirectionofalltransitions.4. Writeleft–lineargrammarfromthetransitiongraph.

LeftLinearGrammartoRightLinearGrammar:

Fig:FromLeftLinearGrammartoRightLinearGrammar.

Everyleftlineargrammarcanberepresentedbyanequivalentrightlineargrammar.Theconversionprocessinvolvesdrawingofanintermediatetransitiongraph.Followingstepsarerequired:

1. Representtheleftgrammarusingatransitiongraph.Markthefinalstateas2. Interchangethestartandthefinalstate.3. Reversethedirectionofalltransitions.4. Writeright–lineargrammarfromthetransitiongraph.

Problems:

UniversityquestionswillbesolvedinClass:

1. Constructrightlineargrammarandleftlineargrammarforthelanguage(ba*).

2. Convertthefollowingright‐lineargrammartoanequivalentDFA:SbBBbC

ɛ 

Left Linear Grammar

Transition Graph

Right Linear Grammar

Page 108: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

BaBCaBb

3. ConvertfollowingRGtoDFA:S0A|1BA0C|1A|0B1B|1A|1C0|0A

4. FinaltheequivalentDFAacceptingtheregularlanguagedefinedbytherightlineargrammargivenas:

SaA|bBAaA|bc|aBaB|bCbB

5. ConstructDFAacceptingtheregularlanguagegeneratedbytheleftlineargrammargivenbelow:

SCa|BbCBbBBa|b

6. ConstructDFAacceptingthelanguagegeneratedbytheleftlineargrammargivenbelow:

SB1|A0|C0BB1|1AA1|B1|C0|0CA0

7. Convertthefollowingrightlineargrammartoanequivalentleft‐lineargrammar:SbB|bBbCBaBCaBb

Page 109: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

8. Writeanequivalentleftlineargrammarfromthegivenrightlineargrammar:

S0A|1BA0C|1A|0B1B|1A|1C0|0A

9. Forrightlineargrammargivenbelow,obtainanequivalentleftlineargrammar:S10A|01A00A|1

10. Writeanequivalentrightlineargrammarfromthegivenleftlineargrammar:SC0|A0|B1AA1|C0|B1|0BB1|1CA0

11. Constructtherightlineargrammarcorrespondingtotheregularexpression:R=(0+1)1*(1+(01)*)

12. Writeanequivalentrightrecursivegrammarforthegivenleftrecursivegrammar:SS10|0

13. Constructtherightlineargrammarcorrespondingtotheregularexpression:R=(1+(01)*)1*(0+1)

14. DrawNFAacceptingthelanguagegeneratedbygrammarwithproductions:SabA|bB|abaAb|aB|bABaB|aA

15. Constructrightlinearandleftlineargrammarforthelanguage:L={anbm,n≥2,m≥3}

16. Constructleftlinearandrightlineargrammarforthelanguage:0*(1(0+1))*

Page 110: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

17. Constructleftlinearandrightlineargrammarforthelanguage:

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

18. Constructleftlinearandrightlineargrammarforthelanguage:(((01+10)*11)*00)*

19. Describethelanguagegeneratedbythefollowinggrammar:SbS|aA|ɛAaA|bB|bBbS

20. FindtheCFLassociatedwithCFG:S0Q|1PP0|0S|1PPQ1|1S|0QQ

Page 111: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

Subjects Taken by Ganesh Sir: 

Semester  Subject  Batch SEM‐VI (Computer) 

SPCC (System 

Programming and Compiler Construction)

Vacation + Regular 

ALL  OCAJP 1.7 (Oracle Certified Associate JAVA Programmer)

Vacation + Regular 

ALL  OCPJP 1.7 (Oracle Certified Professional JAVA Programmer)

Vacation + Regular 

Page 112: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

Chapter6

PushdownAutomata(PDA)

IntroductiontoPushdownAutomata(PDA): (Dec‐2005)

The context‐free languages have a type of automaton that defines them. Thisautomaton, called a "pushdown automaton,'' is an extension of thenondeterministic finite automatonwith ε‐transitions,which is one of theways todefinetheregularlanguages.

Thepushdownautomatonisessentiallyanε‐NFAwiththeadditionofastack.Thestack can be read, pushed, and popped only at the top, just like the "stack" datastructure.

Inthischapter,wedefinetwodifferentversionsofthepushdownautomaton:1. onethatacceptsbyenteringanacceptingstate,likefiniteautomatado,and2. anotherversionthatacceptsbyemptyingitsstack,regardlessofthestateitis

in.

Informally, pushdown automata can be viewed as finite automata with stack. Anaddedstackprovidesmemoryandincreasesthecapabilityofthemachine.

Apushdownautomatacandothefollowings:1. Readinputsymbol[asincaseofFA].2. Performstackoperations:

Pushoperation Popoperation Checkemptyconditionofastackthroughaninitialstacksymbol. Readtopsymbolofstackwithoutapop.

3. Makestatechanges.

Page 113: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

PDAismorepowerfulthanFA.Acontext‐freelanguage(CFL)canberecognizedbyaPDA.OnlyasubsetofCFLthatareregularcanberecognizedbyfiniteautomata.

1. AcontextfreelanguagecanberecognizedbyPDA.2. Foreverycontext‐freelanguage,thereexistsaPDA.3. ThelanguageofPDAisacontext‐freelanguage.

Example: A stringof the formanbn cannotbehandledby a finite automaton.But thesamecanbehandledbyaPDA.

1. Anymachinerecognizingastringoftheformanbn,mustkeeptrackofa’sasnumberofb’smustbeequaltothenumberofa’s.

2. Firsthalfofthestringcanberememberedthroughastack.

3. Asthemachinereadsthefirsthalfofanbn,itremembersitbypushingitontopofthestack.AsshowninFig.afterreadingfirst5a’s,thestackcontains5b’s.

4. Whilereadingthesecondhalfoftheinputstringconsistingofb’s,themachinepopsoutan‘a’fromthestackforevery‘b’asinput.

a  a  a a  a  b  b b b b Input

Finite State 

Control 

a

a

a

a

a

Fig: Structure of PDA 

Page 114: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

5. After reading 5 b’s, input will finish and the stack will become empty. This willindicatethattheinputstringisoftheformanbn.

6. Themachinewillhavetwostatesq0andq1:a. Stateq0–whilethemachineisreadinga’s.b. Stateq1–whilethemachineisreadingb’s

7. Whileinstateq0aninput‘a’isnotallowedandhencethereisaneedfortwostates.

8. AtransitioninPDAdependson:

a. Currentstateb. Currentinputc. Topsymbolofthestack

9. Atransition inPDAcanbeshownasadirectededge fromthestateqi toqj.While

movingtostateqj,themachinecanalsoperformstackoperation.Atransitionedgefrom qi to qj should bemarkedwith current input, current stack symbol and thestackoperation.Itisshowninbelowfig:

10. APDAusesthreestackoperations:a. Popoperation,itremovesthetopsymbolfromthestack.b. Pushoperation,itinsertsasymbolontothetopofthestack.c. Nopoperation,itdoesnothingtostack.

11. Thelanguage{anbn|n>=1}canbeacceptedbythePDAofFig:

qi  qj 

Input symbol, Stack symbol (top most) 

Stack operation 

Fig: A transition from qi to qj 

Page 115: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

12. The state q0 will keep track of the number of a’s in an input string, by pushingsymbol ‘a’onto thestack foreach input ‘a’.A secondstateq1 isused topopan ‘a’fromthestackforeachinputsymbol‘b’.Finally,afterconsumingtheentireinputthewillbecomeempty.

TheFormalDefinitionofPDA:PushDownAutomata:

PDAconsistsofread‐onlyinputtape.InadditionithasastackcalledPushdownStore(PDS).Itisaread‐writepushdownstoreasweaddelementsfromPDS.

PDAconsistsoffinitesetofstates,oneinitialandoneormorefinalstates.

After the input symbol is read the machine can remain in the same state orchangethestate,atthesametimeitcanpushasymbolonthestackorpopthetopmostsymbolorperformneitherpushnorpop.

q0  q1 

(b, a) 

Pop(a) 

(b, a) 

Pop(a) a, any 

Pop(a) 

Fig: PDA for anbn

Page 116: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

APDAisa7‐tuple P=(Q,∑,Γ,δ,q₀,Z₀,F)where,∑:Afinitesetofinputsymbols,alsoanalogoustothecorrespondingcomponent ofafiniteautomaton.Γ:Afinitestackalphabet.Thiscomponent,whichhasnofinite‐automatonanalog,isthesetofsymbolsthatweareallowedtopushontothestack.δ: The transition function. As for a finite automaton, δ governs the behavior of theautomaton.Formally,δtakesasargumentatripleδ(q,a,X),where:

1. qisastateinQ.2. aiseitheraninputsymbolinΣora=ε,theemptystring,whichisassumednot

tobeaninputsymbol.3. Xisastacksymbol,thatis,amemberofΓ.

q0:Thestartstate.ThePDAisinthisstatebeforemakinganytransitions.

Z0: The start symbol. Initially, the PDA's stack consists of one instance of thissymbol,andnothingelse.F:Thesetofacceptingstates,orfinalstates.

AGraphicalNotationforPDA's Sometime,adiagram,generalizingthetransitiondiagramofafiniteautomaton,will

makeaspectsofthebehaviorofagivenPDAclearer.

Page 117: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

@Ban

 

 

 

@Ban

 

Weinw

1.

2.

3.

The

sym

CHndra:986

CHndra:986

shalltherwhich:

ThenodesAn arrowaccepting,The arcs clabeleda,X(p,α),perused,anda

Figure

eonlythingmbol.Conv

HOP67 843 85

HO67 843 85 F

reforeintr

scorrespon

labeled Stasforfinit

correspondX/α:fromhaps amoalsogivest

:Represent

gthattheentionally,

PRA54 @ThanFor Doub

OPR54 @ThanFor Doub

roduceand

ndtothest

tart indicatteautomata

d to transistateqtongother ptheoldand

tingaPDA

diagramditisZ0,un

A ACne:9867 8bts Conta

RA Ane:9867 8ts Contac

subsequen

tatesofthe

tes the staa.

itions of thstatepmpairs. Thanewtops

asagener

doesnottenlessweind

CAD843 853 @act Ganes

ACA843 853 @ct Ganes

ntlyuseat

ePDA.

rt state, an

hePDA in tmeansthatat is, the aofthestack

ralized tran

ellusiswhdicateothe

DEM@Vashi :9sh Sir@83

ADE@Vashi :9h Sir@83

transitiond

nd doubly

the followiδ(q,a,X)arc label tek.

nsitiondiag

hichstackserwise.

MY 9867 8433 84 82 0

EMY9867 8433 84 82 0

diagramfo

circled sta

ing sense.containsthellswhat in

gram

symbolist

3 852 05 75

Y 3 852 5 75

orPDA's

ates are

An archepairnput is

hestart

Page 118: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

InstantaneousDescriptionofaPDA:LetP=(Q,∑,Γ,δ,q₀,Z₀,F)beaPDA.AnIDis(q,x,α) qЄQ,xЄ∑* αЄΓ*say (q,a₁a₂…an,z₁z₂…zm)isanIDThisdescribesthePDAwhenthecurrentstateisq,theinputstringtobeprocessedisa₁a₂…anandthepdshasz₁z₂…zmwithz₁atthetopandzmlowest.Definition:LetPbeaPDAAmoverelation(denotedby|‐)betweenID’sisdefinedas (q,a₁a₂…an,z₁z₂…zm)|‐(q’,a₂,…anβz₂…zn)Ifδ(q,a₁,z₁)contains(q’,β)i.e.PDAinstateofwithz₁z₂…zminPDS(z₁isatthetop)readstheinputsymbola₁,thePDAmovestostateq’andwriteβonthetopofz₂,…zm.Afterthistransition,theinputstringtobeprocesseda₂a₃,…an.Example: P=({q₀,q₁,q₂},{a,b,c},{a,b,z₀},δ,q₀,z₀,{q₂})

δ: δ(q₀,a,z₀)={(q₀,az₀)} δ(q₀,a,q)={(q₀,aa)}δ(q₀,a,b)={(q₀,ab)} δ(q₀,b,z₀)={(q₀,bz₀)}δ(q₀,b,a)={(q₀,ba)} δ(q₀,b,b)={(q₀,bb)}δ(q₀,c,a)={(q₁,a)} δ(q₀,c,b)={(q₁,b)}δ(q₀,c,z₀)={(q₁,z₀)} δ(q₁,a,a)={(q₁,Є)}δ(q₁,b,b)={(q₁,Є)} δ(q₁,Є,z₀)={(q₂,z₀)}

Page 119: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

Inputsequence“bacab” (q₀,bacab,z₀) (q₀,acab,bz₀) (q₀,cab,abz₀) (q₁,ab,abz₀) (q₁,b,bz₀) (q₁,Є,z₀) (q₁,Є,z₀)Thus(q₀,bacab,z₀)|‐*(q₂,z₀)

AcceptancebyPDA:PDAbyFinalStateMethod:Definition: LetP=(Q,∑,Γ,δ,q₀,Z₀,F)bePDA.Thelanguageacceptedbyfinalstateisdefinedas WЄ∑*|‐(q₀,w,z₀)|‐(qf,Є,α) qfЄFαЄΓ*PDAbyNullStoreMethod:Definition: LetP=(Q,∑,Γ,δ,q₀,Z₀,F)beaPDA.Thesetacceptedbynullstore(oremptystore)isdefinedas WЄ∑*|‐(q₀,w,z₀)|‐(qf,Є,Є)forsomeqЄQ.

Problems:

Page 120: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

UniversityquestionswillbesolvedinClass:1. DesignaPDAtoacceptstringsoftypeanbn. (May‐2004)

2. DesignaPDAtoacceptstringsoftype0n1n. (Dec‐2006)3. DesignaPDAtoacceptstringsoftypeanb2n.4. DesignaPDAtoacceptstringsoftypea2nbn.5. DesignaPDAtoacceptstringsoftype0n12n+1. (Dec‐2002)6. DesignaPDAtoaccept(bdb)n. (Dec‐2005)7. DesignaPDAtoaccept(bdb)ncn. (Dec‐2005)8. DesignaPDAwhichacceptsthestringscontainingequalno.ofa’sandb’s.

(Dec‐2002,May‐2003,May‐2004)

9. DesignaPDAtoacceptstringsoftype(ab)ncn.

10. DesignaPDAtoaccept(ab)n(cd)n. (Jun‐2007)11. ConstructaPDAthatacceptsthelanguage–{anbman+m|m,n≥1}12. ConstructaPDAMaccepting{anbman|m,n≥1}bynullstore.(Dec‐2002,Dec‐2006)13. DesignaPDAtocheckforwell‐formednessofparenthesis. (Dec‐2006)14. DesignDPDAacceptingbalancedstringofbrackets. (Nov‐2004)15. DesignDPDAtoacceptstringswithmorea’sthanb’s.16. ConstructaPDAthatwillrecognizethelanguage

L={WCWR|WЄ{a,b}*WR–reverseofW}(Dec‐2003,May‐2005,May‐2007,Jun‐2008)

Page 121: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

17. ConstructaPDAthatwillrecognizethelanguage

L={WWR|WЄ{a,b}*WR–reverseofW}(evenpalindrome)(Dec‐2005,May‐2005,May‐2006,Jun‐2007)

18. DesignthePDAtoacceptthelanguagecontainingalloddlengthpalindromesover∑={0,1} (Dec‐2007)

PushdownAutomataandContext–freeLanguages: There is a general relation between Context – free Languages and NPDA. In the

followingsectionweseethatforeverycontext–freelanguagethereisaNPDAthatacceptsitandconversely,thatthelanguageacceptedbyanyNPDAiscontext–free.

Theorem:Foranycontext–freelanguageL,thereexistsanNPDAMsuchthat L=L(M)Proof:IfLisЄ–freecontextfreelanguage,thereexistsaCFGinGreibachNormalFormforit.Let G = (V, T, S, P) be such a grammar.We then construct anNPDAwhich simulatesleftmostderivationsinthisgrammar.Assuggested,thesimulationwillbedonesothattheunprocessedpartofthesententialformisinthestack,whiletheterminalprefixofany sentential formmatches the correspondingprefixof the input string. Specifically,theNPDAwillbe M=({q₀,q₁,qf},T,VU{z},δ,q₀,z,{qf}),wherezЄV.NotethattheinputalphabetofMisidenticalwiththesetofterminalsofGandthatthestackalphabetcontainsthesetofvariablesofthegrammar. Thetransitionfunctionwillinclude δ(q₀,Є,z)={(q₁,Sz)}

Page 122: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

sothatafterthefirstmoveofM,thestackcontainsthestartsymbolSofthederivation.(thestackstartsymbolzisamarkertoallowustodetecttheendofthederivation.).Inaddition,thesetoftransitionrulesissuchthat (q₁,u)Є(q₁,a,A) Whenever A→auisinp.ThisreadsinputaandremainingvariableAfromthestackreplacingitwithu.InthiswayitgeneratesthetransitionsthatallowthePDAtosimulateallderivations.Finally,wehave δ(q₁,Є,z)={(q,z)}togetMintoafinalstate.ToshowthatMacceptsanywЄL(G),considerthepartialleftmostderivation S=>a₁a₂…anA₁A₂…Am =>a₁a₂…anbB₁B2…BkA2…Am.IfM is to simulate this derivation, then after reading a₁a₂…an, the stackmust containA₁A₂…Am.Totakethenextstepinthederivation,Gmusthaveaproduction A₁→bB₁B₂…Bk

ButtheconstructionissuchthatthenMhasatransitionruleinwhich δ(q₁,B₁…Bk)Єδ(q₁,b,A₁),sothatthestacknowcontainsB₁…BkA2…Amafterhavingreada1a2…an.Asimpleinductionargumentonthenumberofstepsinthederivationshowsthatif S=>w,Then (q₁,w,Sz)|‐(q₁,Є,z),Nowwehave, (q₀,w,z)|‐(q₁,w,Sz)|‐(q₁,Є,z)|‐(qf,Є,z),SothatL(G)C_L(M).ToprovethatL(M)C_L(G),letwЄL(M).thenbydefinition. (q₀,w,z)|‐(qf,Є,u).

Page 123: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

Butthereisonlyonewaytogetfromq₀toq₁andonlyonewayfromq₁toqf.Thereforemusthave (q₁,w,Sz)|‐(q₁,Є,z),Nowletuswritew=a₁a₂a3…an.Thenthefirststepin (q₁,a₁a₂a3…an,Sz)|‐(q₁,a₂a3…an,u₁z).ButthenthegrammarhasaruleoftheformS→a₁u₁,sothat S=>a₁u₁.Repeatingthis,writingu₁=Au₂z)|‐(q₁,a3…an,u3u2z)

(q₁,a₂a3…an,Au₂z)|‐(q₁,a3…an,u3u2z).ImplyingthatAa₂u3isinthegrammarandthat

Sa₁a₂u3u2.This makes it quite clear at any point the stack contents are identical with theunmatchedpartofthesententialform,sothat Sa₁a₂a3...an.Intheconsequence,L(M)subsetofL(G),completingtheproofifthelanguagedoesnotcontainɛ.

Problems:UniversityquestionswillbesolvedinClass:1. ConstructaPDAequivalenttothefollowinggrammar: (Nov‐2004,May‐

2005)SaAAAaS|bS|a

2. ConstructthePDAequivalenttothefollowingCFG: (May‐2006,Dec‐2007)S0BB

Page 124: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

B0S|1S|0Testwhether010000isinthelanguage.

3. ConstructaPDAequivalenttothefollowinggrammar”SaAAaABC|bB|aBbCc

4. ConstructaPDAequivalenttothefollowinggrammar: (Dec‐2003)SaSa|bSb|c

5. ConstructaPDAequivalentthefollowinggrammar:EE+E|E*E|(E)|id(Dec‐2003,May‐2004,Nov‐2004)

6. DesignPDAforthefollowingCFG: (Dec‐2009)S(S)|SS|^

7. WriteCFGforlanguagehavingnumberofa’sgreaterthannumberofb’sandDesignaPDAforthesame. (Dec‐2009)

Page 125: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

Subjects Taken by Ganesh Sir: 

Semester  Subject  Batch SEM‐VI (Computer) 

SPCC (System 

Programming and Compiler Construction)

Vacation + Regular 

ALL  OCAJP 1.7 (Oracle Certified Associate JAVA Programmer)

Vacation + Regular 

ALL  OCPJP 1.7 (Oracle Certified Professional JAVA Programmer)

Vacation + Regular 

 

 

Page 126: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

Chapter7

Turingmachine

TuringMachine:

TuringMachineisasimplemathematicalmodelofageneralpurposecomputer.

Turingmachinemodelsthecomputingpowerofacomputeri.e.theTuringmachineiscapableofperforminganycalculationwhichcanbeperformedbyanycomputingmachine.

TheTuringMachinecanbethoughtofasafiniteautomataconnectedtoread/writehead.

Ithasonetapewhichisdividedintonumberofcells.Eachcellcanstoreonesymbol.

TheinputtoandtheoutputfromtheFiniteAutomataareaffectedbytheread/writeheadwhichcanexamineonecellatatime.

Inonemove,themachineexaminesthepresentsymbolundertheread/writeheadonthetapeandthepresentstateofanautomationtodetermine:

- Anewsymboltobewrittenonthetapeinthecellundertheread/writehead.- Amotionoftheread/writeheadalongthetapei.e.eithertheheadmovesone

cellleft(L),onecellright(R)orstayatthesamecell(S)- Thenextstateofmachine.

TuringMachineisa7‐tuple

M=(Q,Σ,Ѓ,δ,qo,B,F)

Where,

Q‐finitenonemptysetofstates

Page 127: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

Σ‐setofinputsymbols

Ѓ‐finitenonemptysetoftapesymbols

δ‐transitionfunctionmappingthestateoffiniteautomatonandtapesymbolstostates,tapesymbolsandmovementofhead

δ:Q×Г→Q×Ѓ×{L,R,S}

qo‐initialstateof

B‐specialtapesymbolrepresentingblank

F‐setoffinalstatesF

InstantaneousDescriptions:

SnapshotsofaTuringmachineinactioncanbeusedtodescribeaTuringMachine.ThesegiveinstantaneousdescriptionsofaTuringMachine.

AnIDofTuringMachineisdefinedintermsentireinputstringandthecurrentstate.

Definition:

AnIDofTuringMachineMisastringγβαWhere,

βisthepresentstateofM.

Theinputstringissplitasγα.

Thefirstsymbolofγisthecurrentsymbolaunderread/writeheadandγhasallthesubsequentsymbolsoftheinputstring.

Thesubstringαoftheinputstringformedbyallthesymbolstotheleftofa.

Page 128: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

MovesinaTuringMachineSayδ(q,xi)=(p,y,L)Theinputstringtobeprocessedisx1x2…..xnandthepresentsymbolunderread/writeheadisxi.SotheIDbeforeprocessingxiisx1x2……….xi‐1qxi…………xnAfterprocessingofxi,theresultingIDisX1…….xi‐2pxi‐1yxi+1……xnThisisrepresentedby,X1x2…..xi‐1qxi……xn│xi……xi‐2pxi‐1yxi+1…….xnSayδ(q,xi)=(p,y,R)X1x2…….xi‐1qxi…..xn│─x1x2…..xi‐1xiypxi+1…..xnNote:ThedescriptionofmovesbyIDsisverymuchusefultorepresenttheprocessingofinputstrings.LanguageAcceptabilitybyTuringMachine:LetusconsidertheTuringMachine,M=(Q,Σ,Ѓ,δ,qo,B,F)AstringissaidtobeacceptedbyMIfqow│‐α1pα2WherePisthefinalstateandα1andα2aretapesymbols.TheTMMdoesnotacceptwIfthemachineMeitherhaltsinanon‐acceptingstateordoesnothalts.

Page 129: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

Problems:

UniversityquestionswillbesolvedinClass:

TuringMachineaslanguagerecognizer:

1. DesignaTuringmachinewhichrecognizesthelanguage{anbn│n≥1}

2. DesignaTuringmachinewhichrecognizesthelanguage {0n1n│n≥1}

(May‐2002,May‐2003,Nov‐2004,May‐2005,Dec‐2009)

3. DesignaTuringmachinewhichrecognizesthelanguage{0n1n2n│n≥1}

(Dec‐2002,May‐2003,May‐2006,Jun‐2008)

4. DesignaTuringmachinewhichrecognizesthelanguage (Dec‐2002){02n1n│n≥1}

5. DesignaTuringmachinewhichrecognizesthelanguage (Dec‐2002){0n1n0n│n≥1}

Page 130: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

6. DesignaTuringmachinewhichrecognizesthelanguage{anbnan│n≥1}

7. DesignaTuringmachinewhichrecognizesthelanguagehavingequalnumberofa’sandb’sOR

DesignTMtoacceptthelanguage–

L={xЄ{0,1}*│xcontainsequalnumberof0’sand1’s}

Simulatetheoperationforthestring110100.

(Dec‐2006,Jun‐2008)

8. DesignaTMtoacceptalanguageover{a,b}suchthatthenumberofa’s>numberofb’s.

(May‐2007)

9. ConstructTuringMachinethatwillacceptthelanguageLoverΣ={a,b}whereL={w:│w│iseven}

10. ConstructTuringMachinethatwillacceptthelanguageLoverΣ={a,b}whereL={w:│w│isamultipleof3}

11. DesignaTuringmachinetocheckforwell‐formednessofparenthesisOR

DesignaTuringMachinethatcheckswhetherastringofleftand

rightparenthesisiswellformedornot.

(May‐2006)

Page 131: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

12. DesignTMtorecognizedstringcontainingevennumberofa’sandoddnumberofb’soverΣ={a,b}

13. DesignTMtorecognizepalindromesoverΣ={a,b}

14. DesignTMthatcanacceptsetofallevenpalindromesoveralphabet(0,1).(May‐2006)

15. DesignaTuringmachinewhichrecognizesthelanguageL={WCWR│WЄ{a,b}*WR–reverseofW.

16. DesignaTuringmachinewhichrecognizesthelanguageL={WWR│WЄ{0,1}*WR–reverseofW.

UniversityquestionswillbesolvedinClass:

TuringMachinetocomputefunctions:

1. DesignaT.M.toperformadditionoftwonumbers. (Dec‐2003)

2. Designa.M.toperformmultiplicationoftwonumbers.(May‐2003,May‐2004,Nov‐2004,Jun‐2007,Jun‐2008)

Page 132: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

3. DesignaT.M.toperformsubtractionm–nWhichisdefinedas

m–nm>n

m≤n0

4. ConstructTuringMachinetosubtracttwonumbersassumem>n(May‐2006,Dec‐2009)

5. DesignT.M.toperformdivisionandfindthequotientandremainder.

6. DesignT.M.tofindn2 (Nov‐2004)

7. DesignT.M.tofindn! (Dec‐2003, May‐2004, Dec‐2008)

8. DesignT.M.tofindlog24 (Dec‐2003)

9. DesignT.M.tofindlog2n (Dec‐2003, May‐2004, Dec‐2006)

10. DesignTMtoperformC=A–Bgiven“$A#B$”. (May‐2005)

11. DesignT.M.tofind2’cofgivenbinarynumber.

Page 133: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

12. DesignTMtodetectwhetheraunarynumberisdivisibleby3. (May‐2005)

13. DesignT.M.toincrementbinarynumberby1.

14. DesignTMtocovertUnarynumbertoBinaryNumber

15. DesignTMtoconvertBinaryNumbertoUnaryNumber

16. DesignTMtoperformC=A+Bi/p“A+B”

o/p“C”

17. DesignTMtodecrementbinarynumberby1.

18. DesignTMtoaddBinarynumbers

19. ConstructaTuringMachinethatcompares2numbersmandnandleavesattheendxonthetapewherex=g/l/edependingonwhetherm>n/m<n/m=nrespectively.

20. DesignTMtoperformC=A*Bi/p“A*B”

0/p“C”

21. DesignTMtorecognizepalindromesovertheinputΣ={a,b}*

Page 134: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

22. DesignaTMforgenerating2nwherenisbinary.Theresultshouldalsobebinary.(May‐2004,Jun‐2007,Dec‐2007)

UniversalTuringMachine:

AuniversalTuringMachine (UTM) is aTuringMachine™which is al powerful oruniversalinthesensethatitiscapableofdoinganythingthatanyotherTMcando.

Inotherwords,theUTMshouldhavethecapabilityofimitatinganyTuringmachine

‘T’giventhefollowinginformationinitstape:

Thedescriptionof ‘T’ intermsif itsoperationorprogramareaofthetape(i.e. thetransactiontable).

The initial configuration of the TM i.e. starting state or the current state and thesymbolscanned.Theprocessingdatatobefedto‘T’(dataareaofthetape).

ThisobviouslymeansthattheUTMshouldhaveanalgorithmtointerpretcorrectlytherulesofoperationgivenabouttheTM‘T’.

The behavior of the UTM is simple, namely, simulating ‘T’ one step at a time asfollows:

- Amarker to indicate thepointatwhich thedescriptionof ‘T’begins,and itkeepsacompleteaccountofhowthe tapeof ‘T’ looks likesatevery instantguidesit.

- Also, it remembers the state ‘T’ is in, and the symbol ‘T’ is reading.Then itsimplylooksatthedescriptionof‘T;tocarryoutwhat‘T’issupposedtodo.

- Inordertoexhibitthisbehavior,theUTMshouldhavealookupfacilityandshouldperformthefollowingsteps:

Step1:Scanthesquareonthestateareaofthetapeandreadthesymbolthat‘T’readsandinitialstateof‘T’.

Step2: Findthetripletwhichcorrespondstotheinitialstateandthe inputsymbolreadinstep1.

Page 135: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

(Triplet:newstate,newsymboltobereplacedanddirectionofmove).

Step3: Movethetapetoreachtheappropriatesquareinthedataarea,replacethesymbol,movethetapeintherequireddirection,readthenextsymbolandfinallyreachstateareaandreplacethestateandscannedsymbols.Gotostep1.

TheUTMlaidthefoundationfor:

Storedprogramcomputersand Interpretativeimplementationofprogramminglanguages.

VariationsofTuringMachine:

1.TuringMachinewithTwoWayInfiniteTape:

ATuringMachinewithatwoinfinitetapeisdenotedby

M=(Q,Σ,Г,δ,qo,B,F)asintheoriginalmodel.

- Asitnameimplies,thetapeisinfinitetotheleftaswellastotheright.

- We imagine that there is infinity of blank cells to the left and the right of thecurrentnonblankportionofthetape.

- LisrecognizedbyaTuringMachinewithatwo‐wayinfinitetapeifandonlyifitisrecognizedbyaTuringMachinewithaone‐wayinfinitetape.

2.MultitapeTuringMachine:

A multitape Turing machine consists of a finite control with k tape heads and ktapes;eachtapeisinfiniteinbothdirections.

Onasinglemove,dependingonthestateofthefinitecontrolandthesymbolbyeachofthetapeheads,themachinecan:- ChangeState

Page 136: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

- Printanewsymboloneachofthecellsscannedbyitstapeheads.

- Moveeachofitstapehead,independently,onecelltotheleftirright,orkeepitstationary.

3.NondeterministicTuringMachine:

AnondeterministicTuringMachineisadevicewithafinitecontrolandasingleone‐wayinfinitetape.

Foragivenstateandtapesymbolscannedbythetapehead,themachinehasafinitenumberofchoicesforthenextmove.Eachchoiceconsistsofa

- Newstate- TapeSymboltoprint- Directionofheadmotion

4.MultidimensionalTuringMachine:

Itisadevicehavingafinitecontrolandthetapeconsistsofak‐dimensionalarrayofcells infinite in all 2k directions for some fixed k.Depending on the state and thesymbolscanned,thedevice

- Changesstate- Printsanewsymbol- Movethetapeheadinoneof2kdirectionseitherpositivelyornegativelyalong

withoneofthekaxes.

5.MultiheadTuringMachine:

Ak‐headTuringMachinehasfixednumber,k,ofheads.Theheadsarenumbered1throughk,andamoveoftheTMdependsonthestateandonthesymbolscannedbyeachhead.

In one move, the heads may each move independently left, right or remainstationary.

Page 137: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

6.CompositeT.M.:

Two or more Turing Machine can be combined to solve a collection of simplerproblem,sothattheoutputofoneTMformstheinputtothenextTMandsoon.ThisiscalledasComposition.

The ideaofcompositeTMgiverise to theconceptofbreakingthecomplicated jobinto number of jobs implementing each separately and then combining themtogethertogetanswerforthejobrequiredtobedone.

7.IteratedT.M.:

InIteratedTMtheoutputitappliedtotheinputrepetitively.

8.TMwithSemi‐infinitetapes:

TillnowwehaveallowedthetapeheadofTMtomoveeitherleftorrightfromitsinitialposition.

It isonlynecessary that theTM’sheadbeallowedtomovewithinthepositionsatandtotherightoftheinitialheadposition.

InTMwithSemi‐infinitetapestherearenocellstotheleftoftheinitialposition.

TheHaltingProblem:

ForagiveconfigurationofaTMcasecanarise:

Themachinestartingatthisconfigurationwillhaltafterafinitenumberofsteps. Themachinestartingatthisconfigurationnevernomatterhowlogeitruns.

Page 138: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

GivenanyTM,problemofdeterminingwhether ithaltseverornot, iscalledashaltingproblem.

To solve the halting problem, we should have some mechanism to which given anyfunctionalmatrix,inputdatatypeandinitialconfigurationoftheTMforwhichwewanttodetect,determineswhethertheprocesswilleverhaltornot.

Note: Inreality,onecannotsolvethehaltingproblem.Thehaltingproblem isunsolvable.ThatmeansthereexistsnoTM,whichcandeterminewhetheragivenprogramincludingitself,willeverhalt,ornot.

Proof:‐

1. Letusprovethehaltingproblembycontradiction.SupposethatthereexistsaTM‘A’whichdecideswhetherornotanycomputationbyaTM‘T’willeverhalt,giventhedescription ‘dT’of ‘T’andthe tape ‘t’of ‘T’.Then forevery input(t,dT) to ‘A’, if ‘T’haltsfortheinput‘t’,‘A’reachesan“accepthalt”;

2. If ‘T’ does not halt for the input ‘t’, then ‘A’ reaches an “reject halt”.We can nowconstructanotherTM‘B’whichtakes‘dT’astheinputandproceedasfollows:

- First it copies the input ‘dT’ and duplicates ‘dT’ on its input tape and thentakes this duplicated information tape as the input to ‘A’ with onemodificationnamely,whenever ‘A’ issupposedtoreachan“accepthalt”, ‘B’willloopforever.

3. Consideringtheoriginalbehaviorof‘A’,wefindthat‘B’actsasfollows.Itloopsif‘T’haltsforinputt=dTandhaltsif‘T’doesnothaltfortheinputt=dT.

4. Since‘B’itselfisaTM,letussetT=B.Thusreplacing‘T’by‘B’wegetthat,‘B’haltsfortheinput‘dB’ifandonlyif‘B’haltsfortheinput‘dB’.Thisisacontradiction.

5. Hencewe conclude thatmachine ‘A’which candecidewhether anyotherTMwilleverhalt,doesnotexist.Therefore,haltingproblemisunsolvable.

Page 139: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

ConsequencesofHaltingProblem:

1. WecannotdecidewhetheraTMeverprintsagivensymbolof itsalphabet.This isalsounsolvable.

2. Two TM’s with the same alphabet cannot be checked for equivalence orinequivalence by an algorithm; i.e. there is no effective general way to decidewhether a given computational processwill ever terminate orwhether two givenprocessesareequivalent.Thisisalsoanotherunsolvableproblem.

3. Blank‐tape theorem: There exists a TMwhich when started on a Blank tape, canwrite its own description. This is of interest in constructing self‐reproducingmachine.

TuringMachineandComputers:

SimulatingaTMbyComputer:

1. GivenaparticularTMM,wemustwriteaprogramthatactslikeM.

2. FiniteControl:sincethereareonlyafinitenumberofstatesascharacterstringsanduseatableoftransition,whichitlooksuptodetermineeachmove.

3. MachineTape: Zipdisksorremovableharddiskscansimulateinfinitemachinetape. Wecanarrange thedisksplaced in twostacks:One stackholds thedata in

cellsoftheleftofthetapehead,andotherstackholdsthedatasignificantlytotherightofthetapehead.

SimulatingaComputerbyaTM:

ThefollowingdiagramshowshowtheTMwouldbedesignedtosimulateacomputer.

1. Thefirsttaperepresentsmemoryofthecomputer.

2. The second tape holds the memory locations on tape1. The value stored in thislocationwillbeinterpretedasthenextcomputerinstructiontobeexecuted.

Page 140: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852

For Doubts Contact Ganesh Sir@83 84 82 05 75  

 

 

CHOPRA ACADEMY @Bandra:9867 843 854 @Thane:9867 843 853 @Vashi :9867 843 852 For Doubts Contact Ganesh Sir@83 84 82 05 75

 

3. Thethirdtapeholdsthememoryaddressorthecontentsofthataddressafterthat

addresshasbeenlocatedontape1.Toexecuteaninstruction,theTMmustfindthecontentsofmemoryaddressthatholddatainvolvedinthecomputation.

4. Thefourthtapeholdsthesimulatedinputtothecomputer,sincethecomputermustreaditsinputfromafile.

5. Thescratchtapewouldbeusedtocomputemathematicaloperationsefficiently.

ReferClassNotesforExamples.

 

Subjects Taken by Ganesh Sir: 

Semester  Subject  Batch SEM‐VI (Computer) 

SPCC (System 

Programming and Compiler Construction)

Vacation + Regular 

ALL  OCAJP 1.7 (Oracle Certified Associate JAVA Programmer)

Vacation + Regular 

ALL  OCPJP 1.7 (Oracle Certified Professional JAVA Programmer)

Vacation + Regular 

Page 141: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

 

        

Chapter8

IntractableProblems

Wenowbringourdiscussionofwhatcanorcannotbecomputeddowntothelevelofefficientversusinefficientcomputation.

Wefocusonproblemsthataredecidable,andaskwhichofthemcanbecomputedbyTuringmachinesthatruninanamountoftimethatispolynomialinthesizeoftheinput.

1. Theproblemssolvableinpolynomialtimeonatypicalcomputerareexactlythe

sameastheproblemssolvableinpolynomialtimeonaTuringmachine.

2. Experience has shown that the dividing line between problems that can besolved in polynomial time and those that require exponential time ormore isquitefundamental.

3. Practicalproblems requiringpolynomial timearealmostalways solvable inanamountoftimethat wecantolerate,whilethosethatrequireexponentialtimegenerallycannotbesolvedexceptforsmallinstances.

In this chapter we introduce the theory of "intractability," that is, techniques forshowingproblemsnottobesolvableinpolynomialtime.

Westartwithaparticularproblem‐thequestionofwhetherabooleanexpressioncanbesatisfied, that is,made true for someassignmentof the truth valuesTRUEandFALSEtoitsvariables.

Sincewearedealingwithwhetherproblemscanbesolvedinpolynomialtime,our

notionofareductionmustchange.

It is no longer sufficient that there be an algorithm to transform instances of oneproblemtoinstancesofanother.

Thealgorithmitselfmusttakeatmostpolynomialtime,orthereductiondoesnotlet

usconcludethatthetargetproblemisintractable,evenifthesourceproblemis.  

Page 142: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

 

        

 

Thereisanotherimportantdistinctionbetweenthekindsofconclusionswedrewinthetheoryofundecidabilityandthosethatintractabilitytheoryletsusdraw.

We assume the class of problems that can be solved by nondeterministic TM'soperatinginpolynomialtimeincludesatleastsomeproblemsthatcannotbesolvedby deterministic TM's operating in polynomial time (even if we allow a higherdegreepolynomialforthedeterministicTM).

TheClassesPandNP: (Dec‐2009)

1. Pdenotes theclassofproblems, foreachofwhich, there isat leastoneknownpolynomialtimedeterministicTMsolvingit.

2. NP denotes the class of all problems, for each of which, there is at least oneknownnon‐deterministicpolynomialtimesolution.However, thissolutionmaynotbereducibletoapolynomialtimedeterministicTM.

3. Time complexity of an algorithm is defined as a function of the size of theproblem.

4. For comparative study of algorithms, growth rate is considered to be veryimportant.

5. Sizeofaproblemisoftenmeasuredintermsofthesizeoftheinput.

6. Analgorithmwith time complexitywhich canbeexpressedas apolynomial ofthesizeoftheproblemisconsideredtohaveanefficientsolution.

7. A problem which does not have any polynomial time algorithm is called anintractableproblem,otherwiseitiscalledtractable.

8. A solution by deterministic TM is called an algorithm. A solution by a non‐deterministicTMmaynotbeanalgorithm.

9. Foreverynon‐deterministicTMsolution,thereisadeterministicTMsolutionofaproblem.But there isnocomputationequivalencebetweendeterministicTMandnon‐deterministicTM.

Page 143: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

 

        

10. Ifaproblemissolvableinpolynomialtimebynon‐deterministicTMthenthereisnoguaranteethatthereexistsadeterministicTMthatcansolveitinpolynomialtime.

a. IfPissetoftractableproblemthenPissubsetofNP.ItfollowsfromthefactthateverydeterministicTMisaspecialcaseofnon‐deterministicTM.

b. ItisstillnotknownwhetherP=NP.

NP‐CompleteProblems:

1. A problem is NP‐complete if it is in NP and for which no polynomial timedeterministicTMsolutionisknownsofar.

2. AninterestingaspectofNP‐completeproblemisthatforeachoftheseproblems: IthasnotbeenpossibletodesignadeterministicTM,sofar. IthasnotbeenpossibletoestablishthatadeterministicTMdoesnotexist.

3. Thereisalargenumberofproblems,forwhichitisnotknownwhetheritisinPor

notinP.However,foreachoftheseproblems,itisknownthatitisinNP.

4. EachoftheseproblemscanbesolvedbyatleastonNon‐deterministicTM,thetimecomplexityofwhichisapolynomialfunctionofthesizeoftheproblem.

5. AproblemfromtheclassNP,canbedefinedasoneforwhichapotentialsolution,ifgiven,canbeverifiedinpolynomialtimewhetherthepotentialsolutionisactuallyasolutionornot.

6. SomeoftheNP‐completeproblemsinclude: SatisfiabilityProblem(SAT) TravellingSalesmanProblem(TSP) HamiltoniancircuitProblem(HCP) TheVertexcoverProblem(VCP) K‐ColourabilityProblem Thecompletesubgraphproblem

ARestrictedSatisfiabilityProblem:

1. Thesatisfiabilityproblemstates:GivenaBooleanexpression,isitsatisfiable?

Page 144: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

 

        

2. ABooleanexpressionsaidtobesatisfiableifatleastonetruthassignmentmakestheBooleanexpression‘true’.Example,theBooleanexpression(X1ɅX2)νX3istrueforX1=1,X2=1andX3=0.Henceitissatisfiable.

3. ABooleanexpressioninvolves:a. BooleanvariablesX1,X2…Xn,eachofthesecanassumeavalueeitherTRUE

orFALSE.b. Booleanoperators:

4. ThetruthvalueofaBooleanexpressiondependsonthetruthvaluesofitsvariables.

5. SatisfiabilityproblemisNP‐Complete.

6. SATisNP‐CompleteanditisalsoknownasCook’stheorem.

7. A Boolean expression in conjunctive normal form is NP‐complete. A Boolean

expression issaid tobe inCNF, if it isexpressedasC1ɅC2ɅC3Ʌ…ɅCkwhereeachCiisadisjunctionoftheform

Xi1νXi2ν…νXim

Xijisaliteral.AliteraliseitheravariableXiornegationXi.

NP‐Completeness:

1. Polynomial‐timereductionplaysan importantrole indefiningNP‐completeness.Apolynomial‐time reduction is a polynomial‐time algorithm which constructsinstancesofaproblemP2fromtheinstancesofsomeotherproblemP1.

2. IfP1beaproblemwhichisalreadyknowntobeNP‐complete.Wewanttocheckwhetheraproblem P2 is NP‐complete or not. If we can design an algorithm which transforms orconstructsaninstanceofP2foreachinstanceofP2,thenP2isalsoNP‐complete.

3. AmethodofestablishingNP‐completenessofaproblemP2requiresdesigningapolynomialtimereductionalgorithmthatconstructsaninstanceofP2foreachinstanceofP1,whereP1isalreadyknowntobeNP‐complete.

4. NP‐HardProblem:a. AproblemLissaidtobeNP‐HardifforanyproblemL1inNP,thereisapolynomial‐

timereductionofL1toL.b. Inotherwords,aproblemisNP‐Hardif:

i. EstablishingLasanNP‐classproblemissofarnotpossible.

Page 145: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

 

        

ii. ForanyproblemL1inNP,thereispolynomialtimereductionofL1toL.c. EveryNP‐CompleteproblemmustbeNP‐Hardproblem.

5. ComplementsofLanguagesinNP:

a. ItisnotknownwhetherNPisclosedundercomplementation.TheclassoflanguagesP isclosedundercomplementation. It isbelievedthatwhenever languageL isNP‐complete,itscomplementisnotinNP.

b. ThereisasetoflanguageswhosecomplementsareinNP.SuchlanguagesarecalledCo‐NP.

c. WebelievethatcomplementofNP‐completeproblemisnotinNP.d. NoNP‐completeproblemisinCo‐NP.e. WebelievethatthecomplementsofNP‐completeproblems,whichareinCo‐NPare

notinNP.

LanguageClassesBasedonRandomization:

1. A randomized algorithm uses a random number generator. Decisions made in suchalgorithmsdependontheoutputofrandomnumbergenerator.Theoutputofarandomizedalgorithmisunpredictableanditmaydifferfromruntorunforthesameinput.

2. ATuringmachinecanuserandomnumbersinitscalculation.ATuringmachinewithsuchacapabilityisknownasrandomizedTuringmachine.

3. TherearesomesimilaritiesbetweenarandomizedTMandnon‐deterministicTM.Thenon‐deterministicchoiceofaNDTMcouldbebasedonrandomnumber.

4. TheclassoflanguagesacceptedbyarandomizedTMcanbedividedintotwocategories.a. TheclassRPb. TheclassZPP

5. RP stands for randomized polynomial‐time algorithm. ZPP stands for zero‐error

probabilisticprobabilisticpolynomialalgorithm.TheclassZPPisbasedonarandomizedTMthatalwayshaltsinpolynomialtime.

ComplexityofPrimalityTesting:

1. Anintegernumberisprimeifitisdivisibleonlyby1anditself.Analgorithmcanbewrittento testwhether a number is prime or not. These algorithms are found to be in followingclasses:

a. Npb. Co‐NPc. RP

Page 146: CHOPRA ACADEMY - WordPress.com · Rizvi Chambers, RS Rd,Data Mandir Vashi Plaza, Mumbai :400050 Thane - 400601 ... Universal TMs, Variants of TMs − Multitape TMs, CHOPRA ACADEMY

 

        

2. Giveninintegern,theproblemofdecidingwhethernisprimeisknownasprimalitytesting.

3. Algorithmsforprimalitytestingarebasedonthefollowingtwotheorems:a. If‘n’isaprime,thena(n‐1)=1moduloP‐‐‐‐‐‐‐‐‐‐‐‐‐Fermat’stheoremb. TheequationX2=1(modulon)hasexactlytwosolutionsnamely1andn‐1,ifnisa

prime.

4. AnalgorithmbasedonFermat’stheoremcanbewrittenwithtimecomplexityofO(n3).

5. A randomized algorithm based on Fermat’s theorem will have a time complexity ofO(log2n).

Questions:

1. Explainclassesofcomplexitywithexample. (Dec‐2009)2. WritenotesoncomplementsoflanguagesinP. (Dec‐2009)

Subjects Taken by Ganesh Sir: 

Semester  Subject  Batch SEM‐VI (Computer) 

SPCC (System 

Programming and Compiler Construction)

Vacation + Regular 

ALL  OCAJP 1.7 (Oracle Certified Associate JAVA Programmer)

Vacation + Regular 

ALL  OCPJP 1.7 (Oracle Certified Professional JAVA Programmer)

Vacation + Regular