Spring 2001
csc 417
Review for Final
WITH ANSWERS

Review Questions

  1. For the following graph, give the sequence of vertices visited by the following traversals.  If there is more than one choice at each step, visit the nodes in an alphabetically ascending order.

    1. Depth-first Traversal

      ANSWER: A B G I C D H E F

    2. Breadth-first Traversal

      ANSWER: A B C G D E I H F

  1. Multi-part question
    1. Design an NDFSA which accepts all strings over {a,b} which start with ab and end with baa. Note that the string "abaa" is such a string.

      ANSWER:

    2. Convert NDFSA in the previous problem to a DFSA.

      ANSWER:

    3. Construct a regular grammar from the NDFSA in problem a, and from the DFSA in problem b above.

      ANSWER:

      • Grammar G1 constructed from NDFSA (a). Non-terminal symbols correspond to the machine in a) as follows: 0 == S, 1 == A, 2 == B, 3 == C, 4 == D, 5 == E.
      S -> aA
      A -> bB | bC
      B -> aB | bB | bC
      C -> aD
      D -> aE
      E -> l
      • Grammar G2 constructed from DFSA (b):
      S -> aA | bF
      A -> aF | bC
      B -> aB | bC
      C -> aD | bC
      D -> aE | bC
      E -> aB | bC | l
      F -> aF | bF

      NOTE: Both grammars above generate the same language. The difference come in when the grammars are used in processing. Basically, the deterministic grammar (G2) allows exactly 1 transition for an input symbol for any state, whereas the nondeterministic one (G1) allows 0 or even multiple transitions. So, the processing (i.e., parsing) with deterministic grammar runs much faster.

  2. Construct FSA for the regular expression b+a(b*|c*). First construct an FSA with epsilon transitions, then construct an equivalent FSA without epsilon transitions. 

    ANSWER:

    The first part with epsilon transitions is easy, so it is omitted. The machine for the second part without epsilon transitions is one of the following.

  3. Given the following grammar:

    N = {a,b}
    T = {S,A,B}
    s = S 
    P = {S -> AB, S -> BA, A -> Aa, A -> a, B -> Bb, B -> b}

    1. What is the type of the grammar?

      ANSWER: Context-free  grammar

       

    2. Give a regular expression and a set notation to define L(G).

      ANSWER:  

      • Regular expression:  aa*bb* | bb*aa*  (or a+b+ | b+a+ using an extension +)

      • Set notation:  {anbm | n > 0, m > 0} U {bnam | n > 0, m > 0} 

  4. (Handout 3, Exercise #2) Let G be the grammar:

    S ® ASB | l
    A
    ® aAb | l
    B
    ®  bBa | ba

    1. Give a leftmost derivation of "aabbba".

      ANSWER: 
      S Þ ASB Þ aBbSB Þ aaAbbSB Þ aabbSB  Þ aabbB  Þ aabbba

       

    2. Give a rightmost derivation of "abaabbbabbaa".

      ANSWER: 
      S Þ ASB  Þ ASbBa Þ ASbbBaa  Þ ASbbaa Þ AASBbbaa Þ AASbabbaa Þ AAbabbaa  Þ AaAbbbaa  Þ AaaAbbbabbaa Þ Aaabbbabbaa Þ aAbaabbbabbaa  Þ abaabbbabbaa

       

    3. Build the derivation/parse tree for the derivations in parts (a) and (b).

      ANSWER: omitted here

       

    4. Use set notation to define L(G).

      ANSWER: {(anbn)i(bmam) | n >= 0, m > 0 and i >= 0}.

  5. (Handout 3, Exercise #6a) Use set notation to define the language generated by the following grammar:

    S ® aaSB | l
    B
    ® bB | b

    ANSWER:  {a2nbm | n >= 0, m >= n} or {a2nbm+n | n >= 0, m >= 0} 

     

  6. (Handout 3, Exercise #11) Construct a grammar over {a, b} whose language is s {ambian | i = m + n}. 

    ANSWER:

    S ® AB 
    A
    ® aAb | l
    B
    ®  bBa | l

NOTE:  This grammar is very similar to the one for Question #4.  Differences are: