Question: def bfs(graph,start): visited , queue = set() , [start] while queue != []: vertex = queue.pop(0) # from queue : pop the oldest if vertex
def bfs(graph,start):
visited , queue = set() , [start]
while queue != []:
vertex = queue.pop(0) # from queue : pop the oldest
if vertex not in visited:
visited.add(vertex)
queue.extend(graph[vertex] - visited)
return visited
print (bfs(words,'hit'))
###wordlist [hit,hot,dot,dog,cog,log,lot]
###Modify bfs() function to allow the user to enter 'startWord' and 'endWord'. The function should return 'True' if a transformation sequence exists. Return 'False' if there is no such transformation sequence. Notice that you don't need to find the number of transformations. It searches the tree using BFS algorithm to see if a transformation sequence exists
Sample Run
enter startWord : hot
enter endtWord : dog
True
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
