Skip to content

Instantly share code, notes, and snippets.

@kartikkukreja
Last active September 22, 2022 16:44
Show Gist options
  • Save kartikkukreja/ddc476395e7d7511486d to your computer and use it in GitHub Desktop.
Save kartikkukreja/ddc476395e7d7511486d to your computer and use it in GitHub Desktop.
A* Tree Search Pseudocode
def A*-TREE-SEARCH (start):
Let pq be an empty min priority queue
g(start) = 0
f(start) = h(start)
path(start) = []
pq.push(start, f(start))
while not pq.empty():
top = pq.pop()
if isGoal(top):
return f(top), path(top)
foreach next in succ(top):
g(next) = g(top) + cost(top, next)
f(next) = g(next) + h(next)
path(next) = path(top).append(next)
pq.push(next, f(next))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment