Answered step by step
Verified Expert Solution
Question
1 Approved Answer
write python code to convert nfa to dfa change this code i need like this but chagned one # nfaDict = { # ' 0
write python code to convert nfa to dfa change this code i need like this but chagned one # nfaDict
# : a: b:
# : a:
# : b:
# : a: b:
# : a: b:
# : eps:
#
# nfaDict
# : a: b: 'eps':
# : a: 'eps':
# : c: d: 'eps':
# : c: d:
# : a: b: 'eps':
#
# j nfaDictc
# printj
# nfaDict
# A: : B: E
# B: : C 'eps': D
# C: : D 'eps': F
# D:
# E: : F 'eps': BC
# F: : D: E
#
# nfaDict
# : eps:
# : a:
# : b: 'eps':
# : a:
# : a: 'eps':
# : b:
# : b: 'eps':
# : a:
# :
#
# nfaDict
# : eps:
# : a: 'eps':
# : a: b:
# : b:
# : eps:
# : b:
#
# nfaDict
# : eps:
# : b:a:
# : b:a:
# : a:
#
# nfaDict
# : b: 'eps':
# : a: b:
# : a:
#
# nfaDict
# : a: b:
# : b:
# :
#
nfaDict
: a: 'eps':
: a:
: b:
: a:b:
:
strt # should get input form user
allconnectedstates set
checked set
# Func a function to find connected states those are our mainStates that we can reach
def findconnectedstatesnfaDict start:
global allconnectedstates
keyofstart nfaDictstart
straightreachablestates set
temporary listkeyofstart.values
for dic in temporary:
straightreachablestates.updatedic
allconnectedstates.updatestraightreachablestates
allconnectedstates.updatestart
checked.addstart
for stt in straightreachablestates:
if stt not in checked:
findconnectedstatesnfaDict stt
return allconnectedstates
a findconnectedstatesnfaDict strt
printfa Only these states are reachable from start state of strt
print
# Func a function for removing unreachables from nfaDict
def removeunreachablestatesDictin afindconnectedstatesnfaDict strt:
global tempDict,tempNfaStates
tempDict Dictin
nfaPrimaryStates listnfaDictkeys
for membr in a:
if membr in nfaPrimaryStates:
tempNfaStates nfaPrimaryStates
tempNfaStates.removemembr
printfStatestempNfaStates are not reacheable and removed'
print
for k in tempNfaStates:
del tempDictk
return tempDict
availableStates removeunreachablestates
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