Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Let sigma_2 = {0, 1}, and define sigma E = sigma^3_2. Informally, sigma is the s

ID: 3855962 • Letter: L

Question

Let sigma_2 = {0, 1}, and define sigma E = sigma^3_2. Informally, sigma is the set of triples of the form (a, b, c) where a, b, c are single binary digits. Consider a string s elementof sigma*: it is a sequence of such triples. We want to "verify" binary addition of numbers in the first two coordinates by checking that it is equal to the third. Let A be the language of such triples such that the concatenation of the first coordinates, as a number, n of the second coordinates, as a number, sum to be equal to the third. For example, if w = (0, 1, 1) (1, 1, 1) (0, 0, 1) (1, 0, 1), this is encoding 0101_2 + 1100_2 = 1111_2, which is false: therefore, w notequalto A. Prove that A is regular

Explanation / Answer

public s t a t i c int [ ] buildKMPTable ( S t ri n g p a t t e r n ) { int [ ] t a b l e = new int [ p a t t e r n . l e n g t h ( ) + 1]; for ( int i = 2 ; i < t a b l e . l e n g t h ; ++i ) { int j = t a b l e [ i 1]; do { i f ( p a t t e r n . charAt ( j ) == p a t t e r n . charAt ( i 1) ) { t a b l e [ i ] = j +1; break ; } e l s e j = t a b l e [ j ] ; } while ( j != 0 ) ; } return t a b l e ; } 4. public s t a t i c int sim ul a t e ( int [ ] t a bl e , S t ri n g p a t te rn , S t ri n g t e x t ) { int s t a t e = 0 ; for ( int i = 0 ; i < p a t t e r n . l e n g t h ( ) ; ++i ) { while ( true ) { i f ( p a t t e r n . charAt ( i ) == t e x t . charAt ( s t a t e ) ) { s t a t e ++; 3 break ; } e l s e i f ( s t a t e == 0 ) break ; s t a t e = t a b l e [ s t a t e ] ; } } return s t a t e ; } 5. Look for the pattern P$ in the string T and determine how many times you arrive at the next-to-last state. 6. Using KMP you can find the suffixes of P that are also prefixes. Suppose P = vw and P = wx where v, w, x are strings. That is, w is both a suffix and a prefix of P. If |v| divides |P| then P = v |P|/