Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def backtrace(parent, start, end):
- path = [end]
- while path[-1] != start:
- path.append(parent[path[-1]])
- path.reverse()
- return path
- def basicSearch(tree, start, goal):
- parent = {}
- path = []
- visited = [False] * (len(tree))
- squeue = queue.Queue()
- squeue.put(start)
- visited[start] = True
- found=False
- while squeue:
- s = squeue.get(0)
- path.append(s)
- if(s == goal):
- found=True
- return backtrace(parent, start, goal)
- # Get all adjacent vertices of the
- # dequeued vertex s. If a adjacent
- # has not been visited, then mark it
- # visited and enqueue it
- for l in tree[s]:
- if visited[l] == False:
- parent[l] = s
- squeue.put(l)
- visited[l] = True
- return path
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement