hw4sol - CS 181 Winter 2005 Formal Languages and Automata...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 181 — Winter 2005 Formal Languages and Automata Theory Problem Set #4 Solutions Problem 4.1. (10 points) 1. Show that if all productions of a CFG G are of the form A wB or A w for variables A, B V and strings of terminals w Σ * , then L ( G ) is regular. Solution Given a context-free grammar G = ( V, Σ , R, S ) where each production R has either form A wB or A w , we will construct a GNFA for L ( G ). Here is the intuition: Our GNFA will have a state for each variable in V an initial state q 0 and a final state q f . Our initial state q 0 has a transition into S on ε . For each production of the form A wB we have a transition from the state A to the state B over regular expression w . For each production of the form A w we have a transition from the state A to the state q f over w . Formally, our GNFA is defined as M = ( V ∪ { q 0 , q f } , Σ , δ, q 0 , { q f } ) where the transition function is δ ( q, p ) = ε, if q = q 0 and p = S w :( q w ) R w, if q V and p = q f w :( q wp ) R w, if q, p V , otherwise Notice that to handle cases where our grammar has productions A w 1 B and A w 2 B , we have a transition from A to B over w 1 w 2 . Let us now show that in fact L ( M ) = L ( G ). Suppose w L ( G ) then there is some derivation S = w 1 V 1 = w 1 w 2 V 2 = ⇒ · · · = w 1 w 2 · · · w k - 1 V k - 1 = w 1 w 2 · · · w k = w Then clearly the run of M on w with state sequence q 0 ε -→ S w 1 -→ V 1 w 2 -→ V 2 w 3 -→ . . .
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '08
  • griebach
  • Formal language, Formal languages, Regular expression, Context-free grammar, context-free language, R R R R

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern