Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

graph1 = { a : [c], b : [c, e], c : [a, b, d, e], d : [c], e : [c, b], f :

graph1 = { "a" : ["c"],

"b" : ["c", "e"], "c" : ["a", "b", "d", "e"], "d" : ["c"], "e" : ["c", "b"], "f" : [] } def generate_edges(graph): edges = [] for node in graph: for neighbour in graph[node]: edges.append((node, neighbour)) return edges

print('## edges ##') print(generate_edges(graph1))

def find_isolated_nodes(graph): isolated = [] for node in graph: if not graph[node]: isolated += node return isolated print('## isolated nodes ##') print(find_isolated_nodes(graph1))

##word list{hit--hot--dot--dog--cog--log--lot

words ={ 'hit': 'hot': 'dot': 'dog': 'cog': 'log': 'lot':

}

print(generate_edges(words))

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

def bfs(graph,start):

visited , queue = set() , [start]

while queue != []:

vertex = queue.pop(0) # from queue : pop the oldest

if vertex not in visited:

##Sample run

enter startWord : hot

enter endtWord : dog

True

enter startWord : hot

enter endtWord : cog

True

enter startWord : hit

enter endtWord : ddd

False

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2018 Dublin Ireland September 10 14 2018 Proceedings Part 1 Lnai 11051

Authors: Michele Berlingerio ,Francesco Bonchi ,Thomas Gartner ,Neil Hurley ,Georgiana Ifrim

1st Edition

3030109240, 978-3030109240

More Books

Students also viewed these Databases questions