110 likes | 174 Views
CS 461 – Sept. 2. Review NFA DFA Combining FAs to create new languages union, intersection, concatenation, star We can basically understand how these work by drawing a picture. Section 1.3 – Regular expressions
E N D
CS 461 – Sept. 2 • Review NFA DFA • Combining FAs to create new languages • union, intersection, concatenation, star • We can basically understand how these work by drawing a picture. • Section 1.3 – Regular expressions • A compact way to define a regular set, rather than drawing an FA or writing transition table.
Example #2 • NFA transition table given to the right. • DFA start state is A. • DFA accept state would be anything containing D.
continued Let’s begin. δ(A, 0) = A δ(A, 1) = AC We need new state AC. δ(AC, 0) = A δ(AC, 1) = ABC Continue from ABC…
NFA DFA answer
Moral • NFAs and DFAs have same computational power. • NFAs often have fewer states than corresponding DFA. • Typically, we want to design a DFA, but NFAs are good for combining 2+ DFAs. • After doing NFA DFA construction, we may see that some states can be combined. • Later in chapter, we’ll see how to simplify FAs.
U and ∩ • Suppose M1 and M2 are DFAs. We want to combine their languages. • Union: We create new start state. √ • Do you understand formalism p. 60 ? • How can we also do intersection? Hint: A ∩ B = (A’ U B’)’
Concatenation • Concat: For each happy state in M1, turn it into a reject state and add ε-trans to M2’s start. • Example L1 = { does not contain 00 } L2 = { has even # of 1’s } Let’s draw NFA for L1L2. • Let’s decipher formal definition of δ on p. 61.
Star • We want to concat the language with itself 0+ times. • Create new start state, and make it happy. • Add ε-transitions from other happy states to the start state. • Example L = { begins with 1 and ends with 0 } Let’s draw NFA for L*. • Formal definition of δon p. 63.
Regular expression • A concise way to describe a language • Text representation, straightforward to input into computer programs. • Use alphabet symbols along with operators + means “or” * means repetition Concatenation • There is no “and” or complement.
Examples • What do you think these regular expressions mean? 0* + 1* 0*1* 00*11* (a shorthand would be 0+1+) (0 + 1)* • What’s the difference between 10*1 and 1(0+1)*1 ? Does this mean “anything with 1 at beginning and end?”
Practice • Words with 2 or more 0’s. What’s wrong with this answer: 1*01*01 ? • Words containing substring 110. • Every even numbered symbol is 0. • What’s wrong with: ((0 + 1)*0)* ? • Words of even length. • The last 2 symbols are the same. • What is the shortest word not in: 1*(01)*0* ? • True or false: (111*) = (11 + 111)*