0

Check if the path is exist or not in the graph

def dfs(graph,start,end): if start == end : return True for i in graph[start]: if dfs(graph,i,end) == True: return True return False graph = {'2': set(['7','9']), '5': set(), '7': set(['2']), '9': set(['2'])} print(dfs(graph,'7','9')) Please help me by correct this code. I can't get the correct output

10th Mar 2022, 12:08 PM
Anna Hari
Anna Hari - avatar
2 odpowiedzi
+ 1
May I ask why the vector `memo` has been initialised as empty? (and it has not been passed as a parameter while calling the function as well?)
10th Mar 2022, 12:21 PM
Abhishek Tandon
Abhishek Tandon - avatar