function RECURSIVE-BEST-FIRST-SEARCH(problem) returns a solution, or failure
return RBFS(problem,MAKE-NODE(problem.INITIAL-STATE),∞)
function RBFS(problem,node,f_limit) returns a solution, or failure and a new f-cost limit
if problem.GOAL-TEST(node.STATE) then return SOLUTION(node)
successors ← []
for each action in problem.ACTIONS(node.STATE) do
add CHILD-NODE(problem,node,action) into successors
if successors is empty then return failure,∞
for each s in successors do /* update f with value from previous search, if any */
s.f ← max(s.g + s.h, node.f)
loop do
best ← lowest f-value node in successors
if best.f > f_limit then return failure,best.f
alternative ← the second-lowest f-value among successors
result,best.f ← RBFS(problem,best,min(f_limit,alternative))
if result ≠ failure then return result
Figure ?? The algorithm for recursive best-first search.