Вы находитесь на странице: 1из 15

Automata and Formal Languages

CS138, Winter 2006


Wim van Dam Room 5109, Engr. I vandam@cs.ucsb.edu http://www.cs.ucsb.edu/~vandam/
CS138, Wim van Dam, UCSB

Formalities
This Friday is the first midterm of the course, worth 10%, on Automata and Regular Languages [pp. 156] Do not forget to bring your Reader, books, notes, pen, paper and so on. No electronics are allowed. Level of difficulty is comparable with the homeworks.

CS138, Wim van Dam, UCSB

What You Should Know


Automata [Reader, pp. 120; Slides Week 1, Homework 1]: You should be comfortable with the basic set theory that is used to describe languages and their properties, induction on integers and general structural induction. You should know how to deal with: alphabets, words, languages, regular operations (union, concatenation, *). You should be able to reduce general computational problems into (a sequence of) decision problems.

CS138, Wim van Dam, UCSB

What You Should Know


Regular Languages [R, pp. 2156; Slides Wk 23, Hwk 2]: You should know the following topics: Deterministic Finite Automata, Nondeterministic FA, Generalized NFA, Regular Operations, Regular Expressions, Pumping Lemma. You should be able to do the following: describe the regular language recognized by a finite automaton, write down an automaton for a given regular language, translate formal descriptions to state diagrams of FAs and back, transform a NFA into an equivalent FA, interpreting regular expressions, transforming REs into FAs and back (using GNFA), using the pumping lemma to prove nonregularity.

CS138, Wim van Dam, UCSB

Recap Nonregular Languages


What languages can not be recognized by finite automata? How to prove that a language is nonregular?

The example L={ 0n1n | nN } can not be recognized by a FA because the machine needs an unbounded amount of memory to keep track of the value n: the finite number of states |Q| puts a limit on the computational power.

CS138, Wim van Dam, UCSB

Repeating DFA Paths


The action of the DFA in a state qj is always the same. If we repeat (or ignore) the qj,,qj loop on the input xyz, the new path of xyiz will again be an accepting path:

qj q1
z yi

qk
CS138, Wim van Dam, UCSB

Line of Reasoning
If we want to prove that a language L is nonregular, we can use the following proof by contradiction technique: Assume that L is regular. Hence, there is a DFA M that recognizes L. For strings of length |Q| the DFA M has to repeat itself. Show that M will accept strings outside L. Conclude that the assumption was wrong.

Note that we use the simple DFA, not the more elaborate (but equivalent) NFA or GNFA.
CS138, Wim van Dam, UCSB

Thm 1.70: Pumping Lemma


For every regular language L, there is a finite pumping length p, such that for any string sL and |s|p, we can write s=xyz with: 1) x yi z L for every i{0,1,2,} 2) |y| 1 3) |xy| p
Note that: (1) implies that xz L, (2) says that y can not be the empty string , (3) is not always used. This is a lemma about regular languages

CS138, Wim van Dam, UCSB

Formal Proof of Pumping Lemma


Let M = (Q,,,q1,F) with Q = {q1,,qp}. Let s = s1snL(M) with |s| = n p. The computational path of M on s is the sequence r1rn+1 Qn+1 with r1 = q1, rn+1F and rt+1= (rt,st) for 1tn. Because n+1 p+1, there have to be two states rj and rk such that rj = qi = rk (with 1 j < k p+1). Let x = s1sj1, y = sjsk1, and z = sksn+1. The string x takes M from q1=r1 to rj, the string y takes M from rj to rj, and the string z takes M from rj to rn+1F. As a result: xyiz takes M from q1 to rn+1F (for all i 0).

CS138, Wim van Dam, UCSB

Pumping Lemma Exercises


Exercise 1.2930 and 1:4649,5354 in the Reader. Show that the following languages are not regular A1 = {0n1n2n | n0 } A2 = { www | w{a,b}* } A3 = {a(2^n) | n0 } And some more: { 0n 1m 2n | n,mN} { 0m1n| nm, n,mN} { w{0,1}*| w is not a palindrome } { wtw | w,t{0,1}+ }

CS138, Wim van Dam, UCSB

Some Exercises
Let A = {x,y,z} and B = {x,y}, answer: 1. Is A a subset of B? 2. Is B a subset of A? 3. What is AB? 4. What is AB? 5. What is AB? 6. What is P(Q)?

CS138, Wim van Dam, UCSB

More Exercises
Give NFAs with the specified number of states that recognize the following languages over the alphabet ={0,1}: 1. { w | w ends with 00}, three states 2. {0}; two states 3. { w | w contains even number of 0s, or exactly two 1s}, six states 4.{0n | nN }, one state

CS138, Wim van Dam, UCSB

Even More Exercises


Proof the following result: If L1 and L2 are regular languages, then L1L2c is a regular language too.
Describe the language that is recognized by the following nondeterministic automaton:

0,1

1
q1 q2

0, q3

1
q4

CS138, Wim van Dam, UCSB

And More Exercises


Write the formal descriptions of the sets containing 1. the numbers 1,10 and 100 2. all integers greater than 5 3. all natural numbers less than 5 4. the string aba 1 5. the empty string 6. nothing q1 1 Give a formal description of this NFA:

0, q2 q3

Give DFA state diagrams for the following languages over ={0,1}: 1. { w | w begins with 1 and ends with 0} 2. { w | w does not contain substring 110} 3. {} 4. all strings except the empty string
CS138, Wim van Dam, UCSB

Next Wednesday

Q&A:
Bring Questions
CS138, Wim van Dam, UCSB

Вам также может понравиться