Chapter 1 Mathematics Preliminary

Similar documents
Homework 3 Solutions

Regular Sets and Expressions

One Minute To Learn Programming: Finite Automata

FORMAL LANGUAGES, AUTOMATA AND THEORY OF COMPUTATION EXERCISES ON REGULAR LANGUAGES

Reasoning to Solve Equations and Inequalities

Solution to Problem Set 1

CS99S Laboratory 2 Preparation Copyright W. J. Dally 2001 October 1, 2001

Polynomial Functions. Polynomial functions in one variable can be written in expanded form as ( )

PROF. BOYAN KOSTADINOV NEW YORK CITY COLLEGE OF TECHNOLOGY, CUNY

0.1 Basic Set Theory and Interval Notation

Unit 6: Exponents and Radicals

Example 27.1 Draw a Venn diagram to show the relationship between counting numbers, whole numbers, integers, and rational numbers.

EQUATIONS OF LINES AND PLANES

Section 5-4 Trigonometric Functions

flex Regular Expressions and Lexical Scanning Regular Expressions and flex Examples on Alphabet A = {a,b} (Standard) Regular Expressions on Alphabet A

Pentominoes. Pentominoes. Bruce Baguley Cascade Math Systems, LLC. The pentominoes are a simple-looking set of objects through which some powerful

Binary Representation of Numbers Autar Kaw

Factoring Polynomials

Appendix D: Completing the Square and the Quadratic Formula. In Appendix A, two special cases of expanding brackets were considered:

Bayesian Updating with Continuous Priors Class 13, 18.05, Spring 2014 Jeremy Orloff and Jonathan Bloom

. At first sight a! b seems an unwieldy formula but use of the following mnemonic will possibly help. a 1 a 2 a 3 a 1 a 2

A Visual and Interactive Input abb Automata. Theory Course with JFLAP 4.0

P.3 Polynomials and Factoring. P.3 an 1. Polynomial STUDY TIP. Example 1 Writing Polynomials in Standard Form. What you should learn

Regular Languages and Finite Automata

Operations with Polynomials

Math 135 Circles and Completing the Square Examples

LINEAR TRANSFORMATIONS AND THEIR REPRESENTING MATRICES

Experiment 6: Friction

Algebra Review. How well do you remember your algebra?

1.2 The Integers and Rational Numbers

Multiplication and Division - Left to Right. Addition and Subtraction - Left to Right.

A.7.1 Trigonometric interpretation of dot product A.7.2 Geometric interpretation of dot product

Use Geometry Expressions to create a more complex locus of points. Find evidence for equivalence using Geometry Expressions.

Integration by Substitution

DATABASDESIGN FÖR INGENJÖRER F

Modular Generic Verification of LTL Properties for Aspects

5.2. LINE INTEGRALS 265. Let us quickly review the kind of integrals we have studied so far before we introduce a new one.

Vectors Recap of vectors

SPECIAL PRODUCTS AND FACTORIZATION

Chapter. Contents: A Constructing decimal numbers

Words Symbols Diagram. abcde. a + b + c + d + e

5 a LAN 6 a gateway 7 a modem

6.2 Volumes of Revolution: The Disk Method

Java CUP. Java CUP Specifications. User Code Additions You may define Java code to be included within the generated parser:

Review guide for the final exam in Math 233

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Friday 16 th May Time: 14:00 16:00

Or more simply put, when adding or subtracting quantities, their uncertainties add.

Basic Research in Computer Science BRICS RS Brodal et al.: Solving the String Statistics Problem in Time O(n log n)

FAULT TREES AND RELIABILITY BLOCK DIAGRAMS. Harry G. Kwatny. Department of Mechanical Engineering & Mechanics Drexel University

2 DIODE CLIPPING and CLAMPING CIRCUITS

Mathematics. Vectors. hsn.uk.net. Higher. Contents. Vectors 128 HSN23100

9 CONTINUOUS DISTRIBUTIONS

Treatment Spring Late Summer Fall Mean = 1.33 Mean = 4.88 Mean = 3.

Learning Outcomes. Computer Systems - Architecture Lecture 4 - Boolean Logic. What is Logic? Boolean Logic 10/28/2010

The Velocity Factor of an Insulated Two-Wire Transmission Line

Integration. 148 Chapter 7 Integration

and thus, they are similar. If k = 3 then the Jordan form of both matrices is

1. In the Bohr model, compare the magnitudes of the electron s kinetic and potential energies in orbit. What does this imply?

Answer, Key Homework 10 David McIntyre 1

The remaining two sides of the right triangle are called the legs of the right triangle.

Quick Reference Guide: One-time Account Update

AntiSpyware Enterprise Module 8.5

Econ 4721 Money and Banking Problem Set 2 Answer Key

19. The Fermat-Euler Prime Number Theorem

Rotating DC Motors Part II

1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall Final Exam

5.6 POSITIVE INTEGRAL EXPONENTS

3 The Utility Maximization Problem

Math 314, Homework Assignment Prove that two nonvertical lines are perpendicular if and only if the product of their slopes is 1.

RIGHT TRIANGLES AND THE PYTHAGOREAN TRIPLETS

Warm-up for Differential Calculus

9.3. The Scalar Product. Introduction. Prerequisites. Learning Outcomes

Bypassing Space Explosion in Regular Expression Matching for Network Intrusion Detection and Prevention Systems

Babylonian Method of Computing the Square Root: Justifications Based on Fuzzy Techniques and on Computational Complexity

Solving the String Statistics Problem in Time O(n log n)

Physics 43 Homework Set 9 Chapter 40 Key

AREA OF A SURFACE OF REVOLUTION

Example A rectangular box without lid is to be made from a square cardboard of sides 18 cm by cutting equal squares from each corner and then folding

DlNBVRGH + Sickness Absence Monitoring Report. Executive of the Council. Purpose of report

FUNCTIONS AND EQUATIONS. xεs. The simplest way to represent a set is by listing its members. We use the notation

1. Find the zeros Find roots. Set function = 0, factor or use quadratic equation if quadratic, graph to find zeros on calculator

Automated Grading of DFA Constructions

Automata theory. An algorithmic approach. Lecture Notes. Javier Esparza

MATH 150 HOMEWORK 4 SOLUTIONS

New Internet Radio Feature

Lec 2: Gates and Logic

Small Businesses Decisions to Offer Health Insurance to Employees

Ratio and Proportion

Generating In-Line Monitors For Rabin Automata

Concept Formation Using Graph Grammars

4.11 Inner Product Spaces

JaERM Software-as-a-Solution Package

Angles 2.1. Exercise Find the size of the lettered angles. Give reasons for your answers. a) b) c) Example

1 Fractions from an advanced point of view

Chapter 2 The Number System (Integers and Rational Numbers)

Module 2. Analysis of Statically Indeterminate Structures by the Matrix Force Method. Version 2 CE IIT, Kharagpur

Project 6 Aircraft static stability and control

Rotational Equilibrium: A Question of Balance

Data Compression. Lossless And Lossy Compression

Transcription:

1 Mthemtics Preliminry Chpter 1 Mthemtics Preliminry Answer for Exercises (Pge 13, Theory of Computer Science: Definitions nd Exmples. 3 rd Ed.) 1. ) {1,10,100} ) { n n Z nd n > 5 } c) { n n N nd n < 5 } d) {} e) { } or { } f) 2. 3. ) A union B, which consists of x, which is memer of A or x is memer of B. ) A intersect B, which consists of x, which is memer of A nd x is memer of B. c) A minus/differ B, which consists of x, which is memer of A nd x is not memer of B. d) A minus/differ B, which consists of x, which is memer of A or x is memer of B nd x is not memer of oth A nd B. e) x is not memer of A. f) crdintility of set A. Length or no. of elements in A. g) powerset of set A ) Is A suset of B? FALSE. ) Is B suset of A? TRUE. c) Wht is A B? Answer: A d) Wht is A B? Answer: B e) Wht is A x B? Answer: {(x,x), (x,y), (y,x), (y, y), (z, x), (z, y)} f) Wht is the power set of B? Answer: {, {x},{y},{x,y}} 4. ) {0, 6, 7, 8, 9} ) {0, 1, 2, 3, 5, 6, 7, 8, 9} = X = {0, 1, 5, 6, 7, 8, 9}, Y = {0, 2, 3, 6, 7, 8, 9}, X U Y =. c) {2, 3, 4, 5} d) {2, 5} 5. 1 P g e

1 Mthemtics Preliminry A B 1 2 3 4 ) U A B 1 2 3 4 ) U A B 1 2 3 4 c) U A B 1 2 3 4 d) A B 1 2 3 4 e) U 6. 7. ) {0, 1, 2, 3, 4, 6} ) {2} c) {1, 3} d) {0, 4, 6} ) {{λ}, {}, {}, {,}} 2 P g e

1 Mthemtics Preliminry ) {1, 2, 3, 1, 2, 3} 8. ) {{, }, {{, }}} ) {,, d} c) {{}{1}{2}{3}{1,2}{1,3}{2,3}{1,2,3}}-{{} {1}{3}{1,3}} = {{2}{1,2}{2,3}{1,2,3}} d) {{}{}{}{,}} X {{}{c}{d}{c,d}} = {({}, {}),({}{c}),({}{d}),({}{c,d}) ({,}, {}),({,}{c}),({,}{d}),({,}{c,d})} e) {{}} f) {({}, ), ({}, ), ({}, ), ({}, ), ({}, ), ({}, ), ({, }, ), ({, }, )} g) {(1,1,1), (1,1,2), (1,1,3), (1,2,1), (1,2,2), (1,2,3)} 9. 5 10. A x B hs * elements. A x B stnds for crtesin product which is formed s set of tuples tking ech element from ech set. So for 2 x 2 set. {, } x {c, d} = { (,c), (,d), (,c), (,d)}, thus there re 4 elements. 11. There re x 2 elements in the power set of X. In order to explin this conclusion, I sk you to imgine string of x its, ech it representing n element in X. If we llow 0 to indicte the sence of n element in the superset nd 1 to indicte the presence of n element, we'll find the numer of comintions of 0s nd 1s to e the numer of elements in the powerset. For inry numer of length x, we hve x 2 such comintions. 12. 13. ) It is the set of ll odd nturl numers. ) It is the set of ll even rel numers. c) It is set of even nturl numers. d) It is set of nturl numers which re divisile y oth 2 nd 3. e) It is set of inry numers which re i-directionl (tht is red the sme from left to right nd lso from right to left). f) It is set of ll integers. A = Everything in set U ut NOT in set A = {18, 19, 20, 22, 24, 26, 28} B' = Everything in set U ut NOT in set B = {18, 19, 20, 21, 22, 23, 24, 25} Now simply comine the two sets A' nd B' (nd remove ny duplicte elements) to get A U B = {18, 19, 20, 22, 24, 26, 28} U {18, 19, 20, 21, 22, 23, 24, 25} = {18, 19, 20, 21, 22, 23, 24, 25, 26, 28} So the nswer is A U B = {18, 19, 20, 21, 22, 23, 24, 25, 26, 28} 3 P g e

1 Mthemtics Preliminry 14. 15. U = {l, m, n, o, p, q, r, s, t, u, v, w} A = {l, m, n, o, p, q} B = {n, o, r, s, v, w} C = {l, m, p, q, r, t} find (A U C ) B. A = {r,s,t,u,v,w} C = {n,o,s,u,v,w} A U C = {n,o,r,s,t,u,v,w} B = {l,m,p,q,t,u} (A U C ) B = {t,u} ) A B = Set of elements tht BOTH sets A nd B hve in common A B = {1, 2, 3} {3, 4, 5, 6} A B = {3} ) A C = Set of elements tht BOTH sets A nd C hve in common A C = {1, 2, 3} {3, 5, 7} A C = {3} c) A U C = Comintion of the sets A nd C (remove ny duplictes) A U C = {1, 2, 3} U {3, 5, 7} A U C = {1,2,3,5,7} d) B U C = Comintion of the sets B nd C (remove ny duplictes) B U C = {3, 4, 5, 6} U {3, 5, 7} B U C = {3,4,5,6,7} 16. To strt with I m going to ssume tht U = {All the lowercse letters of the lphet}. If this is incorrect, then the nswers to (c), (d) nd (e) will e incomplete. To void ny potentil confusion, I will use U for the "universl" set nd "u" for the union opertor When the elements of set re listed, the order is not importnt The union opertor, u, is n inclusive opertor. The union of two sets will lwys include every memer of oth sets. Elements of oth sets, if ny, re listed only once in the union. (Never list duplicte elements in ny set.) The intersection opertor,, is n exclusive opertor. The intersection of two sets will include only elements tht re memers of oth sets. 4 P g e

1 Mthemtics Preliminry () A u B This mens "the set whose elements re memers of set A or set B (or oth)". A u B = {c, d, e, f, g, h, k} () A B This mens "the set whose elements re memers of oth set A nd set B". A B = {e, f} (c) A B A mens "the set of ll elements of the universl set, U, which re not memers of set A. A = {,, g, h, i, j, k, l, m,..., z} B mens "the set of ll elements of the universl set, U, which re not memers of set B. B = {,, c, d, i, j, l, m,..., z} A B mens "the set whose elements re memers of oth set A' nd set B'". A B = {,, i, j, l, m,..., z} (d) A u B This mens "the set whose elements re memers of set A or set B (or oth)". Using A nd B from (c) we get A u B = {,, c, d, g, h, i, j, k, l, m,..., z} (e) A u B This mens "the set whose elements re memers of set A or set B (or oth)". Using A nd B from (c) we get A u B = {,, c, d, e, f, i, j, l, m,..., z} (f) (A u B ) B The first prt of this is the nswer to prt (e). (A u B ) B mens "the set whose elements re memers of the set B nd memers of the nswer to prt (e)" (A u B ) B = {e, f} (g) (A u B) (A u B ) The first prt is the nswer to prt (), The lst prt is the nswer to prt (e). So (A u B) (A u B ) mens "the set whose memers re memers of the nswer to prt () nd memers to the nswer to prt (e)". So (A u B) (A u B ) = {c, d, e, f} (which is set A} 5 P g e

1 Mthemtics Preliminry 17. ) is simply the union etween the two sets. So simply tke ll of the uniqe elements of ech set nd put them together in the new set So ) is simply the intersection etween the two sets. So whtever elements in two sets hve in common will mke up with set B") (which in English sys "set A intersect Since set A nd set B hve the element "c" in common, this mens the intersection of sets A nd B gives us: c) The nottion A' simply mens the set of every letter tht is NOT in set A. So A' is the entire lphet ut with the letters,c, nd d tken out of it So The nottion B' simply mens the set of every letter tht is NOT in set B. So B' is the entire lphet ut with the letters c, e, f, nd g tken out of it So Now let's tke the intersection etween the two sets. Since set A' nd set B' hve the elements, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, nd z in common, this mens the intersection of sets A' nd B' gives us: d) Using the sme sets A' nd B' from prt c) is simply the union etween the two sets. So simply tke ll of the uniqe 6 P g e

1 Mthemtics Preliminry elements of ech set nd put them together in the new set So Strt with the given sets: Find their respective complement sets: e) So Rememer, union is simply the comintion of the unique elements from oth sets f) From prt ), we got So Rememer, to find the intersection of two sets, simply look for ny elements tht the two sets hve in common g) First find So 7 P g e

1 Mthemtics Preliminry 18. To find the numer of elements in the set K J, simply dd the two sets together. However, rememer to sutrct the numer of elements in oth sets (since these elements re repeted) In other words, use this formul: n(k J) = n(k) + n(j) - n(k J) In this cse, n(k)=30, n(j)=46 nd n(k J) = 11. Plug these vlues in to get: n(k J) = 30 + 46-11 Add n(k J) = 76-11 Sutrct n(k J) = 65 So there re 65 elements in set K J #(K J) = #(K) + #(J) - #(K J) = 30 + 46 11 = 65 19. Notice how ALL of the elements of set A re lso elements of set B, so this shows us tht set A is suset of set B (ie ll of A is in B). So Note: the two sets A nd B re NOT equl since set B hs the element 12 (ut set A does NOT hve the element 12) 20. Drw two overlpping circles, lel one A nd one B, like this First look t these words: 9 letters nd 1 numer is common to oth sets. 8 P g e

1 Mthemtics Preliminry Letting L stnd for letter nd N stnd for numer, put 9 L's nd 1 N in the prt in the middle which is common to oth circles, like this: Next look t these words: Set A hs 9 letters nd 3 numers. Set A lredy hs 9 letters nd 1 numer ecuse they re in the prt tht is in common to oth circles. So set A needs 2 more numers so it will hve 3 numers. (It doesn't need ny more letters). So we put 2 N's in the left prt of A, like this: nd now set A hs 9 letters nd 3 numers. Next we look t these words: Set B hs 12 letters nd 1 numer. Set B lredy hs 9 letters nd 1 numer ecuse they re in the prt tht is in common to oth circles. So set B needs 3 more letters so it will hve 12 letters. (It doesn't need ny more numers). So we put 3 L's in the right prt of B, like this: nd now set B hs 12 letters nd 1 numer. 9 P g e

1 Mthemtics Preliminry Now the question is: Wht is the numer of elements in set A or set B? If we count ll the L's nd N's tht re in either one of the two sets, we see there re 12 L's nd 3 N's, so tht mkes 15 elements. Answer: 15 elements. 21. In survey of college with 50 memers, 21 were tking mthemtics, 36 were tking English, nd 9 were tking oth. How mny were not tking either of these sujects? We drw rectngle with two overlpping circles, one red nd one lue. There re two circles. The red one contins ll the students tking mth. The lue one contins ll the students tking English. Note tht the red circle nd the lue circle overlp. Here is the mistke mny students mke, so DO NOT mke this mistke: Mny students would see the words "21 were tking mthemtics,36 were tking English,", nd put ll 21 in region "", nd ll 36 in region "c", like this: DO NOT mke tht error!!! Some, ut not ll, of the 21 go in region "" nd the rest of the go in region "". Similr, Some, ut not ll, of the 36 go in region "d" nd the rest of the go in region "". So we do not egin with either the 21 or the 36. 10 P g e

1 Mthemtics Preliminry Insted we egin with "9 were tking oth". These 9 go in the middle region,, ecuse those 9 re in oth the red circle nd the lue circle. So we put the 9 in region : Now we see "21 were tking mthemtics", nd of this 21, 9 re tking English too, so we must sutrct the 9 tht re in the middle region, getting 21-9 = 12, nd we put 12 in region "": Now we see "36 were tking English", nd of this 36, 9 re tking too, so we must sutrct the 9 tht re in the middle region, getting 36-9 = 27, nd we put 27 in region "c": We hve one more region, "d". Tht is the region outside of oth circles. They re the ones tht re neither tking mthemtics nor tking English. We hve ccounted for 12+9+27 = 48. We re told there re 50 memers. So there re 50-48 = 2 tht hve not een ccounted for. Those 2 go in the outer region "d": 11 P g e

1 Mthemtics Preliminry So the nswer to the prolem is those 2. 22. F' = Set of everything in U ut NOT in F = {Lower cost, Less time to see the sights, Cn visit reltives long the wy} D' = Set of everything in U ut NOT in D = {Higher cost, More time to see the sights, Cnnot visit reltives long the wy, Less time to see the sights} Now just look for the common elements in oth sets. Since there re no common elements, this mens tht the result of the intersection etween these sets is the empty set. 23. The first thing is to find out how mny do tke either lnguge. Since 25 don't tke either tht mens tht 80-25 tke t lest one of them. 55 tke t lest one of them 30+40 study French nd Spnish. 70-55 tke oth French nd Spnish nd 15 tke only Spnish nd 25 tke only French. 24. First drw 2 overlpping circles cll the left circle qurium nd the right zoo. Second, drw smll horizontl lines in ech of the three regions nd lso one on the outside right of the digrm. step 1 - "15 hd oth" mens put 15 into the overlpping region shred y oth. step 2 - "22 hd memership to the Birch Aqurium" mens tht 15 + x = 22 - > so x = 7. Put 7 on the qurium line. step 3 - "26 hd memership to the Sn Diego Zoo" mens 15 + y = 26 - -> so y = 11. Put n 11 on the zoo line. step 4- there is only one line left, the outside. "140 Sn Diego residents" mens tht ll lines of informtion must dd to 140. We hve 7 + 15 + 11 + z = 140 - -> z = 107. Put 107 on the outside line. i. How mny hd only zoo memership? this is y, so 11 12 P g e

1 Mthemtics Preliminry ii. How mny hd only n qurium memership? this is x, so 7 iii. How mny elonged to either one or the other or oth? this is 15 + 7 + 11 = 33 iv. How mny elonged to neither? this is z, so 107 26-15=11 11 hd only zoo 22-15=7 7 hd only qurium 7+15+11=33 33 elonged to one or oth 140-33=107 107 elonged to neither 25. Since 35 students re in lger, nd 18 re in oth, this mens tht 35-18=17 students re in lger only. Also, ecuse 52 students re in history, nd 18 in oth clsses, there re 52-18=34 students in just history lone. Now dd up the numer of students in lger only (17), the numer of students in history only (34), nd the numer of students in oth (18) to get: 17+34+18=69 So there re 69 students in either clss or oth. Now sutrct this figure from 100 to find the numer of students who re in neither clss: 100-69=31 So there re 31 students in neither clss. 26. Use Venn Digrms: Drw two intersecting circles inside rectngle. Lel one circle "rown eyes" ; Lel the other circle "londe hir". put "10" in the intersection of the circles. put "23" in the rectngle ut not in either circle put 25-10 = "15" in the rown eyes circle tht is not in the intersection put 15-10 = "5" in the londe hir circle tht is not in the intersection Count up ll the "" numers to get 53 Tht is the numer of people interviews. 13 P g e

1 Mthemtics Preliminry Follow this sme pttern to work the other prolem you posted which involves three intersecting circles. 27. If you wnt to mke your Venn digrm on the computer, here re some symols/shpes you might need: 3 intersecting circles r, l, r-l- 7 l- 19-7=12 r- 17-7=10 r-l 15-7=8 r 34-8-10-7=9 l 30-8-12-7=3 37-10-12-7=8 ) r=9 ) r + l + =9+3+8=20 c) 7+12+10+8+9+3+8=57 d) l- + r- + r-l = 12+10+8 =30 e) 75-57=18 14 P g e

2 Lnguges Chpter 2 Lnguges Answer for Exercises (Pge 45, Theory of Computer Science: Definitions nd Exmples. 3 rd Ed.) Prt A Multiple Choices Questions 1. B 2. D 3. B 4. B 5. C 6. D 7. C 8. A 9. D 10. C 11. D 12. C 13. D 14. C 15. A 16. C 17. D 18. A 19. B 20. D 21. C 22. D 23. D 24. B 25. C 26. D 27. D 28. C 29. D 30. A 31. D 32. D 33. D 34. D 35. A 36. C 37. D 38. C 39. A 40. C 41. D 42. D 43. D 44. C 45. A 46. B 47. A 48. C 49. A 50. B 1 P g e

2 Lnguges Prt B 1. Structured Questions ) { } ) {0, 00, 000} c) {0, 00, 000, 0000, 00000, 000000} d) {01111, 001111, 0001111} e) {011011, 0110011, 01100011, 0011011, 00110011, 001100011, 00011011, 000110011, 0001100011} f) {111111} g) {, 0, 00, 000, 0000, 00000, 000000,...} h) {00, 000, 0000, 011, 00000, 0011, 000000, 00011, 110, 1100, 11000, 1111} 2. First we oserve tht L1 = {ε,,,,,,,,,,,,,, }. ) L3 = {ε,,,,,,,,,,,,,,, } ) L4 = {, } c) L5 = every wy of selecting one element from L1 followed y one element from L4: {ε,,,,,,,,,,,,,, } {ε,,,,,,,,,,,,,, }. Note tht we've written ε, just to mke it cler how this string ws derived. It should ctully e written s just. Also note tht some elements re in oth of these sets (i.e., there's more thn one wy to derive them). Eliminting duplictes (since L is set nd thus does not contin duplictes), we get: {,,,,,,,,,,,,,,,,,,,,,, } d) L6 = every string tht is in L1 ut not in L2: {ε,,,,,,,,,,,, }. 3. ) Yes. n = 0 nd m = 0. ) Yes. n = 1 nd m = 0. c) Yes. n = 0 nd m = 1. d) No. There must e equl numers of 's nd 's. e) Yes. n = 2 nd m = 2. f) No. There must e equl numers of 's nd 's. 4. Y = {would, wood, could, cood} 5. ) {,,,, } ) {,,,,, } c) 8 d) {λ,,,, } e) {,,,,,,, } 2 P g e

2 Lnguges 6. ) X 0 Y = Y = {} X 1 Y = {} X 2 Y = {} X 3 Y = {} ) XY 0 = {} XY 1 = {} XY 2 = {} XY 3 = {} c) (XY) 0 = {λ} (XY) 1 = {} (XY) 2 = {} (XY) 3 = {} 7. { λ, 0,1,00,01,10,11,...} 8. ) 2 ) 2 c) All strings over {, } tht contin multiple of 9. Tle 1 Sustring Prefix Suffix None 10. ) No ) {,,,,,,,,,, } 11. ) No ) No c) No 12. ) The lnguge consisting of ny conctention of s nd s of even length. 3 P g e

2 Lnguges ) If S contins ll possile strings of nd of length 3, then ll the words in S* will hve length divisile y 3 nd will include ny conctention of s nd s (ecuse S did). By the product rule, there re 2*2*2 = 8 possile words of length 3: S = {,,,,,,, } c) S* = { nd ll possile strings of s nd s of ny length}. This is ecuse S nd S, nd ny comintion of these letters cn result in ny word. Furthermore, n odd word + nd odd word = n even word. n odd word + n odd word + n odd word = n odd word. So oth odd nd even words re included. 13. ) Y = {00, 01,10, 11} ) {10000, 10001, 10010, 10011} c) {00100, 01100, 10100, 11100} d) {10000100, 10001100, 10010100, 11100} 14. ) 11(1 0)*00 ) (11(1 0)*) ((1 0)*00) c) 11(1 0)*00 15. {,,,,, } 16. IN the lnguge,,,,, Tle 2. Descrie the lnguge in your own words All strings over {, } tht end with,,, All strings over {, } tht do not contin sustring,,,, All strings over {, } tht do not contin sustring,,,,,,,, All strings over {, } tht contin sustring nd end with or 17. Tle 3. IN the lnguge,,,,,,,,, NOT IN the lnguge,,,,,,,,, 18. ) (R ) is R since does not dd nything to their union, nd (R ) mens ppending nothing to ll strings in R which is lso R, hence they re the sme. ) (R ) represents the set R nd empty string. c) (R ) represents R. 4 P g e

2 Lnguges 19. 20. 21. ) All string tht contin only s re not in the lnguge. I.e.:,,, ) {,,,,,,,,,,,,,,,,,,,,,, }. To understnd how they re generted, we need first to list down ll of them strting from the most sic fctor s follows: ( + ) 0 ( + ) 0 = ( + ) 0 ( + ) 1 =, ( + ) 1 ( + ) 0 =, ( + ) 1 ( + ) 1 =,,, ( + ) 0 ( + ) 2 = ( + )( + ) =,,, ( + ) 2 ( + ) 0 = ( + )( + ) =,,, ( + ) 1 ( + ) 2 = ( + )( + )( + ) =,,,,,,, ( + ) 2 ( + ) 1 = ( + )( + )( + ) =,,,,,,, Other thn these fctors re excluded ecuse they will produce the string with more thn 4 letters. Now we will remove ny duplicte strings nd we get = {,,,,,,,,,,,,,,,,,,,,,, }. ) 001, 011, 0001, 0011; ny string of length 3 or greter tht is one or more 0 s re followed y one or more 1 s. ) 111, 0111, 01011, 010101; ny string tht hs t lest three 1 s. c) 0, 1, 01, 0101; ny string tht hs no sustring 110. d) 1, 01, 1011, 10110; ny string tht hs no sustring 00 fter first 11 (if there is ny 11 in the string). ) ( + ) 0 = = ( + ) 1 = ( + ) =, ( + ) 2 = ( + ) ( + ) =,,, ( + ) 3 = ( + ) ( + ) ( + ) =,,,,,,, So ( + )* = {,,,,,,,,,,,,,,,...} ) 0 0 = 1 0 = 0 1 = 1 1 = 2 1 = 1 2 = 2 2 = So ** = {,,,,,,...} 5 P g e

2 Lnguges c) () 0 = () 1 = () 2 = () () = () 3 = () () () = So ()* = {,,,,.} 22. Let X = ; nd Y = (XY) r = () r = Y r X r. = () r () r = () () = 23. Length is n+1 24. Three possile generted strings Shortest string which is NOT in the lnguge,,,,,,,,,,,,,,,,,,,,,,,,,, 25. 0*11*222* 26. {, }* 27. *** + * or ( + )*( + )*( + )* or **( + )* 28. ) the lnguge of ll strings over {, } tht strts nd ends with. ) the lnguge of ll strings over {, } with s the second letter. 29. ) ( + ) + ) () + c) () + ()*() + d) ()* + ()* e) ( + )*( + )( + )* f) ( + )* + ( + )* g) ( + )* 30. ) **c*. ) + *c* * + c* **c +. 6 P g e

2 Lnguges 31. ) nd re memers, nd re not memers. ) nd re memers, nd re not memers. 32. ) **c*. ) + *c* * + c* **c +. c) ( c)( c)( c). d) ( c) 0 ( c) 1 ( c) 2. e) ( c) + ( c) + ( c) +. f) ( ) + ( )* ( )*( ) + g) + + h) ( )*( )*( )* ( )*( )*( )*. The two expressions joined y the indicte tht the my precede or follow the. i) ( )*( )*( )* j) The leding nd triling cc explicitly plced in the expression ( c)*( c) *( c)*cc. Any numer of s nd c s, represented y the expression ( c)* my surround the two s. k) At first glnce it my seem tht the desired lnguge is given y the regulr expression ( )*( )*( )* ( )*( )*( )*. Clerly every string in this lnguge hs sustrings nd. Every string descried y the preceding expression hs length four or more. Hve we missed some strings with the desired property? Consider,, nd. A regulr expression for the set of strings contining sustrings nd cn e otined y dding ( )*( )* ( )*( )* to the expression ove. l) ( c + c)* m) The lnguge consisting of strings over {, } contining exctly three 's is defined y the regulr expression ****. Applying the Kleene str to the preceding expression produces strings in which the numer of 's is multiple of three. However, (****)* does not contin strings consisting of 's lone; the null string is the only string tht does hve t lest three 's. To otin strings with no 's, * is conctented to the end of the preceding expression. Strings consisting solely of 's re otined from (****)** y conctenting, from (****)* with 's from *. The regulr expression (***)* defines the sme lnguge. n) *( c)*( c)*( c)* or *(( c)*) 3 o) In the regulr expression ( )*, 's followed y re produced y the first component, 's preceded y y the second component, nd two 's "covered" y single y the third component. The inclusion of within the scope of the * opertor llows ny numer dditionl 's to occur nywhere in the string. Another regulr expression for this lnguge is (( )( ))*. p) ( + + )* or ()* + * or ( )*( ) q) ( + + )( + )* r) Every in the expression ( )* is followed y t lest one, which precludes the occurrence of. However, every string in this expression ends with 7 P g e

2 Lnguges while strings in the lnguge my end in or s well s. Thus the expression ( )*( ) represents the set of ll strings over {, } tht do not contin the sustring. s) A string cn egin with ny numer of 's. Once 's re generted, it is necessry to ensure tht n occurrence of is either followed y nother or ends the string. The regulr expression *( + )*( ) descries the desired lnguge. t) ( )*( )* u) To otin n expression for the strings over {,, c} with n odd numer of occurrences of the sustring we first construct n expression w defining strings over {,, c} tht do not contin the sustring, w = *( c*)*: Using w, the desired set cn e written (ww)*ww. v) (( c)( c))*( c c)(( c)( c))* w) ()*()*()* ()*()*()* ()*()*()* x) The regulr expression (**)** (**)*** defines strings over {, } with n even numer of 's or n odd numer of 's. This expression is otined y comining n expression for ech of the component susets with the union opertion. y) ([ ()*] [( ()*)(()*)*( ()*)])*. 33. Tle 1. Tle 2. No. Mtching no. of lnguge Generte 3 possile strings 1. 9,,, 2. 11,,, 3. 12,,, 4. 1,,, 5. 2,,, 6. 6,, 9. 3,,, 10. 14,,, 11. 13,,, 12. 4,, 13. 5,,, 14 15,, 15 10,, 8 P g e

3 Context-Free Grmmr Answer for Exercises (Pge 45, Theory of Computer Science: Definitions nd Exmples. 3 rd Ed.) Prt A Multiple Choices Questions 1. B 2. B 3. D 4. C 5. D 6. D 7. D 8. C 9. D 10. A 11. A 12. C 13. C 14. B 15. C 16. B 17. A 18. A 19. D 20. D 21. B 22. D 23. B 24. C 25. C 26. A 27. D 28. A 29. D 30. C 31. B 32. D 33. C 34. A 35. B 36. B 37. B 38. A 39. A 40. A 41. A 42. B 43. C 44. C 45. D 46. D 1 P g e

3 Context-Free Grmmr Prt B Structured Questions 1. ) S SAB SABAB λabab λbab λbab λbab λλab λλab λλb λλb λλλ ) S SAB S SAB λab SABAB λab λabab λb λbab λλ λλab λλb λλλ c) S S A B λ A λ S S A B S A B λ λ λ d) (**)* 2 P g e

3 Context-Free Grmmr 2. ) Derivtion Rule S Sc S Sc Scc S Sc Acc S A cadcc A cad ccddcc A cd c) The derivtion tree corresponding to the preceding derivtion is S S c S c A c A d c d d) L(G) = {() n c m d m c n n 0; m > 0} 3. ) Derivtion Rule S ASB S ASB ASB A A ASB A A SB A B S B ) Derivtion Rule S ASB S ASB ASB B B AS B AASB S ASB AASB B B AAS B AAASB S ASB AAAS B AAA S 3 P g e

3 Context-Free Grmmr AAA A A AAA A A AA A AA A A A A A c) S A S B A A S A S B A S B B A A S B B A A d) L(G) = { n1 n1 nk nk m1 m1 ml ml n i, m i > 0; k, l 0; k l} 4. ) S AB AB B AB B 4 P g e

3 Context-Free Grmmr ) S AB AAB AB A A 5. Set nottions { 2i i *, i 0} or {() i j i > 0, j i} { } or { 2i j i > 0, j i} { }. { n c + 2n, n 0} or { n c m () n n 0, m > 0} or { n c m 2n n 0, m > 0}. {() n (cd) m () m (dc) n, n 1, m 0} { n c m p p d m n, m 1, n 0, p 1} { k j 0 < k j 2k} Descriptions The S rules S SB nd S generte n equl numer of leding 's nd triling B's. Ech B is trnsformed into one or more 's. Since t lest one ppliction of the rule S SB is necessry to generte 's, strings consisting solely of 's re not in the lnguge. The lnguge of the grmmr is {() i j i > 0, j i} { } or we cn write { 2i j i > 0, j i} { }. The recursion of S rules S S generte n equl numer of leding 's nd triling 's. The recursion is terminted y n ppliction of the rule S A. Ech A is trnsformed into one or more c's. The lnguge of the grmmr is { n c m () n n 0, m > 0} or we cn write { n c m 2n n 0, m > 0}. Repeted pplictions of the recursive rule S Sdc produce string of the form () i S(dc) i, i 0. The recursion is terminted y n ppliction of the rule S A. The A rules produce strings of the form (cd) j () j, j 0. The lnguge generted y the rules is {() i (cd) j () j (dc) i i 0, j 0}. Repeted pplictions of the recursive rule S S produce string of the form m S m, m 0. The recursion is terminted y n ppliction of the rule S A. The A rules produce strings of the form c n Ad n, n > 0. While the B rules produce strings of the form i B i, i > 0. The lnguge generted y the rules is { m c n i i d n m m 0; n, i > 0} The rule S SB genertes strings of the form k SB k, y pplying the first option of the rewrite rule k times, or k B k y pplying the second option to replce S. The rule B, pplied k times to the strings generted ove will eventully yield k ( ) k. This cn e written s L = { k j 0 < k j 2k}. Shortest string nd 3 other strings,, c c cc ccc dc / cd cddc, cdcddc, cdcddcdc cd cccddd, cd, cd,, 5 P g e

3 Context-Free Grmmr 6. S AB A A B cb c 7. The lnguge consisting of the set of strings { n m c 2n+m m, n > 0} is generted y S Scc Acc A Ac c For ech leding generted y the S rules, two c's re produced t the end of the string. The rule A rules generte n equl numer of 's nd c's. 8. This grmmr cn e constructed y first generting s mny 's s c's to the left nd right. Susequently generte s mny 's s c's in the middle. This gives us s mny 's nd 's s c's. Then we crete possily more c's. S Sc B Generte n Bc n, n 0 y pplying left option n times. B Bc C Use n Bc n nd this rule to generte n m Cc n+m, n, m 0. C cc Use n m Cc n+m nd this rule to get n m c j c n+m, n, m, j 0}. This gives us the lnguge L = { n m c j c n+m n, m, j 0}. Let i = j + n + m to get: { n m c i 0 n + m i}. 9. S AAS λ or S AS λ A λ A 10. S LR L L λ R L λ 11. The grmmr of this lnguge is S SSS SSS 12. An cn e specificlly plced in the middle position of string using the rules A A A A A The termintion of the ppliction of recursive A rules y the rule A inserts the symol into the middle of the string. Using this strtegy, the grmmr S A A B B A A A A A B B B B B genertes ll strings over f; g with the sme symol in the eginning nd middle positions. If the derivtion egins with n S rule tht egins with n, the A rules ensure tht n occurs in the middle of the string. Similrly, the S nd B rules comine to produce strings with in the first nd middle positions. 13. ) ( + )*( + )* ) S AA A A A λ 6 P g e

3 Context-Free Grmmr 14. ) * ) S A A A λ 15. S AA BA BA BA λa λb λλ S A A B B B λ B λ 16. S SSS XSS SS XS S X S S S S X X X 17. S U111 U 0U 1U λ 18. ) S SAB SABAB λabab λabab λbab λbab λλab λλab λλab λλb λλb 7 P g e

3 Context-Free Grmmr λλb λλλ ) S S A B S A B A B λ A B A B λ λ c) S S A B S A B A B S A B B A B λ λ λ λ d) (**)* 19. ) Anlysis: the lnguge will produce strings with exctly 3 s nd end with. in etween of the s cn hve s mny s s we like. The pttern of the string will e : BBB. S S A A A B B B ) Anlysis: the lnguge will produce strings with t lest one nd one. The pttern of the string will e : ABBA. S S A A A B B B λ 20. ) S A A A B 8 P g e

3 Context-Free Grmmr B A ) S A A A B A B A A. 21. L(G 1 ) = { m n m : n 0, m 0} 22. G1 = ({,, S}, {, }, S, P) with P defined y: S S λ 23. ) S A S S filed. ) S S A A S A S A A A S S A S S S A A A A A S S A S A 24. ) ( + )* ) ** or + + c) ** d) (* + *)* 25. S S A A A B B cb 26. The lnguge ( )*( )*( )* is generted y G 1 : S 1 S 1 S 1 A A B B B B C C D D D D 9 P g e

3 Context-Free Grmmr G 2 genertes the strings ( )*( )*( )* G 2 : S 2 S 2 S 2 E E F F F F G G H H H H A grmmr G tht genertes ( )*( )*( )* ( )*( )*( )* cn e otined from G 1 nd G 2. The rules of G consist of the rules of G1 nd G2 ugmented with S S 1 S 2 where S is the strt symol of the composite grmmr. The lterntive in these productions corresponds to the in the definition of the lnguge. While the grmmr descried ove genertes the desired lnguge, it is not regulr. The rules S S 1 S 2 do not hve the form required for rules of regulr grmmr. A regulr grmmr cn e otined y explicitly replcing S 1 nd S 2 in the S rules with the right-hnd sides of the S 1 nd S 2 rules. The S rules of the new grmmr re S S1 S1 A S S2 S2 E The strtegy used to modify the rules S S 1 S 2 is n instnce of more generl rule modifiction technique known s removing chin rules. 27. S S S A A B B B B C C D D D D 28. G 1 genertes the strings ( )*( )*( )* G 1 : S 1 S 1 S 1 A A B B B B C C D D D D G 2 genertes the strings ( )*( )*( )* G 2 : S 2 S 2 S 2 E E F F F F G G H H H H Thus grmmr G tht genertes ( )*( )*( )* ( )*( )*( )* S S1 S1 A S S2 S2 E S 1 S 1 S 1 A A B B B B C C D 10 P g e

3 Context-Free Grmmr D D D S 2 S 2 S 2 E E F F F F G G H H H H or G: S S S A E A B B B B C C D D D D E F F F F G G H H H H 29. S S A λ A A B B B S 30. The lnguge (( )( ))* is generted y the grmmr S A B A B B S B This lnguge consists of ll strings over {, } in which every is preceded or followed y. An generted y the rule S A is followed y. An generted y B S is preceded y. 31. When we strt nd we red then we re no closer to reding nd we remin in the sme stte. However, if we red n, we my encounter next, so we proceed to stte A, where we my not red next. If we red n in this stte A there still might follow B, so we remin in stte A. On the other hnd, when we red B in stte A, we end up in stte where we my not red n ecuse we hve just red. If the chrcter we red then is we re ck t the initil stte where the string to follow my not e. Of course, we re lwys llowed to stop reding nd ccept tht word in ny stte. This yields the following grmmr S S A A A B B S 32. G: S S A C A B B B D C S D B string to follow my not e string to follow my not e string to follow my not e 11 P g e

3 Context-Free Grmmr 33. G: S S A D G A B B B C C C D E E E F F F G G H H I I I 34. The vriles of the grmmr indicte whether n even or odd numer of 's hs een generted nd the progress towrd the next. The interprettion of the vriles is Vrile Prity Progress towrd S even none A even B odd none C odd The rules of the grmmr re S A S A A B B C B C C S A derivtion my terminte with -rule when B or C is present in the sententil form since this indictes tht n odd numer of 's hve een generted. 35. The ojective is to construct grmmr tht genertes the set of strings over {, } contining n even numer of 's or n odd numer of 's. In the grmmr, S O E O E E O E O E O O O E E E O the E nd O rules generte strings with n even numer of 's. The derivtion of string with positive even numer of 's is initited y the ppliction of n S rule tht genertes either E or O. The derivtion then lterntes etween occurrences of E nd O until it is terminted with n ppliction of the rule E. In like mnner, the O nd E rules generte strings with n odd numer of 's. The string cn e generted y two derivtions; one eginning with the ppliction of the rule S O nd the other eginning with S E. 36. ) { n m n n 0, m > 0} or we cn write { m n n > m 0}. ) { n 2m d 2m 2n n 0, m > 0} c) { n m n n, m 0} 12 P g e

3 Context-Free Grmmr 37. ) ( + + ) + ) The rules S S nd S S llow the genertion of leding 's or triling 's in ny order. Two leftmost derivtions for the string re S S S S S S c) The derivtion trees corresponding to the derivtions of () re S S S S S S 38. The regulr expression for this lnguge is + +. 39. { m n n m > 0, n 0} or we cn write { m n m > n 0}. 40. 41. ) The lnguge {, }* ) The set {, }*{} c) The set {}*{} d) The set {**} e) {}*{}{}*{}{}*, the set of strings in *{, } contining exctly two s f) The set of strings over {, } tht re not plindromes ut could e mde into plindromes y chnging one to or vice vers g) The set of even-length strings in {, }* h) The set of odd-length strings in {, }* ) S S S ) S S S c) S S d) S S S e) S S S S f) S A A; A A A A 13 P g e

3 Context-Free Grmmr 42. Tle 1. Tle 2. No. Lnguge No. Grmmrs CFG or RG 1. ( + )* 6 S A A A B B B λ RG 2. ( + ) + 5 S A A A λ 3. ( + ) 2 S S S RG 4. () 10 5. * 4 6. ** 9 7. ** 8 S AA A A A λ S A A S S S A A B B B B λ S A A A A 8. ( + )* 1 S S S λ RG 9. ( + )*( + )* 7 S S A A B B B λ 10. ( + )*( + )* 3 S RG RG CFG RG RG RG RG 43. Tle 3. Tle 4. No. Lnguge No. Grmmrs CFG or RG Generte 3 possile strings 1. L = {ww R : w ( + )*} 4 S S S SS CFG,, 2. L = { n 2m c n n, m > 0} 3 3. L = (* + *)* 5 4. Let L e the lnguge of ll strings over {, } tht hve the sme numer of s s s S A B λ A A S B B S S X Y X X Y Y S ASC B A C c B B 5. L = { n n n > 0} { n n n > 0} 1 S S S CFG 2 RG CFG CFG 14 P g e

4 Finite Automt Chpter 4 Finite Automt Answer for Exercises (Pge 151, Theory of Computer Science: Definitions nd Exmples. 3 rd Ed.) Prt A Multiple Choices Questions 1. B 2. B 3. C 4. A 5. B 6. D 7. D 8. B 9. A 10. A 11. D 12. D 13. B 14. B 15. B 16. B 17. D 18. B 19. C 20. C 21. C 22. A 23. D 24. C 162 P g e

4 Finite Automt Prt B Structured Questions 1. Wht is the mening of error or trp stte? Non-ccepting stte 2. Wht re the chrcteristics of NFA compred to DFA? Fetures DFA NFA Choice of trnsition Single Multiple Input lel Alphets only Alphets or or Undefined trnsitions No Possile 3. ) S, O, DFA ) [, ] [, ] [, ] [, ] [, λ] Stop t (finl stte) nd ll lphet is trced (string is empty); Hence, string is ccepted y the mchine. [, ] [, ] [, ] [, λ] All lphet is trced (string is empty) ut stop t (not finl stte) ; Hence, string is not ccepted y the mchine. [, ] [, ] [, ] [, λ] All lphet is trced (string is empty) ut stop t (not finl stte) ; Hence, string is not ccepted y the mchine. [, ] [, ] [, ] [, ] [, λ] Stop t (finl stte) nd ll lphet is trced (string is empty); Hence, string is ccepted y the mchine. [, ] [, ] [, ] 163 P g e

4 Finite Automt [, ] [, λ] Stop t (finl stte) nd ll lphet is trced (string is empty); Hence, string is ccepted y the mchine. c),, nd re ccepted., re not ccepted. d) ((+) (+))* 4. ) Yes, DFA. ) [, ] [, ] [, ] [, ] [, λ] Stop t (finl stte) nd ll lphet is trced (string is empty); Hence, string is ccepted y the mchine. [, ] [, ] [, ] [, ] [, ] [, ] [, λ] All lphet is trced (string is empty) ut stop t (not finl stte) ; Hence, string is not ccepted y the mchine. [, ] [, ] [, ] [, ] [, ] [, ] [, λ] Stop t (finl stte) nd ll lphet is trced (string is empty); Hence, string is ccepted y the mchine. [, ] [, ] [, ] [, ] [, ] [, λ] Stop t (finl stte) nd ll lphet is trced (string is empty); Hence, string is ccepted y the mchine. 164 P g e

4 Finite Automt c),, nd re ccepted nd is not ccepted. d) ***(***)* nd (***)**** or * + + (* + + )* nd (* + + )** + +, since * = + 5. ) DFA ) [, ] [, ] [, ] [, ] [, ] [, ] [, λ] All lphet is trced (string is empty) ut stop t (not finl stte) ; Hence, string is not ccepted y the mchine. c) ( + + (*()* (**()* )*)*)* 6. ) DFA ) [, ] [, ] [, ] [, ] [, ] [, ] [, λ] Stop t (finl stte) nd ll lphet is trced (string is empty); Hence, string is ccepted y the mchine. c) ** ((*) + (**))* 7. ) q 3 q 3 q 3 165 P g e

4 Finite Automt q 3 DFA The lnguge consisting of ll strings over {, } with n even numer of s nd n even numer of s. ) [, ] [, ] [q 3, λ] All lphet is trced (string is empty) ut stop t q 3 (not finl stte) ; Hence, string is not ccepted y the mchine. [, ] [, ] [, λ] Stop t (finl stte) nd ll lphet is trced (string is empty); Hence, string is ccepted y the mchine. [, ] [, ] [, ] [, λ] All lphet is trced (string is empty) ut stop t (not finl stte) ; Hence, string is not ccepted y the mchine. [, ] [, ] [q 3, ] [, ] [, λ] Stop t (finl stte) nd ll lphet is trced (string is empty); Hence, string is ccepted y the mchine. c) Only nd. d) (()* + ()*)* 8. ) q0 q1 q2 q3 No, NFA. ) [, ] [q 3, ] [q 3, ] [q 3, ] [q 3, λ] Stop t q 3 (finl stte) nd ll lphet is trced (string is empty); Hence, string is ccepted y the mchine. 166 P g e

4 Finite Automt [, ] [, ] [, ] [, λ] Stop t (finl stte) nd ll lphet is trced (string is empty); Hence, string is ccepted y the mchine. [, ] [, ] [, ] [, λ] Stop t (finl stte) nd ll lphet is trced (string is empty); Hence, string is ccepted y the mchine. [, ] [, ] [, ] [, ] [, λ] All lphet is trced (string is empty) ut stop t (not finl stte) ; Hence, string is not ccepted y the mchine. [, ] [, ] [, ] [, ] [, ] [, λ] Stop t (finl stte) nd ll lphet is trced (string is empty); Hence, string is ccepted y the mchine. c) Only,, nd re ccepted. d) * + ( + )* 9. ) - ),, re ccepted y M c) ** 10. ) 1*01*01* 1 1 1 0 0 ) (0 + 1)*0(0 + 1)*0(0 + 1)* 167 P g e

4 Finite Automt 0, 1 0, 1 0, 1 0 0 c) (0 + 1)*00(0 + 1)* 0, 1 0, 1 0 0 d) ( + )*, q 3 e) ( + )*, q 3 f) ( + )*( + )*,, q 3 11. ) ) Only nd re ccepted y M c) ** (* + **)* 12. ) ***, ) ( + )*( + )*( + )*,, q 3, c) ( + )*( + ) 168 P g e

4 Finite Automt, d) The lnguge of ll strings tht egin or end with or. ( + )( + )* + ( + )* ( + ) e) ( + )*( + ) f) (* + )* g) q 3 h) ( + ) * ( + ) * q 3 q 4 i) ( + )* j) ( + )*( + )*( + )* + ( + )*( + )*( + )* 169 P g e

4 Finite Automt,, q 3 q 4, q 5 q 6, q 7 q 8 q 9 k) ( + )*( + )*( + )* + ( + )*( + )*( + )*,, q 6 q 7 q 3, q 8 q 4 q 9 q 5 0 1, 13. For ech of the following lnguges, drw n FA ccepting it. ) ( + )* ) ( + )* c) ( + )*( + ) ( + )* d) ( + )* e) + * + * f) ( + )*( + ) g) ( + )* h) ( + )*()* 14. ) **c* The DFA,, c q 3 c, c c tht ccepts **c* uses the loops in sttes q0, q1, nd q2 to red 's, 's, nd c's. Any devition from the prescried order cuses the computtion to enter q3 nd reject the string. ) The set of strings over {, } in which the sustring occurs t lest twice. ( + )*( + )*( + )* c) The set of strings over {, } tht do not egin with the sustring. ( + + )( + )* d) ( )*( ) 170 P g e

4 Finite Automt A DFA tht ccepts the strings over {, } tht do not contin the sustring is given y the stte digrm, q 3 The sttes re used to count the numer of consecutive 's tht hve een processed. When three consecutive 's re encountered, the DFA enters stte q3, processes the reminder of the input, nd rejects the string. e) The set of strings over {,, c} tht egin with, contin exctly two 's, nd end with cc. ( + c)*( + c)*( + c)*cc f) The set of strings over {,, c} in which every is immeditely followed y t lest one c. ( + c + c)* g) The set of strings over {, } in which the numer of s is divisile y three. h) The set of strings over {, } in which every is either immeditely preceded or immeditely followed y, for exmple,,, nd. ( + + + )* i) The set of strings of odd length over {, } tht contin the sustring. j) The set of strings over {, } tht hve odd length or end with. k) ccepts strings of even length over {,, c} tht contin exctly one. A string ccepted y this mchine must hve exctly one nd the totl numer of 's nd c's must e odd. Sttes q1 or q3 re entered upon processing single. The stte q3 represents the comintion of the two conditions required for cceptnce. Upon reding second, the computtion enters the nonccepting stte q4 nd rejects the string. l) The set of strings over {, } tht hve n odd numer of occurrences of the sustring. Note tht hs two occurrences of. m) The set of strings over {, } tht contin n even numer of sustrings. n) The set of strings over {1, 2, 3} the sum of whose elements is divisile y six. o) The set of strings over {,, c} in which the numer of s plus the numer of 's plus twice the numer of c's is divisile y six. p) The sttes of the mchine re used to count the numer of symols processed since n hs een red or since the eginning of the string, whichever is smller. 171 P g e

4 Finite Automt A computtion is in stte qi if the previous i elements re not 's. If n input string hs sustring of length four without n, the computtion enters q4 nd rejects the string. All other strings ccepted. q) The DFA to ccept this lnguge differs from the mchine in Exercise 20 y requiring every fourth symol to e n. The first my occur t position 1, 2, 3, or 4. After reding the first, the computtion enters stte q4 nd checks for pttern consisting of comintion of three 's or c's followed y n. If the string vries from this pttern, the computtion enters stte q8 nd rejects the input. Strings of length 3 or less re ccepted, since the condition is vcuously stisfied. 15. ) q 3 ) q 3 c) d),, q 3 q 4 q 5 172 P g e

4 Finite Automt q 4 q 3 e) 16. 17. ) IN the lnguge c,, c,, cc, c,,, cc, c, c, cc, ccc, c {, } Ø Ø {, } {, } Ø NOT IN the lnguge,, c, c, c, c ) [, ] [, ] [, ] [, ] No such input, string rejected [, ] [, ] [, ] [, ] [, ] [, λ] Not finl stte, string rejected [, ] [, ] [, ] [, ] [, ] [, λ] String Accepted [, ] [, ] [, ] [, ] [, ] No such input, string rejected 173 P g e

4 Finite Automt [, ] [, ] [, ] No such input, string rejected [, ] [, ] No such input, string rejected c) Yes d) **(* + **)* or ( + + ) +. A regulr expressions for L(M) is + + ( + + + + )*. Processing + + leves the computtion in stte q2. After rriving t q2 there re two wys to leve nd return, tking the cycle q0, q1, q2 or the cycle q1, q2. The first pth processes string from + + nd the second +. This expression cn e reduced to ( + + ) +. 18. ) ) {, } Ø Ø {, } Ø {, } [, ] [, ] [, ] String Rejected [, ] [, ] [, ] [, ] [, λ] String Accepted [, ] [, ] [, ] [, ] [, λ] String Accepted [, ] [, ] [, ] [, ] String Rejected etc..! c) Yes e) *(* + *)* stop t *( + + *)* stop t Regulr exp is: *(* + *)* + *( + + *)* or + ( + + + )* + + ( + + + )* since * = + nd * = + 174 P g e

4 Finite Automt {,} {,} {,, }, 0 {,} 19. ) ( )* ) q 3 c) The NFA q 3 c ccepts the lnguge (c)**. Strings of the form (c)* re ccepted in q0. Stte q3 ccepts (c)* +. q 4 q 3 c d) 175 P g e

4 Finite Automt,, q 3 q 4 e) q 3 20. ) The set of strings over {, } tht contin either nd s sustrings. ( + )*( + )*( + )* + ( + )*( + )*( + )* ) The set of strings over {, } tht contin oth or neither nd s sustrings. c) The set of strings over {, } whose third-to-the-ist symol is. ( + )*( + )( + ) The set of strings over f; g whose third to the lst symol is is ccepted y the NFA When is red in stte q0, nondeterminism is used to choose whether to enter stte q1 or remin in stte q0. If q1 is entered upon processing the third to the lst symol, the computtion ccepts the input. A computtion tht enters q1 in ny other mnner termintes unsuccessfully. d) The set of strings over {, } whose third nd third-to-ist symols re oth. For exmple,,, nd re in the lnguge. ( + )( + )( + )*( + )( + ) + ( + )( + )( + )( + ) + ( + )( + ) + ( + ) e) The set of strings over {, } in which every is followed y or. ( + + ) f) The set of strings over {, } tht hve sustring of length four tht egins nd ends with the sme symol. ( + )( + ) + ( + )( + ) g) The set of strings over {, } tht contin sustrings nd. ( + )*( + )*( + )* + ( + )*( + )*( + )* h) The set of strings over {,, c} tht hve sustring of length three contining ech of the symols exctly once. c + c + c + c + c + c 21. Construct the stte digrm of DFA tht ccepts the strings over {, } ending with the 176 P g e

4 Finite Automt sustring. Give the stte digrm of n NFA with six rcs tht ccepts the sme lnguge. ( + )* 22. ) S A S A A ) S A B A A B B S, c) S A A B B A d) q 3 q 3 q 3 e) 23. ), S O, 177 P g e

4 Finite Automt 24. ) ) (( + )( + ))* S B A C ),,,,,. 25. ) RE = ( + c + c)*,c c only finl, remove finl in ) q 3, 26. ) C D S A B ) ()*()* 27. Design finite utomton to ccept the lnguge defined y the regulr expression ) ()*()* ) (+) + c) (() + )* 178 P g e

4 Finite Automt d) * + ()* e) *(*)* + λ 28.,,, q 3 q 4 q 5,, q 3 ), q 3 q 4 q 5 29. 0,1 0 1 1 0,1 q 3 0 q 7 1 0 0 q 4 q 5 q 6 1 30. (( + ) ( + )) ( + )* (( + ) ( + )) 31. 32. Tle 1. Tle 2. DFA or NFA No. Mtching No. no. of RE (0) DFA Z 1. 3 2. 8 (i) DFA j 3. 7 (ii) NFA 4. 6 (iii) NFA 5. 1 (iv) DFA g 6. 2 (v) DFA i 7. 5 (vi) DFA h 8. 9 (vii) DFA e 9. 10 (viii) DFA f 10. 4 179 P g e

4 Finite Automt (ix) DFA c (x) DFA d 180 P g e

Answer for Exercises of Chpter 5 (Questions t Pge 190, Introduction to Theory of Computer Science: Definitions nd Exmples) Prt A Multiple Choices Questions 1. C 2. D 3. D 4. C 5. B Prt B 1. Structured Questions ) The stte digrm of M is, e/a e, A/e e, A/e, A/e e, e/e, A/e ) (,, ) (,, A) (,, AA) (,, A) (,, ) ccept (,, ) (,, A) (,, ) reject (,, ) (,, A) (,, ) reject c) To show tht the strings nd re in L(M), we trce computtion of M tht ccepts these strings. Stte String Stck A AA A Stte String Stck A AA AAA AA A Both of these computtions terminte in the ccepting stte q2 with n empty stck.

d) The PDA M ccepts the lnguge { i j 0 j i}. Processing n pushes A onto the stck. Strings of the form i re ccepted in stte. The trnsitions in empty the stck fter the input hs een red. A computtion with input i j enters stte upon processing the first. To red the entire input string, the stck must contin t lest j A s. The trnsition (,, A) = [, ] will pop ny A s remining on the stck. The computtion for n input string tht hs fewer s thn s or in which n occurs fter hlts in stte without processing the entire string. Thus strings with either of these forms re rejected. 2. ) δ(,, λ) = {[, A]} δ(,, λ) = {[, B]} δ(, λ, λ) = {[, λ]} δ(,, A) = {[, λ]} δ(,, B) = {[, λ]} ) {ww R w {, }*}. c) The computtions of in M re s follows: Stte String Stck q0 λ q1 λ Stte String Stck q0 λ q0 A q1 A Stte String Stck q0 λ q0 A q0 λ BA q1 λ BA The computtions of in M re s follows: Stte String Stck q0 λ q1 λ Stte String Stck q0 λ q0 A q1 A Stte String Stck q0 λ q0 A q0 BA q1 BA q1 λ A Stte String Stck

q0 λ q0 A q0 BA q0 λ BBA q1 λ BBA The computtions of in M re s follows: Stte String Stck q0 λ q1 λ Stte String Stck q0 λ q0 A q1 A Stte String Stck q0 λ q0 A q0 BA q1 BA q1 A Stte String Stck q0 λ q0 A q0 BA q0 BBA q1 BBA q1 λ BA Stte String Stck q0 λ q0 A q0 BA q0 BBA q0 λ BBBA q1 λ BBBA d) Stte String Stck q0 λ q0 A q0 AA q1 AA q1 A q1 λ λ Stte String Stck q0 λ q0 B q0 AB q1 AB q1 B

q1 λ λ e) To show tht the string nd re not in L(M), we trce ll computtions of these strings in M, nd check whether none of them ccepts these strings. We hve listed ll the computtions of in (), nd none of them ccepts it. Now we trce ll computtions of in M. Stte String Stck q0 λ q1 λ Stte String Stck q0 λ q0 A q1 A q1 λ Stte String Stck q0 λ q0 A q0 AA q1 AA q1 λ A Stte String Stck q0 λ q0 A q0 AA q0 λ AAA q1 λ AAA Since none of the computtions ove is ccepted, we hve is not in M. 3. (, ) (, ) (, A ) (, A ) (, ) q 4 q 3 ) or ) (,e X) (,e Y) (c,y/e) (d,x e) (, ) c) d) (,e X) (,e Y) (c,y/e) (d,x e) (,e Y) (c,y/e) (d,x e)

(,e X) (,X e) (c,e Y) (d,y/e) e) f) (,e X) (,X e) (c,e Y) (d,y/e) (,X e) (c,e Y) (d,y/e) (,e X) (,e X) (c,x/e) (d,x e) (,e X) (c,x/e) (d,x e) g) (e,e e) (, e) (e,$/e) (c,e e) (e,e $) (,e ) (e,e e) (,e e) (c, e) (e,e e) (e,$/e), e/a, A/e e, $/e ( /A) ( B/ ) ( AA/ ) ( /BB) ( A/B) e, e/$, e/a, e/b, $/$ e, e/b q 4 e, A/e e, e/a, $/$ e, e/b q 3 q 5 e, $/e q 8 h) ( /A) ( A/ ) ( /B) ( B/ ) or q 6, e/b q 7, B/e i) j) e, e X (, e X, X e (, e X, X e, e e k) e, e X, X e or e, e e (,e ) (c,e e) (, e) (e,e e) (e,e e)

l) (,e/a) (,A/e) (,e/ ) (c /e) (, e ) (,A/e) (,e/ ) q 3 (c /e) q 4 or (,e/a) (,A/e) (,e/b) (c B/e) (e,e/e) (e,e/e) q 4 m), A, A (, ) (, ) q 3 (, ), q 4, n) (e,e/e) (,e/) (e,e/e) (,/e) (e,e/e) q 3 (c,e/e) (e,e/e) (,e/e) (e,e/e) (,e/) (e,e/e) q 4 (c,/e) o) (,e A) (,A e) (,e e) (e,e e) (,e e) (e, A e) q 3 (e, A e) p) (,e ) (, A e) (,e ) e, e/e e, e/a (, A e) q 3 q)

(,e/a) (,A/e) (c, /e) (e,e e) (e,e e) r) /A /B / / / A/ B/ 4. (,e/a) (,e/b) (c,e/c) (,A/e) (,B/e) (c,c/e) (d,e/e) 5. Give the stte digrm of PDA M tht ccepts { 2i i+j 0 j i} with cceptnce y empty stck. Explin the role of the stck symols in the computtion of M. Trce the computtions of M with input nd. 6. The mchine M, A, A, A ccepts the lnguge L = { i i i 0} y finl stte nd empty stck. ) Give the stte digrm of PDA tht ccepts L y empty stck. ) Give the stte digrm of PDA tht ccepts L y finl stte. 7. ) (,e/a) (,A/e) (,e/e) (,e/e) (e,e/b) (, B/e) ) (,e/a) (,A/e) (,e/e) (,e/e) (e,e/b) (, B/e) 8. Let L = { 2i i i 0}. ) Construct PDA M 1 with L(M 1 ) = L. ) Construct n tomic PDA M 1 with L(M 2 ) = L.

c) Construct n extended PDA M 3 with L(M 3 ) = L tht hs fewer trnsitions thn M 1. d) Trce the computtion tht ccepts the string in ech of the utomt constructed in (), (), nd (c). 9. Let L = { 2i 3i i 0}. ) Construct PDA M 1 with L(M 1 ) = L. ) Construct n tomic PDA M 2 with L(M 2 ) = L. c) Construct n extended PDA M 3 with L(M 3 ) = L tht hs fewer trnsitions thn M 1. d) Trce the computtion tht ccepts the string in ech of the utomt constructed in (), (), nd (c). 10. ) This lnguge ccepts the strings which strt with nd followed y. The numer of s is doule thn s. ) (,e ) (,A e) (,e e) c) L = { n 2n n > 0} d) S S A A (,A e) e) (,, ) (,, A) (,, AA) (,, A) (,, A) (,, ) (,, ) ccept f) S S S A 11. ) (, c, ) (, c, A) (, c, AA) (,, AA) (,, A) (,, ) ccept ) S S S ca A A A c) S S S ca ca ca c c 12. ) ) (0,e,X) (1,X,e) (1,X,e) (0,e,X) (1,X,e) (1,X,e) 13. ) (,, ) (,, A) (,, AA) (,, AAA) (,, AA) (,, A) (,, ) ccept ) (,, ) (,, A) (,, A) (,, ) reject

14. ) ) (,e X) (,X/e) (c,x/e) (e,x e) (e,e e) (e,e e) (e,x e) (e,e X) (,e X) (,X/e) (c,x e) (e,e X) (e,e e) (e,e e) q 3 q 3 15. ) CFG : S XC AY X X ε C cc ε A A ε Y Yc ε ) (e,e/e) (,e/) (,/e) (e,e/e) q1 q3 (c,e/e) q0 (,e/e) (e,e/e) q2 (e,e/e) q4 (,e/) (c,/e) 16. OR On seeing ( push it on the stck On seeing ) pop ( from the stck If ttempt to pop n empty stck, reject If stck not empty t the end, reject Else ccept First push ottom-of-the-stck sysmol $ nd move to On seeing ( push it onto the stck On seeing ) pop if ( is in the stck Pop $ nd move to finl stte q f, e/( e, e/$ q e, $/e q f ), (/e

5 Push-down Automt 17. ) S ABA BB δ(q0,, λ)= {[q0, ABA]¹, [q1, BB]²} A A δ(q1,, A)= {[q1, A]³, [q1, λ] 4 } B cb c δ(q1, c, B)= {[q1, B] 5, [q1, λ] 6 } ) Drw the PDA mchine M tht ccept L(G). M: Q = {, } = {,, c} = {A, B} F = { } δ(q0,, λ) = {[q0, ABA] } δ(q0,, λ) = { [q1, BB] } δ(q1,, A) = {[q1, A] } δ(q1,, A) = {[q1, λ] } δ(q1, c, B) = {[q1, B] } δ(q1, c, B) = {[q1, λ]} 18. (i) (ii) (iii) (iv) (v) (vi) (vii) (viii) (ix) (x) (xi) c i k j e g h f d 164 P g e