HM2-Chapters2-4-Answers

HM2-Chapters2-4-Answers - CS 341 Homework 2 Answers Chapter...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 341 Homework 2 Answers Chapter 2 1) Consider the language L = { 1 n 2 n : n > 0}. Is the string 122 in L ? No. Every string in L must have the same number of 1 ’s as 2 ’s. 2) Let L 1 = { a n b n : n > 0}. Let L 2 = { c n : n > 0}. For each of the following strings, state whether or not it is an element of L 1 L 2 : a) ε . No. b) aabbcc . Yes. c) abbcc . No. d) aabbcccc . Yes. 3) Let L 1 = { peach , apple , cherry } and L 2 = { pie , cobbler , ε }. List the elements of L 1 L 2 in lexicographic order. apple , peach , cherry , applepie , peachpie , cherrypie , applecobbler , peachcobbler , cherrycobbler (We list the items shortest first. Within a given length, we list the items alphabetically.) 4) Let L = { w { a , b }* : | w | 3 0}. List the first six elements in a lexicographic enumeration of L . ε , aaa , aab , aba , abb , baa 5) Consider the language L of all strings drawn from the alphabet { a , b } with at least two different substrings of length 2. a) Describe L by writing a sentence of the form L = { w Σ * : P ( w )}, where Σ is a set of symbols and P is a first-order logic formula. You may use the function | s | to return the length of s . You may use all the standard relational symbols (e.g., =, , <, etc.), plus the predicate Substr ( s , t ), which is True iff s is a substring of t . L = { w { a , b }* : 5 x , y ( x y | x | = 2 | y | = 2 Substr ( x , w ) Substr ( y , w ))}. b) List the first six elements of a lexicographic enumeration of L . aab , aba , abb , baa , bab , bba 6) For each of the following languages L , give a simple English description of L . Show two strings that are in L and two that are not (unless there are fewer than two strings in L or two not in L , in which case show as many as possible). a) L = { w { a , b }* : exactly one prefix of w ends in a }. L is the set of strings composed of zero or more b ’s and a single a . a , bba and bbab are in L . bbb and aaa are not. b) L = { w { a , b }* : all prefixes of w end in a }.
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
L = , since ε is a prefix of every string and it doesn’t end in a . So all strings are not in L , including a and aa .
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern