Best-First Search

Suppose PQ is a priority queue that stores states so that the state with the lowest heuristic value is removed first (of course there may be ties).

Then the following operation will construct a search tree in a "best-first" fashion:

Search(s)
   d[s] = 0
   pred[s] = null
   PQ = {s}
   V = {s}
   while PQ ≠ {} do
      u = Remove[PQ]
      if success(u) 
         then return u
      for each v ∈ expand(u) do
         if v ∉ V
            then put v in V
                 d[v] = d[u] + 1
                 pred[v] = u
                 Add(PQ,v)
   return null