PYTHON ALGORITHM…AGAIN.(Depth first search(Dfs))

def dfs(graph, node,   path=[]):path += [node]for n in graph[node]:if n not in path:path = dfs(graph, n, path)return pathgraph = {'A':['B', 'C', 'D'],'B':['A', 'E'],'C':['A', 'F'],'D':['A', 'G', 'H'],'E':['B'],'F':['C', 'I', 'J'],'G':['D'],'H':['D'],'I':['F'],'J':['F']}print(dfs (graph,'A'))
:P

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store