3 Breadth First Search
function bfs(P = ⟨S, s₀, A, τ, c, G⟩):
agenda ← newQueue()
agenda.enQueue(s₀)
while not agenda.isEmpty():
s ← agenda.deQueue() # expand s
for a ∈ A:
s' ← τ(s, a)
if s' ∈ G: # goal found?
return "done"
agenda.enQueue(s') # goal not found, add s' to queue
Utilise queue for FIFO
Expand all nodes on depth before expanding any on depth .
For the branching factor and the depth at which the solution occurs, then BFS takes (i.e. explores ).
Evaluation
Completeness: BFS guaranteed to find a solution if it exists.
Time complexity: is exponential in depth of the tree. If solution at shallower depths, BFS is good approach.
Space complexity: Requires storing at least entire frontier of . Susceptible to combinatorial explosion for larger problems.
Optimality: Solution found will be optimal.