0% found this document useful (0 votes)
183 views

Toc TH PDF

Uploaded by

TanyaGarg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
183 views

Toc TH PDF

Uploaded by

TanyaGarg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 154
Theory of Computation Comprehensive Theory with Solved Examples and Practice Questions MADE ER! mADE ERSY Indio's Bast Institita for (ES, GATE & PSUS orth tus, state axis le sable able ng? gular @ for OFLU REL Contents Grammars, Languages & Automata. Context Free Languages & Push down, 2 1.1. Introduction... 2 Automata 1.2. Chomsky Hierarchy. 4 3.1 Context Free Grammars sre 13. Automaton. 5 32 Context Free Language ne 8 14 Gram 6 33 PushDown Automata POM. 8 1.5 Equivalence of Languages, Grammars and 34 Equivalence between CFL and CFG. 107 ‘Automata a 5 35 Closure Properties of CFs 108 4 oe 216 Closure Properties of DCS see 10 1) pplaontatonite ns 427 Decision Properties of CFLS m 38 Non-Contest Free Languages... 13 29 Non-Regular Languages and CFLs 14 Regular Languages & Finite Automata. 21 ItrOd uP nen 1 REC, RE Languages & Turing Machines, 22 Deterministic nite Automata (DFA) enon1S Decidability.nnn 123 23. Non-determinsti Fite Automata 41 Turing Machine (TM 13 {NFA or NDA). ae) 42 Vaiationof Tung Machine 14 pee = 443 Turing Machine Compton nen 25 4 Turing Machine Recognizable Languages... 127 25 Regular Expressions nan aA 45 Closure Properties 26 Equivalence between Finite Automata and ae ve 46 Restricted Turing Machines. 129 Regular Expressions ensnsnnnniennenennn 47 Turing Machine Construction. 129 A = 48 Post Correspondence Problem (PCP) 133, 28 Closure Properties of Regular Languages nnn 55 49 Some Decidable Problems Recursive 29° Decision Properties of Regular Language ...61 Languages) on Turing Machines. 133 2.10 Moore and Mealy Machines 62 410 Chomsky Hierarchy Vs Other Classes. 134 2.11. Pumping Lemma.. oa 4.11, Decidabiliy of Formal Languages. 134 2.12. Minimization of Finite Automata o 412 Terminology of Problems. 136 2.13. Myhil-Netode Theotern 2 4.13. Important Pints of Undecidabilycsnnen 137 4.14 Reduction. an 137 Theory of Computation eee Theory of Computation deals with automata theory and formal languages. Itis the study of “Abstract Model of Computation’. This subject helps to solve various problems using the following modes. © Finite Automata © Push Down Automata © Linear Bound Automata © Turing Machine Iti very important for every computer programmer to know what are the problems that can be solved and what cannot be solved. This subject explains the capabilities and limitations of computation era ‘To understand the formal model of computation, this book provides you rigorous presentation of concepts, models, examples accompanied by practice problems and student assignment. This book is organized with all mode's that makes it easier to read, understand and acquire quick interpretation of all models. Ituses definitions and properties of mathematical models to explain the capabilities and limitations of Problems/Computation/Programs/Languages. ‘The following information provides a brief description of the chapters in this book. Chapter 1 (Grammars, Languages & Automata): This chapter deals with all notations, and definitions of theory of computation such as Grammar, Equivalence of Language, Chomsky Hierarchy Model and languages with their relationships in the computation model. Chapter 2 (Regular Languages & Finite Automata): This chapter explains indetall about type-3 formal languages acceptance by Finite Automata with representations like Regular Expressions, Regular Sets, and Regular Grammars. It also covers the Closure Properties and Decision Properties of regular languages with detailed proofs and Moore and Mealy machines. Chapter 3 (Context free languages & Push Down Automata): This chapter covers type-2 formal languages acceptance by Push Down Automata and representations with equivalences between CFG and CFL, Closure Properties and Decision Properties of context free languages with detalled proofs and identify lhe CFL and non- CFL languages. Chapter 4 (REC, RE Languages & Turing Machines, Decidability): This chap Decidable and Undecidable problems of formal languages and automata theory and Closure Properties and Decision Properties of context free languages with detailed proofs, deals with Turing Machine wwrtinadeeasyin (9mabeE Easy ‘Theory with Solved Examples Grammars, Languages & Automata 11 wa 12 113 is} Introduction Alphabet(Z) Definition: An Alphabet is a set of finite non-empty set of symbols, (2, b} is alphabet with 2 symbols a and b. (0, this binary alphabet. + E=(0, 1,2... 9] is decimal alphabet String Definition: & string is any sequence of zero or more symbols over the given alphabet 5, ‘abp" is the string over 2 = (a, b} Empty string (e or 4): Empty string is a string with zero number of symbols in the sequence. Empty tring is also called as “Null String" Operations on Strings 1. Length of astring: The number of symioois in the sequence of given string is called “length of a string” + Length of string abb = |abo| = 3, where = = [a, b) ‘The length of empty string is zero , labl sequence of symbols from any part of the given string over an alphabet is called a “Substring of a string” For string abb over 5 = {a,b}. The possible substrings are: + Zerolenath substring: e © One length substrings: a, © Two length substrings: ab, bb © Three length substrings: abb Theory with Solved Examples MADE EASY ound 1a 1.1.6 TBMRDE EASY EEE 2070) Theory of Computation | “Proper Substing' is @ substring and its length is less than given string length. The string “ab” is not a proper substring of the string "abb” but is a substring of “abb’ 3. Prefix ofastring: A substring with the sequence of beginning symbols of a given string is called a "Prefix For string “ab, the possible prefixes of ab are: + ©,(zorolength prefix) # (ene length prefix) * ab (twolength prefix) * abo (three length prefix) 4. Suffix of a string: A substring with the sequence of traling (ending) symbols of a given string is called a "Suffix" For string ab, the possible suffixes are: e, b, bb, ab. 5. Proper Prefix of a string: Proper prefix is a prefix except the given string, For string abb, the possible proper prefixes are: e, a, ab. 6. Proper Suffix ofa string: Proper sulix is a suffix except the given string For string abb, the possible proper suffixes are: e, b, bb. Power of an Alphabet Consider 5 = (2, b}. The following are powers of an alphabet over input alphabet 5. fe}: zero lenath string (2, b}: set of t-length strings (also called as symbols) 1? = (aa, ab, ba, bb] : set of 2ength strings 3 = (aaa, aa, aba, abb, baa, bab, bba, bbb} : set of 3-length strings. Kleene Star Closure (5*) + Eris the set ofall stings over B. © BePururury + Kleene closure (")is unary operation Positive Closure (") + E+is the set of stings over S except an empty string r-r Language Definition: A set of strings over the given alphabet Eis called a ‘language’ Let = (a, b}. Then (ab, aab] is @ language. Language may contain finite or infinite number of strings. So language is two types: a) Finite language, and (b) Infinite Language. 18 Grammar (Grammar has set of rules to generate the strings of a language. Grammar is a set of 4 tuples. Grammar G V, T, P, §) where Vis set of non-terminals, Tis set of terminals, Pis set of productions or rules and Sis start symbol (Se V). Each rule appears as: X-> Y, where X and Yare any sequence of terminals and non-terminals. wwwmadeeasy.in G@mnave Easy ‘Theory with Solved Examples | Computer Science & 7 PEE) G3 MADE EASY 1.2 Chomsky Hierarchy + Allformalianguages ae divided into four classes by chomsky and thishiorarchy known as “Chornsky- Hierarchy + Type 3c Type 2c Type 1 < Type 0. + Rogular languages c CFLs c CSis c RELs. ZEN a is accepted by TM AN } \ XS 4 “ Type 3 lass\ ~~} Type 1 class is accepted by FA _| is accepted by LBA Type 2 class is accepted by PDA Figure: nomisky Hierarchy 1.2.1. Formal Languages Definition: Formal language is en abstraction of the generalized characteristics of programming languages. or ‘ormal Janguage is a set ofall strings where each string is restricted over a particular form or Formal language is a set ofall stings permitted by the rules of formation, 1.2.2 Types of Languages 1. Regular Language (REG): 4 language accepted by a finite automaton is called a “regular language’ or A language generated by regular grammar is called a “regular language” 2. Deterministic Context Free Language (DCFL: A language accepted by a deterministic push down automaton is called a DCFL. 3, Context Free Language (CFL): A language accepted by a push down automaton (non-deterministic) is calleda “CFL” or A language generated by a contex! tree grammar is called a "CFL 4. Context Sensitive Language (CSL): A language accepted by a linear bound automaton is called @ “esl” or language generated by a context sensitive grammar is called a ‘CSL’. 5. Recursive Language (REC): language accepted by the Halting Turing Machine is called a recursive language or REC. (Gy theory with Solved Examples G3 MADE Ensy rwonanadesdipln GSMADE EASY ERS 2076] Theory of Computation | or Ifa language can be enumerated in a lexicographic order (Particular order) by some turing machine, then such a language is called recursive or REC, 6 Recursive Enumerable Language (REL): A language accepted by turing machine is called a r ‘enumerable language or REL, or The language enumerated by the turing machine is called as recursive enumerableor REL. 1.3 Automaton 1. Automaton Acts as Recognizer or Acceptor: An automaton is a machine that accepts or recognizes the strings of a language (L) over an input alphabet E. teprateg ts ema | 7 ore ocean Renor Sina tng) 2. Automaton Acts as Generator or Enumerator or Transducer: An automaton can also produce the ‘output over any alphabet A for the given input alphabet 5, Seputsting [puiratn | out tng overE 7] Prosuee op overs 1.3.1 Types of Automaton 1. Finite Automaton (FA): An autor: Types of Finite Automaton: (@)_ Deterministic Finite Autoriaton (OFA) (b) _Non-deterministc Finite Automaton (NFA or NOFA) (¢)_NFAwithe-moves (e-NFA) L(DFA) = L(NFA) = L(e-NFA) where L(DFA) is the class of languages accepted by DFAS. i... allfinite automata are having same expressive power, 2 Push Down Automaton (PDA): /An automaton that accepts a context free language is called a PDA’ ‘Types of Push Down Automaton: (@) Deterministic PDA (DPDA) (©) Non-deterministic PDA (NPDA or PDA) L(DPDA) < L(NPDA)ie., DCFL’s < CFL's Class of languages accepted by DPDAS are proper subset of class of languages accepted by NPOAS, NPDAs have more expressive power than the DPDAs. 3. Linear Bound Automaton (LBA): An automaton that accepts a context sensitive language is called a linear bound automaton. that accepts a regular language is called a "FA" wwwimadeeasy.in Q@MADE EASY ‘Theory with Solved Examples | Computer Science & IT REeiemei 2s) GIMACe Easy 1.4 4. Turing Machine (TM): An automaton that accepts @ recursive enumerable language is called a turing ‘machine. ‘+ TMean accept a recursive enumerable language, (TM acts as recognizer) ‘+ TMcan enumerate a recursive enumerable language. (TM acts as enumerator) * Types of turing machine (based on configuration): (@) Deterministic Turing Machine (OTM) (0) Non-deterministc Turing Machine (NTM) + NTMand DTM are having same expressive power: L(NTM)=L(OTM) + Standard turing machine is a deterministic turing machine. + Types of TM (Based on acceptancelenumeration} (@) Halting TM (HTM): Accepts recursive language () Standard TM (TM): Accepts recursive enumerable language ‘+ HTM has less expressive power as compared to TM; (HTM) Aa, A Aala + Right linear grammar: S a8, 8 bBla 2 Context Free Grammar (CFG): Every ule of CFG is restricted as: V > (VUT)* © (S-aSole} isCFG + (SBA adda, B—>ABle} is CFG 3 Context Sensitive Grammar (CSG): Every rule of CSG is restricted as following X—> Ywhere |X|s |¥|,Xe (VUT)’ and Ye (VT) and X must contain atleast one variable. If NULL productions are present inthe grammar, it may nol be a CSG {S>arbla, eA-ca) isCSG {SaAb|e, aA cd} isCSG {S-+aAb]aS, aAb > cdef) is CSG 4. Recursive Enumerable Grammar (REG): Every rule of REG is restricted as folowing XY where X€ (VUTI", Ye (VUT)*: X must contain atleast one variable + REGis also called as unrestricted grammar or phrase-structure grammar. + {85 aAb|bs, a4 b} is REG ‘Theory with Solved Examples (9 mApe Ensy wo madecasy.in Da mabe easy Postal Study Course EEIE ‘Theory of Computation 1.5. Equivalence of Languages, Grammars and Automata 1, Regular Language (REG) Finite Automaton (DFA = NFA Regular Grammar Left Linear Grammar (LLG) Right Linear Grammar (RLG) Feegular Expression (RE) ‘Type-3 formal language 2. Context Free Language (CFL) Push Down Automata (NPDA or PDA) Context Free Grammar (CFG) ‘Type-2 formal language 3. Context Sensitive Grammar (CSG) Linear Bound Automata (LBA) Context Sensitive Language (CSL) ‘Type-1 formal language 4, Recursive Enumerable Grammar or Unrestricted Grammar (UG) ‘Turing Machine (TM) Recursive! Type-0 formal language tumerable Language (REL) Glass | Formal Languages Grammars ‘Astomata “pe | Repvar Languages | Regul grammars Fine Automata “p02 | Conte Fee Largvopes | Conti Free Gamnars Push down Atonata [iceeeeeetsee eee __| Pet gown Aon Typet | Contest SensiveLangoges | Conte Senstne Grammars | LnearBound Automata eave Gramaratie | Recurive enumerbie farms Typed ng Machines [_ Tye? | Cngunges {unvestrcies grammars} ‘Turng Me wiunmadeaasype GgmApE EASY ‘Theory with Solved Examples | Computer Science & 1T EESEMESoos) OE MADE ERsy 1.6 Expressive Power of Automata Exprossive power of a machine is determined by the setof languages acceoted by he particular ype of machines FA.< DPDA < PDA < LBA < TM, FA\is less powerful than any other machine and TM is more powerful than any other machine + Type3 class c Type 2 class c Type 1 class c Type 0 cla + FA=TM with read only tape = TM with unidirectional ape = TMwith finite tape = PDA with rite stack + PDA=FA with stack + TMzPDA with additional stack = FA with two stacks 1.7 Applications of Automata + Finite automata can be used in the following cases: {@) To design lexical analysis of a compiler (b) Torecognize the pattern using regular expressions (@) Todesign the combination and sequential circuits using Moore / Mealey machines. (d) Used in text editors (€) Used to implement spell checkers + PDAcan be used in the folowing cases: (2) ‘To design the parsing phase of a compiler (syntax analysis) (b) Toimpiement stack applications (o) Toevaluate arithmetic expressions (@) Tosoive the Tower of Hanoi probiem + Linear Bounded Automata can be used in the following cases: (2) To construct syntactic parse trees for semantic analysis of the compiler. {b) Toimolement genetic programming + Turing Machine can be used inthe folowing cases: (a) To solve any recursively enumerable problem (b) Tounderstand complexity theory (0) Toimplement neural nets (2) Toimplomentartticialintligence {@) Toimplement Robotic applications (259 Theory with Solved Examples MADE EASY winnmadecasy.in GIMBDE EASY [RES 2075] Theory of Computation Summary + © : Alphabet: It is a sot of finite number of symbols, String: Itis a sequence of symbols over given alphabet. Substring: Any part of the given string is called a substring. Language: itis a set of strings over given alphabet. Grammar: itis a set of 4 tuples that contain set of rules to generate the strings of a language. ‘Automaton: Automaton can accept the language and it may be used to produce the output, Formal Languages: Type0, Typet, Type? and Type3 formal languages. ‘Automaton Types: Finite automata, Push down automata, Linear bound automata and Turing Machines. Grammars: Regular grammars. CFGs, CSGs, REGS Language may be finite set or infinite set Expressive power ofa machine is the class or set of languages accepted by the particular type of machines, FA < PDA PDA> LBA > TM (2) TM< PDA < LBA < FA (@) TM> PDA > LBA > FA .22 A language L is accepted by @ PDA if and only iritis (@) Regular language (©) cs (©) Expressible by CFG (@) Expressible by Right-inear grammar .23 Alenguage L is accepted by a TM if and only if itis (@) Recursive language (©) Enumerable in lexicogranhical order (6) Expressible by unrestricted grammar (@) None of these Q.24 Find the correct chomsky hierarchy (@) Typed c Typet = Type? Typed (b) Type3 < Typet c Type2< Typed (6) Typed «Type? & Typet < Types (d) None of these transition Q.16 The languages accepted by DPDA are Q.25 Which one of the following is correct for the input. @ cs (b) GSLs alphabet 57 (c) DCFLs (d) RELs (a) D=E {o) ‘Et- fe} Q.17 The languages accepted by PDA are __ (©) =z ute) () Baz nie (a) CFls (o) CSLs Answer Key: (©) DCFLs (d) RELs Le 26 36 40 56) 0.18 Thelanguages accepted by NPDA are te on in Clon te \a CAs te) Cs (@) Doris ore 1H) RO Be) WO BE 6 7 Be Q.19 The languages accepted by LBA are _ ee ee f@ ors (e) cSts 2G) 2 BE _*W) 2.16 (c) DCFLs (d) RELs [Ea] theory with solved Examples GgmADE ERsy worn madecasyin CHAPTER Regular Languages & Finite Automata 2.1 Introduction ‘© Finite Automaton (FA) is also called as Finite State machine (FSM). ‘* Finite Automaton has no temporary storage hence it can remember finite information with the help of, nite contro! which contain states and transitions. 2.1.1 Types of Finite Automata Finite Automata ON inte Accenter (FA without output) | |” Finke Transducer (FA wih ouput) Deterministic: DFA Moore Machine Non-deterministic: NFAande-NFA | | Mealy Machine Finite automata is categorized into two types: 1. Finite automata with output: This is of two types Mealy machines and Moore machines. @ In Mealy machine the output is associated with transition (state and input syriool) (b) Inthe Moore machine output is associated with only state. 2. Finite automata without output: This is of two types deterministic and non-deterministic. (@) Deterministic Finite Automate (DFA): itis deterministic finite automata, For every input symbol in DFA there is an exactly one transition from any state of finite automata. It accepts the string by halting at a final state and rejects the string by halting at a non-final state. (©) Non-deterministic Finite Automata (NFA): itis non deterministic finite automata, For every input ssymibol in NFA there is zero or more transitions from any state of finite autornata. It accepts the string by halting ata final state and rejects the string either by halting at a non-final state or by halting in a dead configuration (6) e-NFA:Itis anon deterministic finite automata which can include e transitions. ithas capability of changing the state without reading the input symbol. Gumaakaaple QSmAdE EASY Theory with Solved Examples ESSEC 20s) GIMADE Ass 213 214 an input. = Non-deterministic automaton is one in which each move may have set of possible actions. = Moore and Mealy machines are deterministic. = Finite Automaton accepts a regular language as follows: “Rosaps sing, ising se A) te den roils angusge Input sting [Feito Pegead song Fri reader age | = Finite transducer produces an output for the given input as follows: Input Sting [Output Sting ver input aiphabot "| TRANSDUCER Fever output alphabet Model (Configuration) of Finite Automata + Input tape contains a sting over the given input alphabet osteo Read head isa poiner which reads one input symbolatatimeand CLT TT L111)" moves to the next symbol. Finite control contains set offre states and transition functions to {eke an action based on current stale and input symbol scanned + For every string the finite control starts trom an inital state. Ifthe string is valid ite contol aches tothe final state Read Head Finite Contol ite Automata Acceptance * Finite Automata accepts type-3 formal languages called as regular languages. * Regular language is either finite or infinite language. = Alanguage is finite itt contains finite number of strings otherwise itis infinite language. © Every finite language is regular hence it is possible to cortstruct finite automata to accept the finite language, + For infinite language the construction of finite automata may or may not possible. Ifthe finite automata does not require infinite memory then it is possible to construct otherwise it is not possible to construct as it requires infinite number of states, wich is not allowed in FA. Regular Language «Allfnite languages are regular + the language isininite over unary alphabet and whose strings are forming an arithmetic progression then itis regular language, otherwise itis non-regular. + Ifthe languages infinite over wo or more input symbols and which do not contain any dependency ‘between symbols then the language is regular Solved Examples MADE EASY irricinadecasyn GaMADE EASY BRST 2075) Theory of Computation 2.1.5 Representations of Regular Language Finite Automata (by construction) Regular Grammars (by writing productions Regular Sets (by representation of a set) Regular Expression (by writing an expression) 2.1.6 Equivalence of Finite Automata DFA: All Every DFA is also a special cas IFA=e-NFA hese three finite automata accept same class of languages called as regular languages of NFA NFA can be converted to DFA using subset construction e-NFA\ can be converted to NFA and also to DFA 2.1.7 Representations of FA where, Q is set of finite 1 Fi (Q,, 8, ag, F)is a S-tuple notation tes, is an input alphabet contains fiite number of input symbols, 6s transition function defined over transitions of FA for state and input. Qi initial state or start state of FA, gy Q. F is set of final states of FA, State Transition Diagram @ (0) ) (a) @ Every state represented by a circle. For an Initial state, a circle is associated with an arrow. Final state represented by double circle. Every state is connected with transitions associated with an input. In the following diagram: g, and q, are states, qj is an intial state and a, is a final state % ]) | dois nl state L x 9,43 afina tate State transition table: (a) (o) (o) @® © 0 Table contains rows and columns Each row corresponds to the state of DFA Each column corresponds to the input symbol of OFA initial state is associated with an arrow Final state is associated with a circle or star In the following table: q, and q, are states, q, is an initia state and a, is a final state, Tey Sala [ae "a e@| a | a al 2.2 Deterministic Finite Automata (DFA) If for every input symioo! of an alphabet there is an exactly one transition from every state of finite ‘automata then such FA is called as DFA, ‘wuninadealajuh Ggmape Ens Theory with Solved Examples KE) | Computer Science & IT ieee 2s] GIMAGE Easy * DFA covers deterministic transitions forall valid and invalid strings in the given regular language, * For every valid string, DFA reaches to the final state and for every invalid string it reaches to the non- final state. 2.2.1. Specifications of DFA DFA = (Q, E, 8, ag, F)is a 5-tuple notation where Qis the set of finite states is an input alphabet contain finite number of input symbols. 8s a transition function defined over transitions of FA for state and input, (8: x =~» Q) 9/8 an initial state or start state of DFA, (Qy € Q). F is the set of final states of DFA (FQ). 2.2.2 Constructing Minimal DFA for the Regular Languages strings. Solution: Language L = {e, 0, 1,00, 01, 10, 11...) Construct a minimal DFA that accepts a language where it contain all binary wwe (0, 1}) al Initial state = A, Final states = (A) Language contain all strings of a's and b’s over the alphabet © = (a, b}. where every string is starting with a. Solutio Initial state = A, Final states = [B}, reject state = C, and non-final states = (A, C) Reject state is constructed to reject all invalid combinations in finite automata, PEEEEEEEN | 2700090 conan al stings of sand bs wih an input alphabet of and 1 where every sting is ending wtb solu Gq Mery with soived Examples G3MADE EAsy ieee GIMBDE ERSY RAR M ei 2075) Theory of Computation | ih an input alphabet of a’ and Gano Language contain all strings of a's and b's ', where each string contain substring ‘at Solution: A 2 A» A Aye eye) Language contain all strings of a's and b’s with an input alphabet of ‘a’ and , where each string starts with aa or bb. Sol Note: States F and C can be combined into a single state. PREEEIEZ rc 1200 conian a stings ofa ena ' wi an input alphabet of’ ana where each sng starts wth ab ard ends wth ab. (Excluding the sting ab) solution Language contin al binary stings, where each sing contains 000 a substring Solution: | 1 | 0 7 warwmadeeasy.in MADE EASY Theory with Solved Examples | Computer Science & IT SMEs) GI MAE EASu FEEEEIEEEI rouge conan a binary sing, where each sing not contains 000, sek Language contain all binary strings, where the decimal value of each string is divisible by 3. Solu BERGEN Language contain all strings of a's and b's with an input alphabet of ', where each string contain second symbol from the beginning is ‘a’. Soluti and Language contain all strings of a's and b’s with an input alphabet of ‘a’ and where each string contain second symbol from the ending is 'b' (ending with ‘bat or ‘bb’). Solution: (Gy theory with Sotved Examples MADE EASY wwmeanodecasyiin G3 MADE ERSY [Sem ceeueed 2078] FEEEEIERE consict a minimal FA ortho regular language =| Solutior Lis the set of all strings start with ‘b. (ay o > La oDae MS = as FEEEEEEESEN «Construct a minimal DFA for the regular language L=(w,a w,|w,, we (a, bl") Solutior Lis the set ofall strings where every string contain ‘a’ Theory of Computation | bw Iwefa, b}) FREER) Construct minimal DFA forthe reguiar language U= fw a fwe(a, BF Soluti Lis the set of all strings end with ‘a’ GEEEIIERE) Gonsinct a minimal DFA forthe rogue language Solution: Lis empty language. ca Le No final state in DFA. J over E = (a, b} EERIE «Construct a minimal DFA for the regular language L = (aw b |we(a, b)*) Solution: Sot ofall stings start with a and end with b. (@mAbE Easy wowmadeeasy.in Theory with Solved Examples | Computer Science & IT SST) G3MACe easy Construct a minimal DFA for the regular language L = {w Iwe (a, bl", w contains an even number of a's} Solution: language L = (w |we a, b}*, w contains an odd number of b's) Soluti Construct a minimal DFA for the regular language L = {w |we(a, bj*, w has even length} Solution: Gy = 8 eee Construct a minimal DFA forthe regular language L = tw Twela,B) whas oat engi Soluti — OGIO ab XS Construct DFA forthe regu language t= Iw Tw coniaine oxacly two as.wele or} Solution: aa > mpd (Na a ~ Oe © | @ oa (EJ theory with solved Examples Ga Mave Easy wrenimeadesssyin (3 mApeE ERsY See two a's, wefa, D}*} Soluti Ee with same symbol, we (a, Solution: See ee meee Theory of Computation ry pA Construct a minimal DFA for the regular language L = {w |w contains atleast OHO) ey) Construct a minimal DFA for the regular language L = {w |w contains atmost Construct a minimal DFA for the regular language L = {w Iw starts and ends by} Construct a minimal DFA for the regular language L = {w Iw start and end with different symbols, w e{a, b}*} Soluti Qgmave easy Theory with Solved Examples FD | Computer Science & IT iow] GIMADE ERSY Construct @ minimal DFA for the regular language L = {w lw contain 3 consecutive a's, wefa, b}*} Solution: — ae 6 Q) J EEE Construct a minimal DFA for the regular language L = {w |w contain ‘a’ in every odd position, w e{a. b}*) Solution: Reguar expression [aja brea) Construct a minimal DFA for the regular language L. = (w Iw contains ‘b’ in every even position, we (a, b}*) Solution: Construct a minimal DFA for the regular language L = {w |we{a, b}*, w contains ‘every ‘a’ followed by exactly two b's} Solution: Construct a minimal DFA for the reguler language L = {w [we (a, *, w contains all a's followed by all b's} = (a""|m, n2 0}. Solution: 6-6-o-| (Gy Theory with Solved Examples MADE ERSY wunwmadeeasy.in G3MADE EASY ERA 2073] Theory of Computation ao Construct a minimal DFA for the regular language L. = (w Iw contains all a's followed by single ‘b’,w {a, b}*} = {a"b|m > 0}. Soluti Construct a minimal DFA forthe regular anguagel= (wlwela, 6) number of a's nwis eMisbi by 2) Sol Construct a minimal DFA for the regular language L = {w |wefa, b}*, number of b's in w is divisible by 3} Soluti EZ) Construct a minimal DFA for the regular language = (wlwefa, 0}, wl mod 3 = 0} Exampl Solution: Here, |w | mod 3 = 0 implies the length of wis divisible by 3 GEEEIEEEDE onsite minal A ortho voguarianguags” SS = (w| we(a, b}*, wlmod 32 1} Solution: Mod 3 has remainders: 0, 1.2 => 3 states. lw | mod 32 1 = q, and q, are final states, ‘goropresents remainder 0. eon) wooama ‘represents remainder 2 Wwenadieapar Gamabe ensy Theory with Solved Examples | Computer Science & IT PES so] 09 WADE ERsy fa" b"|m>1,n21) EGE Construct a minimal DFA for the regular language L = Ene Solutior 37 Sol FEEEIEEED «Construct a minimal DFA for the regular language | L=(vawlve fa, bh, we (a, by} Sol PEEEEEEEIN Constct a minimal 0 forthe regular ianguage L= wobl we (a Solution: Every string in Lends with ‘bb’ (EJ theory with solved Examples MADE EASY wanda GaMADE EASY EERSEee 2075) Theory of Computation EL = Construct a minimal DFA for the regular language L = {w levery occurrence of aais followed by a 'b’ in each w, we{a, b}*} Solution: Ems Construct @ minimal DFA for the regular language L = (ww (xe(a, 6)°, we (a,b\" wie the roverse of wh Soluti L=(ala.b}-a)v (bla. b}* 8) Construct @ minimal DFA for the regular language we {a,b}*, wis the reverse of w Solution: L=(a+oy (waw? Ixe{a, b}*, BMEIIEZEN Construct a wewy Te ela. we{a.b)"} Solution La(axor | —-@"* worm madeeasy.in GgMADE EASY Theory with Solved Examples | Computer Science & IT Sete 2os) G2MADE ERsy EEN Construct a minimal DFA for the regular language L = {wxwy Ix, ye{a, 6, Emo wea, B}*} Solu L ala, bi'ala, btu bla, by blab) Sa. —®& Construct a minimal DFA for the regular language L. wlwe (0, 1}* and last two bits are different) Solution: (GJ theory with solved Examples Gg MADE Ensy wwwamadeeasy.in GQMADE EASY ESR 00g) Theory of Computation EGE Construct a minimal OFA for the regular language is congruent to 1 modulo 3, we {a,b}*} = {wln,(w) mod 3 = 1, we{a.b}"). = (wiNumber of a’sinw Solution: 669" PREETI | Gonstca rininal FA forth reguarianguage L=(w lumber of bin wy mod § < 2, we{a, b] Soluti 2.2.3 Compound FA (D1 x D2) Let D1 and D2 be two DFA, Then operalions defined over D1 x D2 are (D1 U2), (0102). (01-02) and (D2 D1). Construction of compound FA for the given 01 and D2 as follows: D1 =(Q,2,8,, dp, F,) and D2 = (Q., 8. dp. Fs) 1. The number of states in compound FA (D1 x D2) is equal to mn, whore r isthe number of states of D1 and nis the number of states of D2. 2, Initial state of compound FA is combination of inital states of D1 and D2. Let qa be the start state of Dt and @, be the start of D2. (a, 4,8 intial state of D1 x D2, 3. Lett = {4p dy, dp} is set of states of D1, and Q2= (q,, gy} is set éf states of D2, Then Q1 x Q2= {ay as (Gos Hed (Is Ga): Is ahs (Fes Aas (Fs Meh 4. Assume g,is the final state of Dt and q, isthe final stato of D,, Final states depends on type of compound finite automata (D1 x D2) (2) (D1. D2) inal states: Make the states of (21 x Q2) as final, if inal state of D1 or final state of D2 contain in any of the states, (D1 w D2) accepts (D1) UL(D2} Final sates of (D1 U D2) = {(qp. 4) (@p. %): (Qo» Mp) (Qn Ge)h, where F1 = (a) and F2 = {q,) (o) (D1 D2) final states: Make the states of (Q1 x G2) is final, if bath final state of D1 and final sate of D2 contain in any ofthe states. (01 D2) accepts L(D1) a L(D2) Final sates of (D1 D2) = {(qp. ay) (©) (©1-De) inal states: Make the states of (21 x @2) as final inal state of Dt and non-final state of D2 contain in any of the states. (D1 -D2} accepts (D1) - L(D2) Final sates of (D1 ~ D2) = {(q2,q,)} where gi final state of D1 and q, is nor-fnal state of D2 (@) (02-D1) final states: Make the states of (Q1x G2) as final, final state of D2 and non-fnal state of D1 contain in any of the states. (D2 -D1) accepts L(D2) - L(D1). Final sates of (02~-D1) = {(q, 4). (ay. )}. where Q, sina state of D2, gy and a, are non-fnal states of D1 GRNINDALGaSIN (3 mabe ensu ‘Theory with Solved Example: | computer Science & 17 ESE) G3 MADE EASY Ea Construct a minimal FA that accepts a language over E = {a, b] where every string contain number of a's is divisible by 2 and number of b's is divisible by 3. Solution: Let FA1 be a DFA that accepts all strings containing number of as is divisible by 2 FAL Let FA © FA2 is a DFA thet accepts all strings containing number of a's is divisible by 2 and number of Bs is divisible by 3 FAI nFA2 Eo Construct a minimal FA that accepts a language over E = (a, b} where every string contain number of a's is divisible by 2 or number of b's is divisible by 3. Solution: Let FA\1 be a DFA that accepts all strings containing number of ais divisible by 2 Let FA2 be a DFA that accepts all strings containing number of b's is divisible by 3 LetFA1 UFAZis a DFA that accepts all strings containing number of as is divisible by 2 or number of B's is divisible by 3 (Gy theory with solved Examples Gg mabe Ensy wwwmadeeasy.in GQMADE EASY EEN Theory of Computation | FALUFAZ PREIS © = tl cocina vate of tinary number w is dvisbi by 20r8) Solution: Let FA1 be accepts all strings whose decimal value is divisible by 2 and FA2 accepts all strings singe decina vale i sil by 3 FA1 UFA2 accepts all stings divisible by 2 or 3. FAL FA Exampl Solution: Let FA1 be accepts all strings divisible by 2 and FA2 accepts all strings divisible by 3. winnaar (Sma~ade ensy ‘Theory with Solved Examples Solution: | Computer Science & IT RES 2os)| GIMASE Easy Ee -- {w/Binary number w is divisible by 2 but not divisible by 3} Let FA1 be accepts all strings divisible by 2 and FA2 accepts all strings divisible by 3. El. Solutio FA1-FAZ 4 x ? wi CN Gay = {wl Binary number w is divisible by 3 but not divisible by 2} Let FAI be accepts all strings divisible by 2 and FA2 accepts all strings divisible by 3. En - Solution: FA2-FAt (w| Binary number w is divisible by neither 2 nor 3} Let FAT be accepts all sings divisible by 2 and FA2 accepts all strings divisible by 3. (FAT~ FA) (FA2— FAN) ; = ee Ledley ‘ 2.3 Non-deterministic Finite Automata (NFA or NDFA) For every valid string there exists atleast one path from initial state that reaches to final state. (Every path may not reach to final state but atleast one path should exist). NFA caver transitions forall valid strings. NFA need not cover transitions for invalid combinations. For every valid string, NFA reach toone ofits final state with atleast one path, For invalid strings it may ‘or may not contain path that reaches to non-final state cs ‘Theory with Solved Examples G3 made Ersy wwwmadeeasy.in G32MADE EASY ERAT 2074] Theory of Computation 23.1 ication of NFA NFA = (Q, 2, 8, dy, F) is @ S-uple notation, where Q is the set of finite states, is an input alphabet contain finite number of input symbols Bis transition function defined over transitions of NFA for state and input, (8:0 x ~» 29) 8 a start state of NFA, (qye Q) F is the set of final states of NFA (F 2° is NFA transition function. + Construction of NFA is easier than DFA for many problems. * In NFA, zero or more number of transitions from any state for each input symbol. But in DFA there is exactly one transition from every state for each input symbol 2.3.3 Construction of NFA for Regular Language a Construct a minimal FA that accepts a language containing all binary strings where each string is starting with 0. Solution: © Construct a minimal FA that accepts a language containing all binary strings where each string starts with 1. Solution: (,\1sy) |-O--@D Construct a minimal FA that accepts a language containing all binary strings, where each string start and end with the same symbol. i.e, L = 0(0+1)°0 + 1(0+1)"1 +0 +1. mabe EASY ‘Theory with Solved Examples | Computer Science & IT ieee 2os)| GIMACE Easy Solution: Construct a minimal FA that accepts a language containing all binary strings, where each string starts and ends with different symbol. i.e. L = 0(0+1)"1 + 1(0+1)°0. Solution: Construct a minimal FA that accepts a language containing all binary strings where each string contains a substring ‘01. i.e. L = (0+1)*01 (0+1)* Solution: a a= HC) © Construct a minimal FA that accepts all binary strings where each string contains a third symbol from the beginning is 0. i.e. L = (0+ 1) (0+ 1)0(0+ 1)" OOO (EY theory with soived Examples ieee eee wormmadecasy.in GAME Gass RSE 2075] Theory of Computation | Construct a minimal FA that accepts all binary strings where each string Contains a third symbol from the ending (right hand side) is 0. Le. L = (0+1)°0 (0+1\0+1), Solution: A . ALTO) (e yey LIRA EF RD Construct a minimal FA that accepts all binary strings where each string contain 000" as a substring. i.e. L = (0+1)"000 (0+1)*. Solution: . Construct a minimal FA that accepts all binary strings where no string contain ‘000’ as a substring. Solutio Since ths language has @ negative condition we wil design a minimal DFA for its complement (containing ‘000" as substring), complement it and then remove the trap state i any, to get the required minimal NFA. The minimal OFA (for containing '000' as substring) is given below: Its complement which will be a minimal DFA accepting the required language (not containing ‘000' as substring) is given below: Now, removing the trap state D we get the requited minimal NFA for the given language. AUNT Gg mabe ERnsy ‘Theory with Solved Examples | Computer Science & IT kaos) GIMADE SASH “| FREER construct minimal Fa that acconis a language k= fab. nk 0) Solution: L = (walwe(e, 8) Solution: Se Solution: Lelewblwela, oF) Soluti TN E xe L = (ww contains exacily wo a, wefa,B) Soluti 6-6-8 [EJ Theory with Solved Examples G2 MADE Ensy www.madeeasy.in GQMADE EASY ERT) Theory of Computation = (wlw contains atleast two a's, we(a, b)*) : Saini Peat Onn Omen) = (ww contains amos wo a’, wel, BF Solution: L= fewelxe (a, b), we(a,b}") : Solution: nh Solution: (p\s8(s)28-(o)28-6) | TEPER EP AE) | Eze | Solution: iwlwe(a, by, [wl <3} 0" O"O*+© OO" OO | = (wlwe(a, bi lwl 2a) : Solution: | -O2-O2-O* ~S nunca (@mMADE Ensy Theory with Solved Examples | Computer Science & IT RSs) G3MACE Easy L= (wlw start with either aa or bb, wea, b]*). ie. L = (aa+bb)(a+b)" Solution: L = (wlw end with either aa or bb, we(a, bl"). ie. L = (a+b)*(aa+bb). Solutio 2b tp On ZY 2.3.4 Conversion from NFA to DFA (Subset Construction) In states are present in NFA then minimum number of states are present in DFAis 1 and maximumis 2° states, NFA = (Q, £, 8, dp, F) and DFA = (29, , 8, gy, FP’) Evory NFA can be converted to DFA as following 1. Inllal state of DFA is same as NFA 2, Ifthereis any new state while covering the transitions ofa stato of DFA then cover the transitions for the new state ao. 3. Repeat the step-2 until there are no new states to cover the transitions. Let&’ be a transition function of DFA and 6 is transition function of NFA. Transition function of DFA: 8(A, x) = Uyq.48(@.x), where A is a set of states of NFA and A is the state of DFA, qis a single state of NFA, xis an input symbol 4, fany of the states of DFA contain final state of NFA, then make that state as final lfm states are there in some NFA then the equivalent DFA has almost 2" states. Construct an equivalent DFA for the following NFA WATOT 7] » G | | fa. ct | L'a [eo [SJ Theory with Solved Examples G2 MADE ERSY www.madeeasy.in GME EASY ERE 2078) Theory of Computation | Solution: DFA initial state qs is same as inital state of NFA. DFA | 0 > % | (a) |. [Goat [fact | 10. a While covering the transitions of q,, the new state is created as (q, 4,h Final state of DFA is (q,, a,} which contains a final state g, of NFA, Construct an equivalent DFA forthe folowing NFA NFAT @ [6] [DFA] a] 6 > A) {ABI | {A} | =| tA) AB} (AP “B | (6) [iBi] [ABI TAB TAB) [ R 8.0 on fa) FERRET onstuct an equivalent OFA forthe folowing NFA Solution: Solution: NFAT a [6] [DFA] a [b =A [TABI | Al] = [STA ABTA) “Ble [é| ABABA Const a eauvalnt OFA forthe folowing NFA, oo i} | E+O+-6| witnadecasyle fampAbe easy ‘Theory with Solved Examples cs | computer Science & IT SSE oo) G3 MADE ensy Solution: WaTa ye) [PAT @ Te] Sataata) | 2a aa [a Bey Tier] | ae ABI | 1c) Spe Te MABC}| {ABC} IAC) AC) TABI Solution: [NFAT a] 5 [>A Ter (| ¢ | *C Hata Theory with Solved Examples (3 mabe Ensy Gaines GAMADE EASY ERS 2078) Theory of Computation Solution: S — |[DFA[ al b ig] Eales Berea | 8 [eee ee SCHECE Peis e tele Construct an equivalent DFA for the following NFA. Example-2.85 Solution: i bl NFA] a [b a SAAB TA 14) Bld le |= {A} [core HABCOI ADI} *0 | 18 [to “TAD | {ABDI [ADI] [ABCD IA 2.4 Epsilon NFA (e-NFA) For every valid string there exists a path from initial state that reaches to final state. e-NFA is same as NFA but t can include epsilon transitions e-NFA cover transitions forall valid strings similar to NFA. For every valid string, e-NFA reaches to one of its Final state with atleast one path. For invalid strings it may or may not contain a path that reaches to the non-final state, 24.1 Specification of e-NFA E-NFA = (Q, E, 8, do, F)is a S-tuple notation. where, Qis the set of finite states, iis an input alphabet contain finite number of input symbols, 8is a transition function of e-NFA, (8:Qx Zu {e} > 29) ais a start state of e-NFA, (q,¢ Q) Fis the set of final states of e-NFA, (Fc Q) 2.4.2 Conversion from e-NFA to NFA e-NFA = (Q, 2, 8, qo, F) and NFA = (Q, 2, 8, qo, F) Every e-NFA can be converted tothe NFA as folowing 1. Initial state of e-NFA is same as that of NFA 2. Transition function ofe-NFA: 8'(q, a) = closure (8(e-closure(), 2). \whore 8’ represents transition function of NFA and 8is e-NFA transition function Winnie omAve EAs Theory with Solved Examples KD | Computer Science & IT akon 2os] GIMAOE SASH e-closure (q) = the set of all the states which are reachable from state q by reading only (qis always reachable from g, so e-closure (q) includes q) 3. The number of slates in e-NFA is same as NFI 4, InNFA make all states as final where e-closure of that stale contain a final state of e-NFA. Constt an eauivaient NFA for tefl VY 1g €-NFA. NFA Solution: e-closure(A) = (A, B}, e-closure(B) = (B) Initial state A of NFA is same as initial state of e-NFA, Final states in NFA are both A and B, their e-closures contain final state B of e-NFA. x y P «|» © | A WA} Emo EP Construct an equivalent NFA for the following e-NFA. NFA Gq theory with Solved Examples Ggmabe Ersy wamadcedian GQMADE EAS (REM 207 Theary af Computation | Corsican eauvalant NFA forthe oloning NFA, NFA: 24.3 Conversion from e-NFA to DFA e-NFA = (Q, £, 8, do, F) and DFA = (29, 5, 8’, e-closure(q,), F’) Evory e-NFA can be converted to DFA as folowing: (2) Initial state of DFA is “e-closure of inital state of e-NFA\ Let qo s an intial state of e-NFA. Then e-closure(q,) is inital state of DFA. (b) Transition function of DFA: 8'(q, a) = e-closure (6(q, a)).. where 6’ and & are transition functions of DFA and e-NFA respectively (6) If any state of DFA contain final state of e-NFA, make that state as a final state in DFA. (@) e-NFA to DFA conversion also possible with the help of NFA. Convert first e-NFA to NFA, then convert NFA to DFA, Corsican eauvalort OFA forthe folowing eA. NFA Solution: e-closure(A) (A, B) and e-closure(B) mabe EASu Theory with Solved Examples | Computer Science & IT RESEewere 201s) GIMADE EASY Consnict an equivaint DFA forthe folowing e-NFA Ae AB a -@ Indirect transition table for e-NFA (NFA): [>A | {A Bi] (B} Solution: 3 é [8 intial state of DFA is e-closure(A), e-closure(A) = 14, Bp OFA 7 SCENIC) “a _ |e | ole Const en eaivlont OFA for tho folowing eNFA ab a ap | _fr «fr» & OGG | NFA a b ASIAB.C} IAB) a] eo] 6 °c [eer Solution: Indirect transition table for e-NFA (NFA): e-closure(A) = (A, B DFA a b TAB (ABO | (AB) ABCT (ABO) ABC] 2.5 Regular Expressions Regular expressionis an expression that generates exectly those strings which are in a regular languege. itis @ declarative way of reprosentation for a regular language Operators of Regular Expressions: +” R'is Keene closure of regular expression R. ("isa unary operator) + Ris positive closure of regular expression R, (*is a unary operator) + ie concatenation operator. (-isa binary operator) + +is oroperator.(+ is a binary operator) [SJ] theory with Solved Examples Gg made ersy wwnwmadeeasy.in 25.1 [a MADE EAsy = (Al stings of 9 and Bs) L= (Alstings start wih a) = (Allstings ends with 2} (Alsvings stan with 2 and aed with 8) L= (ll tings wth atmost two length L= (Al strings with atleast two length} L= (strings with exactly two length) L= (Al etings containing ‘at as a substing) L={inall stings, every ‘a must folowed by 8} L= {Al stings contain second eymbal rom LHS i a} L= (Al stings contain second symbol rom RHS is'2} | = (stings of even lena = (Alstings of oad length) 1L= Ever sting contain al a's followed by b8) Postal Study Course EXEL] Equivalence between Regular Languages and Regular Expressions Theory of Computation | (a+ bp =a ata+by" in (arbre aja oy (erbeey(arbee) (at by(as iar oy= (e+ bi(a+b) (a+ oy abje by" (ot any (as b)a(a+ be (a+ by (e+) (a+ oy(as by" (a+b) (a+ 8)(a+ By on + ovat 2.5.2 Equivalence between Regular Expressions and Regular Sets Regular Expression Regular Set Over == (0,1) [3] [aa] 15] 18 | lo 7 2 2 4 5 | e+x0serOryo 6 a a to 100 7 rn e @ 0) ont wo. ono tt +04 orto pir i 1(0* 170+ 000+ 1)1 (mabe EASY (oelwis empty string or ends with 0} (lw stat and end win same symbol) {orl caniinsa single one) (rly has atleast one 1) or wlwhas substing 1) Foor | (wlwcontains 00's a substring) (a+ory (| every On ws fotowed by atteast 4) exy (wrlwis oven length sng) rgiire €.0, 1,03), ornors {00,01, 10,14) (Ortee@riee) {ws sing with atmost 2 enath) oo +47 {iw star with 0} (or ayo ‘lwend wih’) | o@+tvo+o {lw stant and end with 0} 0+ 10 {ow start witht and end with 0) {weston ane end wih ifferent symbols) {star with + anc end with 00) Theory with Solved Examples | Computer Science & IT PES Ease 2018) GIMADE SASH 2.5.3 Properties of Regular Expressions using Operators (@) Union operator satisfies commutative property and associative property. + a+b=b+a (commutative) + a+(b+0)=(a +b) +c (associative) (b) The concatenation operator satisfies associative property but not commutative property + ab#b.a (not commutative) + a(b.c)=(ab).c (associative) (©) Both lett and right distributive properties of concatenation over union are holds + ald +c)=(ab)+ (ac) (Left distribution of. over +) * (a+b)ic » (ac) + (b.c) (Right distribution of, over +) (0) Both Jeft and right distributive properties of union over concatenation are not hokds. + a4(b0) #(a+b). (a+) + (ab) +c4(ato).(0+0) {© Sion operator sashes ibempoterh property bathe concalenstion operant doeenah hats, a (idempotent) + aaza(notidempotent) (9) Identity property: + R+6=6+R=R — (pisidentity element with respect to union operation) + eR=Re=R_ (eisidentty element with respect to concatenation) (9) Annihilator property: ReX = X © R4Et=E" (Eisanninilator with respect io union operator) + R.o=6 (Gis annihilator with respect to concatenation operator) 25.4 Equivalences of Languages (or Regular Expressions) Ltr, f2and rare regular expressions. J@ p+) i $0) Ut, te) =U) Lt) 1 Y=} Wy TIT (8) Het) = (Otay Att) = tet hts ©) renee +) ) o+ 0 We We no (mre (9) crear @r ore @w 0 () (e+m=r (e+e) ) plapy*= (oay'p () (p+a)=('a'y = (pray © (P+arp'g = (pray Consider the following regular expressions are over the symbols @ and b. = Regular expression R that generate all strings where each string start and end with ‘same symbol satb+a(a+byta+b(a+byo = Regular expression R that generate al strings where each string start with ‘a’ and not having two consecutive b's. A= (a+ ab)* Gq reory with Soived Examples Ggmmbe Easy aekalaaa = Regular expression R that generate all strings where length of the string is exactly ‘S" R=(a+b)(a+b)(a+b) = Regular expression R that generate all stings where the length of the string is least 3" R=(a+b)(a+b)(a+b)* = Regular expression R that generate all strings where the length of the string is atmost ‘3 Ra(arbre)(arb+e(arb+e) = Regular expression R that generate al strings where the length of the string is even = (a+b) (a+o))" = Regular expression R that generate all strings where the length of the string is divisible by 3, R=((a+b)(a+b) (a+b) Regular expression R that generate all strings where the length of the string is odd R=((a+b) (a+ b))". (a+b) = Regular expression R that generate all strings where each string contain exactly one'b’. R=at bat = Regular expression R that generate all strings where each string contain exactly two bis. R= at bat bat = Regular expression R that generate all strings where each string contain atmost two bs. Reat(b+eja'(breat = Regular expression R that generate al strings R= (a+b)* =(asb+e)*= (a°b*)' =(b'at) =(a*+b)*=(asby* 2.6 Equivalence between Finite Automata and Regular Expressions 2.6.1 Conversion from Finite Automata to Regular Expressions {A) State Elimination Method 1. More than one initial state is invalid. So simplify the transition graph such that it contain exactly one initial state and exactly one final state, 2, Simplify the transition graph such that it contain different states for initial and final 3, Eliminate all the states except initial state and final state by forming regular expressions. 4, Elimination of state 2: Before Elimination Alter Elimination ONMITNS NET) ILA NEN We ©) eC? (a) . ar . UTE ww inniodeenap: Qgmave Ensy ‘Theory with Solved Examples | Computer Science & IT EESEMTS 20s) G3 MADE EASY Rel RS) — 5 : 3 | | | ReMRIRE RL) RARER) (EJ Theory with Solved Examples G3 MADE EASY wormmadeeasyin G2MADE EASY ERB 2078] Theory of Computation 5. Continue the state elimination unti transition graph is converted to any one of the following with 2 states, o—O-O ner ee o—O+O (\ 2) org Recenastaats Rerintenrtyt 2) & O Oo @ Oe" a on Y ‘e FEEEEIEEIN Fir en equvaiont roglar expression forthe folowing tne automata, Solution: Keep initial and final states separately Delete state C: wormmadeeosyin GgMADE EASY ‘Theory with Solved Examples is} | Computer Science & IT EESEMetsco) G3MADE Easy Delete state B: (aa Delete state C: | Wy a b+abtab)' Regular expressior PEEEIIEEE Fin en cauivaiont requar expression for he flowing tite automata Solution: | Delete state B: —Y Regular expression = b'(aa‘b)(aa"b)* = b*(aa"b)* PREEIIEEIN Fic er cquivaiontreguar expression forthe folowing fie automata a Lo Solution: Regular expression = (a’a)*a" (bate) = (a*)*a" (bate) = a" (bate) ‘Theory with Solved Examples Gg MADE EASY wwwmadeeasy.in G2MADE EASY BSR 2075) Theory of Computation | EEE Find an equivalent regular expression for the following finite automata. Exampl & Delete 8: © Regular expresso ae Find an equivelon regular expression forte folowing fine automata Regular expression = (ba) (baa + b'ab) = (b%a)*b'a(a +b) = (b'a)-(a +b) (8) Arden’'s Method I P and Q are two regular expressions over an alphabet E and P does not contain e then the equation R= Q.+ RP has unique solution given by R = QP*, Note: The equation R = Q + PR, although it does not occur while converting FA to regular expression, can still be solved and the solution is R = P*Q. Example: The equation R = 10 + R(00+1), has a solution which is R= 10 (00+1)* and the equation R= 10 + (00+1) R, has a solution which is R= (0041)*10. Note: P contains ¢ then the equations R = Q + RP as well as R = Q + PR, both have infinite number of solutions, ‘wwwmadeeasy.in Gamabe ensy ‘Theory with Solved Examples | Computer Science & IT PSSEteiere 2s) GIMROE EASY We use Arden's Theorem to find the regular expression recognized by transition systems. NFA and DFA are transition system. While applying the Arden’s Theorems following assumptions are made regarding the transition system: ‘© The transition system (FA) does not contain e-moves. ‘©The transition has only one inital state. FEREEIEZIN Write an oquivalont regular expression for the following finite automata cS : a +{ Qy »_. a, Solutior (@) See that no eran tion is presentin finite automata (©) For each and every state find characteristic equation by using direct tran: sitions only (©) For nal state equation, add e Q,-Q,a+0,a CG oa) Q,=0,b4+0,b fe Qe20,a,2a,) = QarO,bre fe %e*-0,,0-2-0,, a4) (©) Express the final state(s) by regular expression whichis derived by characteristic equation of @’s and bs. Q,=0,a+Q,a Q,=Q,b+Q,b=Q, bb" (: R=Q+RP Substitute Q, in equation Q, Q, =Q,a + (Q, bb"a) = Q, b.bvaa" Substitute Q, in equation Q, Q, = Qa + (O,,bb‘a)a"b += Q, (a + bb‘a’b) ‘Substitute Qo in equation Q Q,=(a+ bb" at (a + bb‘a"by" bo” aat is equivalent regular expression for the given FA, PREETI sen eauivaent guia expression forthe folowing tne aomata, Solution: S=Sa+Sb+e (eis includ S=e+(a+b)S because Sis initial state) [2] theory with Soived Examples (gmpbe easy Tuna GAMADE EASY ERS 2075] Theory of Computation (Using Arden’s equation R = Q + RP and solution R= QP") (Sis final expression because Sis final state) So, the regular expression (a + b)" is recognized by the given DFA, Geos) Vite an equivalent regular expression for the following finite automata. Solution: A C=Ab [Az] 3 0-6 B= Aa+Ba+ 8b+ Ca=a+ Bat Bb+ba=Bla+b)+bara B= (ba + a) (a + b)*is equivalent regular expression BE] Write an equivalent regular expression for the following finite automata, oo 2 2 La la GO+O+38 Solution: A=Abte, B=Aa+Bb, O=Batcarcd AzAbte=b B= Aat+Bb=(bY)a+ Bb= brad" C= Ba+ Cat Cb=brab'a+ da+b) C= brabta(a + b)* is equivalent regular expression. Ems EJ Write an equivalent regular expression for the following Solution: AzetAa+Ba+Ca, B=Ab, C=B+Cb = C=Bb+Cb= Abb = AsesAa+Ba+Ca=e+ Aa+ Aba+Ca=e+Aa+ Aba + Abba + Cha = (e + Ca) + A(a+ ba + bba) (¢ + Cha) (a+ ba + bba)*bb + Cb {a+ ba + bba)*bb + Chala + ba + bbay'bb + Cb (a+ ba + bba)"bb + Olbala + ba + bba)*bb + b) = [a+ ba + bba}"bb) (bala + ba + bbay'bb + by = C=Abb+ Ct www.madeeasy.in G@maAbde EAsy ‘Theory with Solved Examples | Computer Science & IT eae 20s) GIMABE EASY 2.7. Regular Grammar {Allproductions of regular grammar are either leftinear productions or righ lineer productions. Regular grammars equivalent to lft near grammar and right linear grammar A grammars regular grammar if itis lett inear grammar or right linear grammar 2.7.1 Linear Grammar ‘© Class oflinear grammars are subset of context ree grammars and super set of regular grammars. '* Each production of linear grammar appears as: V—> T*VT*|T* + Lefthand side of the production contains a single non-terminal ‘© Righthand side of the produ $8 aSb|aS|Sblalbis linear grammar. jon contains almost one non-terminal 2.7.2. Left Linear Grammar (LLG) * Class of left Linear grammars are subset of linear grammars. * Each production of Left Linear grammar appears as: V-» VT*|T* where V is a variable and T is terminal. * Left hand side of the production contains a non-terminal, * Righthand side of the production contains either "a non-terminal followed by terminal sequence® or “terminal sequence’. i.e., non-terminal can appear only as a left most symbol. * $-+Sa|Sblalb is left inear grammar hence itis regular grammar. 2.7.3. Right Linear Grammar (RLG) + Class of ight inear grammars are subset of linear grammars + Each production or right near grammar appears as:V-»T*VIT* + Lefthand'side ofthe production contains anon-terminl + Righthand side ofthe production contains either *terminal sequence followed by anon-terminal or “terminal sequence’, non-erminal can apaear only as aright most symbol + §a8|bSlalbisrigntinear grammar + For every right linear grammar tnere exist an equivalent ft linear grammar and vice-versa 2.7.4 Equivalence of Grammars Regular grammar, left linear grammar and right linear grammar are always possible to generate the strings of given regular language. © Regular grammar oft linear grammars = Right linear grammars ‘© Allthese three grammars generate same class of language called as regular languages. 2.7.5 Conversion from RLG to Finite Automata Steps to convert ALG to finite automata 1. Starting state is named with starting symbol of given grammar 2, Final state is named with e 3. LetG =(V, TP, $) be the given ALG. Then we can const (Si). (fe) an equivalent e-NFA as M = (Q,T, 6, Gq Theory with soived Examples (3 mpAbe Ersy isnewcmadeediyin GaMBDE ERSS PERS 2075) Theory of Computation PEEEEERT) «onstuct an cauivaont tints automata forthe folowing ALG so1slo Solution: NFA can be constructed for the above given grammar is as following: @) PO FEEIEIER) Construct an equivalent tne automata for the flowing RLG S—as|bsla NFA: Solution: NFA can be constructed for the above given grammar is as follow na —-{s) an FEE) consti an equivalent fte automata othe owing ALG SbA A-aalbAlalb Solution: NFA can be constructed for the above given grammar is as following: NFA: — (5) Construct an equivalent finite automata for the following RLG. S—aAlaB A—adlbBlb 8+ bBlb LAG G3 mAbE ERsy Theory with Solved Examples is3 | Computer Science & IT kei 2os) GIMAOE Easy Solution: NFA can be constructed for the above given grammar is as following: 2.7.6 Conversion from Finite Automata to RLG Steps to convert finite automata to a RLG: 1. Initial state acts as @ start symbol 2. IFA, a) = B, then * AaB is a production i B is not final state * A aBlais a production if B is final state. 3. initial and final states are same then make them separate, Emotes | Find the equivalent RLG for the following finite automata. ~ Oe sO) xb Solution: ‘The equivalent right inear grammar is Ao aBlb8 Boaclbclalb EEE] | Find the equivalent RLG for the following finite automata, Or i Solution: ‘The equivalent right inear grammar is a aBlbe B28 |bBle Emiineeente) Find the equivalent RLG for the following finite automata, Solution: ‘The equivalent right linear grammar is: AsaBlba 8 bAlac C-raClbAle (25 Theory with Solved Examples (9 MADE EAs Waa GUMADE EASY EET Theory of Computation | PEEEIIER) Fir tn ccuivatnt LG for tho following fn automata. Solution: AaadlbAle FREI) ir te equivalent forthe follwing fn automata A-aB BbBlac CHaClbBle Dis useless symbol, so no need to write the productions of D. Find the equivalent LG forthe following fite automata 2 OO AsbalaBle Baalbe Solutior 2.7.7 Equivalence between Regular Expressions and Regular Grammars So] Regier Expression | atiUnear Grammar | Right Linear Grammar | Le Sale Sasle 2 | lerar S-salsble |S asibsle a | west 5 Salsolalo Sasloslalo 4 | aerey S—Salsbla SoaA AxaAlbale 5 | (esbro so AnAalaale Sasiosio 6 | ae S—ralbble 8 aAlesle onsale Amaalsle BblAle Bale 7 | @or S—sable S—absle 8 | ateror SAD Soak l [AS aalable Ax aAlbale PANAAE Ggmabe ensy Theory with Solved Examples

You might also like