To Convert NFA To DFA: Date: 04/02/2022
To Convert NFA To DFA: Date: 04/02/2022
Algorithm:
1. Step 1: Initially Q’ = ɸ.
2. Add q0 to Q’.
3. For each state in Q’, find the possible set of states for each input symbol
using the transition function of NFA. If this set of states is not in Q’, add it
to Q’.
4. Final state of DFA will be all states with contain F (final states of NFA)
PROGRAM:
import pandas as pd
nfa = {}
n = int(input("No. of states : "))
#Enter total no. of transitions/paths eg: a,b so input 2 for
a,b,c t = int(input("No. of transitions : "))
for i in range(n):
state = input("state name : ")
nfa[state] = {}
for j in range(t):
path = input("path : ")
print("Enter end state from state {} traveling through path
{} : ".format(state,path))
reaching_state = [x for x in input().split()]
nfa[state][path] = reaching_state
print("\nNFA :- \n")
new_states_list = []
for x in dfa_states_list:
for i in x:
if i in nfa_final_state:
dfa_final_states.append(x)
break
Output:
Result:
Program to convert RE to NFA was written and executed successfully using the
given example.