Question: Modify the code below to run the non-deterministic finite automata (NFA) in python with the given graph below. - initialize `current_states` - define `x` -

Modify the code below to run the non-deterministic finite automata (NFA) in python with the given graph below. Modify the code below to run the non-deterministic finite automata (NFA) in

- initialize `current_states`

- define `x`

- define the NFA given above with edit nfa1

Code: (Only modify the section "code here")

```

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 = nfa.states[code here]

# 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 = code here

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'})

nfa1 = code here

# 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()

```

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!