Question: nfa.py class FA: def _ _ init _ _ ( self , alphabet, states, transition, accepting _ states ) : self.alphabet = alphabet self.states =

nfa.py
class FA:
def __init__(self, alphabet, states, transition, accepting_states):
self.alphabet = alphabet
self.states = states
self.transition = transition
self.accepting_states = accepting_states
def DFA(input_string, dfa):
# set current_state to initial state
current_state = dfa.states[0]
# run through the input string
for symbol in input_string:
i = dfa.states.index(current_state)
j = dfa.alphabet.index(symbol)
current_state = dfa.transition[i][j]
return current_state
def NFA(input_string, nfa):
# set current_state to initial state
current_states = #
# run through the input string
for symbol in input_string:
x = set()
for state in current_states:
i = nfa.states.index(state)
j = nfa.alphabet.index(symbol)
x = #
current_states = x
return current_states
def main():
# Read in the input_string
input_string = input()
# Define a DFA
dfa1= FA(['0','1'],['q','r'],[['r','q'],['q','r']],{'q'})
# Define the NFA given in Figure 8.2 for n=5
nfa1= #
# Run the DFA on the input string
# final_state = DFA(input_string, dfa1)
# if final_state in dfa1.accepting_states:
# print("Accept")
# else:
# print("Reject")
# Run the NFA on the input string
final_states = NFA(input_string, nfa1)
if set(final_states) & set(nfa1.accepting_states):
print("Accept")
else:
print("Reject")
if __name__=="__main__":
main()
 nfa.py class FA: def __init__(self, alphabet, states, transition, accepting_states): self.alphabet =

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!