This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Problem Set 2 Solutions CS373  Spring 2011 Due: Thursday Feb 24 at 2:00 PM in class (151 Everitt Lab) Please follow the homework format guidelines posted on the class web page: http://www.cs.uiuc.edu/class/sp11/cs373/ 1. Is it regular? [ Category : Proof, Points : 12] Prove that each of the following languages is regular by building a nite automaton or regular expression, or prove nonregularity by using the pumping lemma. i) A = { w { , 1 } *   w  is even and the number of zeros in w 's rst half is even } (4 Points) [SOLUTION] Given pumping length p , let w = 1 p 01 p 1 . This string has an even number ( 2 p ) of characters, and an even number of 's (zero) in the rst half. Since  xy  p , y = 1 k for some 1 k p . If k is odd, then  xy 2 z  is odd, so xy 2 z 6 A . If k is even, then k 2 . Therefore,  xy z  2 n 2 . Since there are p 1 1 's after the zero in w , the in xy z will be in the rst half of the string. Since there is only one in xy z , and it is in the rst half of the string, xy z 6 A . ii) A = { xy  x,y { , 1 } * , the number of 0s in x is equal to the number of 1s in y } (4 Points) [SOLUTION] This language includes every string and has the regular expression (0 1) * . We will prove that all strings w = a 1 a 2 a 3 ...a n are in A . Let ( i ) be the number of zeros in all a k for k i minus the number of ones in all a j for j > i . Notice that if ( i ) = 0 for some i , then w is in A , since the `border' between x and y is between a i and a ( i + 1) . The number (0) , as there are no zeros to the left of position zero. The number ( n ) , as there are no ones to the right of position n . Note that if the i th character is a zero, then ( i ) = ( i 1) + 1 , as the number of zeros to the left of character i has increased by one, and the number of ones to the right is unchanged. Also, if the i th character is a one, then ( i ) = ( i 1) + 1 , as the number of zeros to the left of i has not changed, but the number of ones to the right of i has decreased by one. Since ( i ) can only change by one at each character, and (0) , and ( n ) , there must be an i such that ( i ) = 0 , so there is a way to decompose any string w into xy = w such that the number of zeros in x is equal to the number of ones in y . iii) A = { xy  x,y { , 1 } * , the number of 0s in x is equal to the number of 0s in y } (4 Points) [SOLUTION] This language is regular, and is equal to (1 * 01 * 01 * ) * . This is the regular expression that requires the number of zeros to be even. Any string w with an even number of zeros can be decomposed into xy = w such that the number of zeros in x is the same as the number of zeros in y . If w contains 2 n zeros, then split the string right after the n th zero....
View
Full
Document
This note was uploaded on 04/28/2011 for the course CS 373 taught by Professor Viswanathan,m during the Spring '08 term at University of Illinois, Urbana Champaign.
 Spring '08
 Viswanathan,M

Click to edit the document details