Question
Need to finish this python program to solve the NFA, but I'm not sure how. I'm mostly familiar with java. A nondeterministic finite-state automaton
Need to finish this python program to solve the NFA, but I'm not sure how. I'm mostly familiar with java.
""" A nondeterministic finite-state automaton that recognizes strings with 0 as the next-to-last character. """
""" The current set of states, encoded bitwise: state i is represented by the bit 1
""" Reset the current state set to {the start state}. """ def reset(): global stateSet stateSet = 1
""" The transition function represented as an array. The set of next states from a given state s and character c is at delta[s,c-'0']. delta[q0,0] = {q0} delta[q0,1] = {q0,q1} delta[q1,0] = {q2} delta[q1,1] = {q2} delta[q2,0] = {} delta[q2,1] = {} """ delta = [[1
""" Make one transition from state-set to state-set on each char in the given string. @param inp the String to use """ def process(inp): global stateSet for i in range(len(inp)): c = inp[i] nextSS = 0 # next state set, initially empty for s in range(3): # for each state s if (stateSet&(1
""" Test whether the NFA accepted the string. @return true if the final set includes an accepting state. """ def accepted(): global stateSet return (stateSet&(1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started