Skip to content

Instantly share code, notes, and snippets.

@kartikkukreja
Last active September 22, 2022 16:44
Show Gist options
  • Save kartikkukreja/3eb7f38e026bd642f8b0 to your computer and use it in GitHub Desktop.
Save kartikkukreja/3eb7f38e026bd642f8b0 to your computer and use it in GitHub Desktop.
A* Graph Search Pseudocode
def A*-GRAPH-SEARCH (start):
Let pq be an empty min priority queue
Let closed be an empty set
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)
closed.add(top)
foreach next in succ(top):
if next not in closed:
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