CS503

Solution of Exam #1

#1 - #4 Consider the following NFA
#1 (4 points) Why is it non-deterministic?
  1. More than 1 transition from the same state on the same input (e.g., 2 transitions from state 2 on an "a")
  2. -transition (e.g., from state 2 to 3)
  3. No transition for some input (e.g., no transition for "b" from state 3)
#2 (4 points) Convert the NFA to a DFA.

                    a             b  
    {1, 3}        {1, 3}         {2}
    {2}           {2, 3}         {3}
    {2, 3}        {1, 2, 3}      {3}
    {3}           {1, 3}         {0}
    {1, 2, 3}     {1, 2, 3}      {2, 3}
                                     


#3 (4 points) Using the algorithm to eliminate states, eliminate all but the initial & final states.

Using original:

#4 (3 points) Give the regular expression from #3.


((lambda U ba*(aUb))a)*


#5 - #10 Consider the following grammar, G

E->E+T|T
T->T*F|F
F->(E)|x

#5 (3 points) Specify V, , P, and S in G = (V, , P, S)



     V  =  {E, T, F}
       =  {+, *, (, ), x}
     P  =  above
     S  =  E


#6 (3 points) Eliminate any chain rules in G
    
     E->E+T|T*F|(E)|x
     T->T*F|(E)|x
     F->(E)|x


#7 (3 points) Eliminate any useless symbols in G

None


#8 (3 points) Convert G to Chomsky Normal Form


     (CNF has non-recursive start symbol)
     E'->E+T|T*F|(E)x
     E->E+T|T*F|(E)|x
     T->T*F|(E)|x
     F->(E)|x

     E'->E, T1|TT2|T3T4|x
     T1->T5T
     T5->+
     T2->T6F
     T6>->*
     T3->(
     T4->ET7
     T7->)
     etc.


#9 (3 points) Eliminate any direct left recursion in G

     E->TE'|T
     E'->+TE'|
     T->FT'|F
     T'->*FT'|
     F->(E)|x


#10 (5 points) Use the pumping lemma to show L(G) is not regular

If L(G) were regular, then there is a DFA with k states that accepts it
Pick Z = (kx)k. Then, by the PL, Z = uvw with L(uv)< = k. So uv is all "(".
Also, uvvw must be in L. But this means uvvw has more "(" than ")". Contradiction.

#11 (5 points) Show by induction that the length of a derivation in a Chomsky Normal Form Grammar for a string of lenght n is 2n-1 for n> = 1.

    
     Proof by induction on n.
Basis
     n = 1 so w =  or w = a  .
So, derivation is S-> or S->a which has length 1 = 2*1-1

I.H:
     Assume For a string of length k, L(deriv.) = 2k-1, 1<= k<= n

F.S: To show when L(w) = n+1, L(deriv.) = 2(n+1)-1. Since 
n >= 1, n+1 >= 2, so derivation must start with S = >AB.

     Then, L(deriv. w) = L(deriv. u)+L(deriv. v) + 1
                         = 2(L(u)-1) + 2(L(v)-1) + 1 (by IH)
			 = 2(L(u)+L(v)) -1
			 = 2L(w)-1
			 = 2(n+1)-1