2076 9

CSC262 · 2076 · 5 marks

Construct a NFA accepting language of {0, 1} with each string ending with 01 and convert it into equivalent DFA.

Construct a NFA accepting language of {0, 1} with each string ending with 01 and convert it into equivalent DFA. [5]

Theory of ComputationChapter 2: Introduction to Finite AutomataMethod for reduction of NFA to DFA

NFA Accepting Strings Ending with 01, and its Equivalent DFA

Part 1: Constructing the NFA

Language: L = { w | w ∈ {0,1}* and w ends with 01 }

Example strings: 01, 001, 101, 0001, 1101, ...

NFA States and Design

We need 3 states:

StateRole
q0Start state (reading any symbol, staying in loop)
q1Just read '0' (possible start of ending "01")
q2Just read '01' -- Final/Accept state

NFA Transition Diagram

     0,1          0              1
  ┌──────┐    ┌──────┐       ┌──────┐
  │      ▼    │      ▼       │      ▼
 (q0) ──0──► (q1) ──1──►  ((q2))
  ▲                           
  └──────────────────────────

More precisely:

  • q0 loops on both 0 and 1 (to consume any prefix)
  • q0 on input 0 also goes to q1 (non-deterministic choice)
  • q1 on input 1 goes to q2 (accept)
  • q2 has no outgoing transitions

NFA Transition Table

StateInput 0Input 1
→q0{q0, q1}{q0}
q1{}{q2}
*q2{}{}

→ = start state, * = final state


Part 2: Converting NFA to Equivalent DFA (Subset Construction)

Each DFA state represents a subset of NFA states.

Step 1: Start State

DFA start state = {q0}

Step 2: Compute Transitions for Each DFA State

For {q0}:

  • On 0: δ(q0, 0) = {q0, q1} → new state {q0, q1}
  • On 1: δ(q0, 1) = {q0} → state {q0}

For {q0, q1}:

  • On 0: δ(q0,0) ∪ δ(q1,0) = {q0,q1} ∪ {} = {q0, q1}
  • On 1: δ(q0,1) ∪ δ(q1,1) = {q0} ∪ {q2} = {q0, q2} → new state

For {q0, q2}:

  • On 0: δ(q0,0) ∪ δ(q2,0) = {q0,q1} ∪ {} = {q0, q1}
  • On 1: δ(q0,1) ∪ δ(q2,1) = {q0} ∪ {} = {q0}

Step 3: DFA Transition Table

DFA StateOn 0On 1Final?
→ A = {q0}B = {q0,q1}A = {q0}No
B = {q0,q1}B = {q0,q1}C = {q0,q2}No
*C = {q0,q2}B = {q0,q1}A = {q0}Yes (contains q2)

C is a final state because it contains q2 (the NFA's final state).

Step 4: DFA Transition Diagram

        0              0
  ┌──────────┐    ┌─────────┐
  │          ▼    │         ▼
 (A) ──0──► (B) ──1──►  ((C))
  ▲    1     │              │
  └──────────┘    0         │ 1
       ▲──────────┘         │
       └─────────────────────┘

Simplified transitions:

     1          0           1
(A) ──► (A)   (A) ──► (B) ──► (C)
                (B) ──► (B)
                (C) ──► (B)
                (C) ──1──► (A)

Summary

  • 3 DFA states are sufficient: A, B, C
  • C = {q0, q2} is the only final state
  • The DFA correctly accepts all strings over {0,1} that end with 01

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.