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.

10th Mar 2022, 12:04 PM
Anna Hari
Anna Hari - avatar
1 Odpowiedź
+ 1
Pass memo also in if dfs(graph,i,end,memo) == True:
10th Mar 2022, 1:49 PM
Jayakrishna 🇮🇳