lease I need an explanation of the code and how I can implement it
Please I need an explanation of the code and how I can implement it
graph={}
route=[]
visited=[]
def dfs(start,dest):
lmt = input("\nLimit: ")
route.append(start)
countnode=0
countlimit=0
nodeinlevel=0
while len(route)>0:
vertex=route.pop(len(route)-1)
if vertex not in visited:
visited.append(vertex)
route.extend(set(graph[vertex])-set(visited))
countnode+=1
if nodeinlevel==countnode:
nodeinlevel=len(route)
countnode=0
countlimit+=1
if countlimit==lmt:
print ('cut off')
break
if visited._contains_(dest):
return visited
st = input("Starting Point: ")
if st not in graph:
print(st+"does not exist\n\nStarting Point: ");
st = input("Starting Point: ")
en = input("\n\nEnding Point: ")
if en not in graph:
print(en+"does not exist\n\nEnding Point: ");
en = input()
v = dfs(st, en)
print("\nShortest Path: ")
j=0
for i in v:
print(v[j])
j+=1

Step by step
Solved in 2 steps









