🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

lecture-5.docx

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Transcript

University of Science and Technology Faculty of Computer Science and Information Technology Computer Science Department Semester 7 Theory of Computation Lecture (5) Instructor: Prof. Noureldien Abdelrahman Date 22-11-2022 **Equivalence of NFAS and DFAS** Deterministic and nondeterministic fi...

University of Science and Technology Faculty of Computer Science and Information Technology Computer Science Department Semester 7 Theory of Computation Lecture (5) Instructor: Prof. Noureldien Abdelrahman Date 22-11-2022 **Equivalence of NFAS and DFAS** Deterministic and nondeterministic finite automata recognize the same class of languages. Such equivalence is both **[surprising and useful]**. **[It is surprising]** because **[NFAs appear to have more power]** than DFAs, so we might expect that NFAs recognize more languages. **[It is useful because describing an NFA]** for a given language sometimes is much easier than describing a DFA for that language. **[We say that two machines are *equivalent* if they recognize the same language]** THEOREM **1.39** **Every nondeterministic finite automaton has an equivalent deterministic finite automaton**. Theorem 1.39 states that every NFA can be converted into an equivalent DFA. Thus nondeterministic finite automata give an alternative way of characterizing regular languages. We state this fact as a corollary of Theorem 1.39. COROLLARY **1.40** A language is regular if and only if some nondeterministic finite automaton recognizes it. **Steps for converting NFA to DFA** **Step 1:** Initially Q\' = ϕ **Step 2:** Add q0 of NFA to Q\'. Then find the transitions from this start state. **Step 3:** In Q\', find the possible set of states for each input symbol. If this set of states is not in Q\', then add it to Q\'. **Step 4:** In DFA, the final state will be all the states which contain F(final states of NFA) Example 1: Convert the given NFA to DFA. Conversion from NFA to DFA **Solution:** For the given transition diagram we will first construct the transition table. **State** **0** **1** ----------- ---------- ---------- →q0 q0 q1 q1 {q1, q2} q1 \*q2 q2 {q1, q2} Now we will obtain δ\' transition for state q0. 1. δ\'(\[q0\], 0) = \[q0\]   2. δ\'(\[q0\], 1) = \[q1\]   The δ\' transition for state q1 is obtained as: 1. δ\'(\[q1\], 0) = \[q1, q2\]       (**new** state generated)   2. δ\'(\[q1\], 1) = \[q1\]   The δ\' transition for state q2 is obtained as: 1. δ\'(\[q2\], 0) = \[q2\]   2. δ\'(\[q2\], 1) = \[q1, q2\]   Now we will obtain δ\' transition on \[q1, q2\]. δ\'(\[q1, q2\], 0) = δ(q1, 0) ∪ δ(q2, 0)                      = {q1, q2} ∪ {q2}                         = \[q1, q2\]   δ\'(\[q1, q2\], 1) = δ(q1, 1) ∪ δ(q2, 1)                         = {q1} ∪ {q1, q2}                         = {q1, q2}                    = \[q1, q2\]   The state \[q1, q2\] is the final state as well because it contains a final state q2. The transition table for the constructed DFA will be: **State** **0** **1** -------------- ------------ ------------ →\[q0\] \[q0\] \[q1\] \[q1\] \[q1, q2\] \[q1\] \*\[q2\] \[q2\] \[q1, q2\] \*\[q1, q2\] \[q1, q2\] \[q1, q2\] The Transition diagram will be: ![Conversion from NFA to DFA](media/image2.png) The state q2 can be eliminated because q2 is an unreachable state. Example 2: Convert the given NFA to DFA. Conversion from NFA to DFA **Solution:** For the given transition diagram we will first construct the transition table. **State** **0** **1** ----------- ---------- ---------- →q0 {q0, q1} {q1} \*q1 Φ {q0, q1} Now we will obtain δ\' transition for state q0. 1. δ\'(\[q0\], 0) = {q0, q1}   2.                = \[q0, q1\]       (**new** state generated)   3. δ\'(\[q0\], 1) = {q1} = \[q1\]   The δ\' transition for state q1 is obtained as: 1. δ\'(\[q1\], 0) = ϕ   2. δ\'(\[q1\], 1) = \[q0, q1\]   Now we will obtain δ\' transition on \[q0, q1\]. 1. δ\'(\[q0, q1\], 0) = δ(q0, 0) ∪ δ(q1, 0)   2.                       = {q0, q1} ∪ ϕ   3.                       = {q0, q1}   4.                       = \[q0, q1\]   Similarly, 1. δ\'(\[q0, q1\], 1) = δ(q0, 1) ∪ δ(q1, 1)   2.                       = {q1} ∪ {q0, q1}   3.                       = {q0, q1}   4.                       = \[q0, q1\]   As in the given NFA, q1 is a final state, then in DFA wherever, q1 exists that state becomes a final state. Hence in the DFA, final states are \[q1\] and \[q0, q1\]. Therefore set of final states F = {\[q1\], \[q0, q1\]}. The transition table for the constructed DFA will be: **State** **0** **1** -------------- ------------ ------------ →\[q0\] \[q0, q1\] \[q1\] \*\[q1\] Φ \[q0, q1\] \*\[q0, q1\] \[q0, q1\] \[q0, q1\] The Transition diagram will be: ![Conversion from NFA to DFA](media/image4.png) **Steps for converting NFA with ε to DFA** **Step 1:** We will take the ε-closure for the starting state of NFA as a starting state of DFA. **Step 2:** Find the states for each input symbol that can be traversed from the present state. That means the union of transition value and their closures for each state of NFA present in the current state of DFA. **Step 3:** If we found a new state, take it as current state and repeat step 2. **Step 4:** Repeat Step 2 and Step 3 until there is no new state present in the transition table of DFA. **Step 5:** Mark the states of DFA as a final state which contains the final state of NFA. **Example 1:** Convert the NFA with ε into its equivalent DFA. Conversion from NFA with Null to DFA **Solution:** **Let us obtain ε-closure of each state.** 1. ε-closure {q0} = {q0, q1, q2}   2. ε-closure {q1} = {q1}   3. ε-closure {q2} = {q2}   4. ε-closure {q3} = {q3}   5. ε-closure {q4} = {q4}   Now, let ε-closure {q0} = {q0, q1, q2} be state A. Hence The partial DFA will be ![Conversion from NFA with Null to DFA](media/image6.png) Now, For state C: 1. δ\'(C, 0) = ε-closure {δ(q4, 0) }   2.               = ϕ   3. δ\'(C, 1) = ε-closure {δ(q4, 1) }   4.               = ϕ   The DFA will be, Conversion from NFA with Null to DFA Example 2: Convert the given NFA into its equivalent DFA. ![Conversion from NFA with Null to DFA](media/image8.png) **Solution:** Let us obtain the ε-closure of each state. 1. ε-closure(q0) = {q0, q1, q2}   2. ε-closure(q1) = {q1, q2}   3. ε-closure(q2) = {q2}   Now we will obtain δ\' transition. Let ε-closure(q0) = {q0, q1, q2} call it as **state A**. Thus we have obtained 1. δ\'(A, 0) = A   2. δ\'(A, 1) = B   3. δ\'(A, 2) = C   The partial DFA will be: Conversion from NFA with Null to DFA Now we will find the transitions on states B and C for each input. Hence Thus we have obtained 1. δ\'(B, 0) = ϕ   2. δ\'(B, 1) = B   3. δ\'(B, 2) = C   The partial transition diagram will be ![Conversion from NFA with Null to DFA](media/image10.png) Now we will obtain transitions for C: Hence the DFA is Conversion from NFA with Null to DFA As A = {q0, q1, q2} in which final state q2 lies hence A is final state. B = {q1, q2} in which the state q2 lies hence B is also final state. C = {q2}, the state q2 lies hence C is also a final state. **[Converting NFA to DFA-]**   The following steps are followed to convert a given NFA to a DFA- **[Step-00]** Draw the transition table of the NFA.  **[Step-01:]** - Let Q' be a new set of states of the DFA. Q' is null in the starting. - Let T' be a new transition table of the DFA.   **[Step-02:]**   - - -   +-----------------------------------------------------------------------+ | **In NFA, if the transition of start state over some input alphabet | | is null,** | | | | **then perform the transition of start state over that input alphabet | | to a dead state in the DFA**. | +-----------------------------------------------------------------------+   **[Step-03:]**  Now look to the transition table T\'. If any new state is present in the transition table T', - -  **[Step-04:]** Keep repeating Step-03 until no new state is present in the transition table T'. **Step 5:** States containing the final state of nfa as its component are treated as final states of the DFA. Finally, the transition table T' so obtained is the complete transition table of the required DFA.   **[Example]** Convert the following Non-Deterministic Finite Automata (NFA) to Deterministic Finite Automata (DFA)-   ![https://www.gatevidyalay.com/wp-content/uploads/2019/07/NFA-to-DFA-Conversion-Problem-02-NFA.png](media/image12.png)   **[Solution]**   **Step 0:** Transition table for the given Non-Deterministic Finite Automata (NFA) is-   **State / Alphabet** **0** **1** ---------------------- ---------- ---------- →**q0** q0 q1, \*q2 **q1** q1, \*q2 \*q2 **\*q2** q0, q1 q1   **[Step-01:]**   Let Q' be a new set of states of the Deterministic Finite Automata (DFA). Let T' be a new transition table of the DFA.   **[Step-02:]**   Add transitions of start state q0 to the transition table T'.   **State / Alphabet** **0** **1** ---------------------- ------- ---------- →**q0** q0 {q1, q2}   **[Step-03:]**  Now in the transition table T\' the new state is {q1, q2}, Add the new state {q1, q2} to Q\'. Add transitions of state {q1, q2} to the transition table T'.   **State / Alphabet** **0** **1** ---------------------- -------------- ---------- →**q0** q0 {q1, q2} **{q1, q2}** {q0, q1, q2} {q1, q2}   **[Step-04:]** Now in the transition table T\' the new state is {q0, q1, q2}, Add the new state {q0, q1, q2} in Q' Add transitions of state {q0, q1, q2} to the transition table T'.   **State / Alphabet** **0** **1** ---------------------- -------------- ---------- →**q0** q0 {q1, q2} **{q1, q2}** {q0, q1, q2} {q1, q2} **{q0, q1, q2}** {q0, q1, q2} {q1, q2}   **[Step-05:]**   Now there is no new states are left to be added in the transition table T', so we stop. **States containing q2 as its component are treated as final states of the DFA.**  Finally, Transition table for Deterministic Finite Automata (DFA) is-   **State / Alphabet** **0** **1** ---------------------- ---------------- ------------ →**q0** q0 \*{q1, q2} **\*{q1, q2}** \*{q0, q1, q2} \*{q1, q2} **\*{q0, q1, q2}** \*{q0, q1, q2} \*{q1, q2}   Now, Deterministic Finite Automata (DFA) may be drawn as-   https://www.gatevidyalay.com/wp-content/uploads/2019/07/NFA-to-DFA-Conversion-Problem-02-DFA.png   **Example**   Convert the following Non-Deterministic Finite Automata (NFA) to Deterministic Finite Automata (DFA)-   ![https://www.gatevidyalay.com/wp-content/uploads/2019/07/NFA-to-DFA-Conversion-Problem-03-NFA.png](media/image14.png)   **[Solution]**   **[Step 0:]** Transition table for the given Non-Deterministic Finite Automata (NFA) is-   **State / Alphabet** **a** **b** ---------------------- ---------- ------- →**q0** \*q1, q2 -- **\*q1** -- -- **q2** \*q1, q2 q2   **[Step-01:]**   Let Q' be a new set of states of the Deterministic Finite Automata (DFA). Let T' be a new transition table of the DFA.   **[Step-02:]**   Add transitions of start state q0 to the transition table T'.   **State / Alphabet** **a** **b** ---------------------- ---------- ---------------- →**q0** {q1, q2} Ø (Dead State)   **[Step-03:]**   Now in the transition table T\' the new state is {q1, q2}, Add the new state {q1, q2} in Q'. Add transitions for set of states {q1, q2} to the transition table T'.   **State / Alphabet** **a** **b** ---------------------- ---------- ------- →**q0** {q1, q2} Ø **{q1, q2}** {q1, q2} q2   **[Step-04:]**   New state present in state Q' is q2. Add transitions for state q2 to the transition table T'.   **State / Alphabet** **a** **b** ---------------------- ---------- ------- →**q0** {q1, q2} Ø **{q1, q2}** {q1, q2} q2 **q2** {q1, q2} q2   **[Step-05:]**   Add transitions for dead state {Ø} to the transition table T'.   **State / Alphabet** **a** **b** ---------------------- ---------- ------- →**q0** {q1, q2} Ø **{q1, q2}** {q1, q2} q2 **q2** {q1, q2} q2 **Ø** Ø Ø   **[Step-06:]**   Since no new states are left to be added in the transition table T', so we stop. States containing q1 as its component are treated as final states of the DFA.   Finally, Transition table for Deterministic Finite Automata (DFA) is-   **State / Alphabet** **a** **B** ---------------------- ------------ ------- →**q0** \*{q1, q2} Ø **\*{q1, q2}** \*{q1, q2} q2 **q2** \*{q1, q2} q2 **Ø** Ø Ø   Now, Deterministic Finite Automata (DFA) may be drawn as-   https://www.gatevidyalay.com/wp-content/uploads/2019/07/NFA-to-DFA-Conversion-Problem-03-DFA.png   **[Important Points-]**   It is important to note the following points when converting a given NFA into a DFA-   **[Note-01:]**   - -  

Tags

computer science theory of computation automata
Use Quizgecko on...
Browser
Browser