Answered step by step
Verified Expert Solution
Link Copied!

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 ={
# '0': {'a': {'1'},'b': {'2'}},
# '1': {'a': {'3'}},
# '2': {'b': {'3'}},
# '3': {'a': {'4'},'b': {'4'}},
# '4': {'a': {'5'},'b': {'5'}},
# '5': {'eps': {'0'}}
# }
# nfaDict ={
# '0': {'a': {'1','3'},'b': {'2'}, 'eps': {'4'}},
# '1': {'a': {'2','4'}, 'eps': {'3'}},
# '2': {'c': {'1'},'d': {'3'}, 'eps': {'4'}},
# '3': {'c': {'4'},'d': {'2'}},
# '4': {'a': {'3','4'},'b': {'0'}, 'eps': {'2'}},
# }
# j = nfaDict['2']['c']
# print(j)
# nfaDict ={
# 'A': {'1': {'B'},'0': {'E'}},
# 'B': {'1': {'C'}, 'eps': {'D'}},
# 'C': {'1': {'D'}, 'eps': {'F'}},
# 'D': {},
# 'E': {'0': {'F'}, 'eps': {'B','C'}},
# 'F': {'0': {'D'},'1': {'E'}}
# }
# nfaDict ={
# '1': {'eps': {'2','5'}},
# '2': {'a': {'3'}},
# '3': {'b': {'3'}, 'eps': {'4'}},
# '4': {'a': {'4'}},
# '5': {'a': {'6'}, 'eps': {'7'}},
# '6': {'b': {'7'}},
# '7': {'b': {'8'}, 'eps': {'5'}},
# '8': {'a': {'9'}},
# '9': {}
# }
# nfaDict ={
# '1': {'eps': {'2','3'}},
# '2': {'a': {'4'}, 'eps': {'5'}},
# '3': {'a': {'3'},'b': {'6'}},
# '4': {'b': {'5'}},
# '5': {'eps': {'2'}},
# '6': {'b': {'6'}}
# }
# nfaDict ={
# '0': {'eps': {'3'}},
# '1': {'b':{'1'},'a':{'0'}},
# '2': {'b':{'0'},'a':{'2','3'}},
# '3': {'a':{'1'}}
# }
# nfaDict ={
# '1': {'b': {'2'},'eps': {'3'}},
# '2': {'a': {'2','3'},'b':{'3'}},
# '3': {'a': {'1'}},
# }
# nfaDict ={
# '0': {'a': {'0','1'},'b': {'0'}},
# '1': {'b':{'2'}},
# '2': {}
# }
nfaDict ={
'1': {'a': {'3'},'eps': {'2'}},
'2': {'a':{'4','5'}},
'3': {'b':{'4'}},
'4': {'a':{'5'},'b':{'5'}},
'5': {}
}
strt ='1' # should get input form user
all_connected_states = set()
checked = set()
# Func-1// a function to find connected states those are our mainStates that we can reach
def find_connected_states(nfaDict, start):
global all_connected_states
key_of_start = nfaDict[start]
straight_reachable_states = set()
temporary = list(key_of_start.values())
for dic in temporary:
straight_reachable_states.update(dic)
all_connected_states.update(straight_reachable_states)
all_connected_states.update(start)
checked.add(start)
for stt in straight_reachable_states:
if stt not in checked:
find_connected_states(nfaDict, stt)
return all_connected_states
a = find_connected_states(nfaDict, strt)
print(f'{a} Only these states are reachable from start state of {strt}')
print("-------------------------------------------------------------")
# Func-2// a function for removing unreachables from nfaDict
def remove_unreachable_states(Dictin, a=find_connected_states(nfaDict, strt)):
global tempDict,tempNfaStates
tempDict = Dictin
nfaPrimaryStates = list(nfaDict.keys())
for membr in a:
if membr in nfaPrimaryStates:
tempNfaStates = nfaPrimaryStates
tempNfaStates.remove(membr)
print(f'State(s){tempNfaStates} are not reacheable and removed')
print("-------------------------------------------------------------")
for k in tempNfaStates:
del tempDict[k]
return tempDict
available_States = remove_unreachable_states(

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

How many wires and how many pairs are there in a UTP cord?

Answered: 1 week ago

Question

What obstacles interfere with eff ective listening?

Answered: 1 week ago