Skip to content

Latest commit

 

History

History
42 lines (36 loc) · 2.13 KB

Breadth-First-Search.md

File metadata and controls

42 lines (36 loc) · 2.13 KB

BREADTH-FIRST-SEARCH

AIMA4e

function BREADTH-FIRST-SEARCH(problem) returns a solution node, or failure
if the initial state is a goal then
   return a node for the initial state
frontier ← a FIFO queue, with a node for the initial state
reached ← a set of states, initially empty
while frontier is not empty do
   node ← POP(frontier)
   if node is a goal then return node
   for child in EXPAND(problem, node) do
    schild.STATE
    if s is a goal then return child
    if s is not in reached then
     add s to reached
     add child to frontier
return failure


Figure 3.2 Breadth-first search algorithm.

AIMA3e

function BREADTH-FIRST-SEARCH(problem) returns a solution, or failure
node ← a node with STATE = problem.INITIAL-STATE, PATH-COST = 0
if problem.GOAL-TEST(node.STATE) then return SOLUTION(node)
frontier ← a FIFO queue with node as the only element
explored ← an empty set
loop do
   if EMPTY?(frontier) then return failure
   node ← POP(frontier) /* chooses the shallowest node in frontier */
   add node.STATE to explored
   for each action in problem.ACTIONS(node.STATE) do
      child ← CHILD-NODE(problem,node,action)
      if child.STATE is not in explored or frontier then
         if problem.GOAL-TEST(child.STATE) then return SOLUTION(child)
         frontier ← INSERT(child,frontier)


Figure ?? Breadth-first search on a graph.