def recursive_best_first_search(problem, h=None):
h = memoize(h or problem.h, '<STR_LIT:h>')<EOL>def RBFS(problem, node, flimit):<EOL><INDENT>if problem.goal_test(node.state):<EOL><INDENT>return node, <NUM_LIT:0>   <EOL><DEDENT>successors = node.expand(problem)<EOL>if len(successors) == <NUM_LIT:0>:<EOL><INDENT>return None, infinity<EOL><DEDENT>for s in successors:<EOL><INDENT>s.f = max(s.path_cost + h(s), node.f)<EOL><DEDENT>while True:<EOL><INDENT>successors.sort(lambda x,y: cmp(x.f, y.f)) <EOL>best = successors[<NUM_LIT:0>]<EOL>if best.f > flimit:<EOL><INDENT>return None, best.f<EOL><DEDENT>if len(successors) > <NUM_LIT:1>:<EOL><INDENT>alternative = successors[<NUM_LIT:1>].f<EOL><DEDENT>else:<EOL><INDENT>alternative = infinity<EOL><DEDENT>result, best.f = RBFS(problem, best, min(flimit, alternative))<EOL>if result is not None:<EOL><INDENT>return result, best.f<EOL><DEDENT><DEDENT><DEDENT>node = Node(problem.initial)<EOL>node.f = h(node)<EOL>result, bestf = RBFS(problem, node, infinity)<EOL>return result<EOL>
[Fig. 3.26]