Breadth-First Search (BFS) Is An
Breadth-First Search (BFS) Is An
Breadth-First Search (BFS) Is An
searching tree or graph data structures. It starts at the tree root (or some arbitrary node
of a graph, sometimes referred to as a 'search key') and explores the neighbor nodes
first, before moving to the next level neighbors .
Breadth-first search
Class
Search algorithm
Data structure
Graph
Completeness:
it is easy to see that breadth-first search is complete that it visit all levels given that d
factor is finite, so in some d it will find a solution.
Optimality:
breadth-first search is not optimal until all actions have the same cost.
Space complexity and Time complexity:
Consider a state space where each node as a branching factor b, the root of the tree
generates b nodes, each of which generates b nodes yielding b 2 each of these
generates b3 and so on.
In the worst case, suppose that our solution is at depth d, and we expand all nodes but
the last node at level d, then the total number of generated nodes is: b + b 2 + b3 + b4 +
bd+1 b = O(bd+1), which is the time complexity of BFS.
As all the nodes must retain in memory while we expand our search, then the space
complexity is like the time complexity plus the root node = O(bd+1).
ADVANTAGES OF BREADTH-FIRST SEARCH
1. Breadth first search will never get trapped exploring the useless path forever.
2. If there is a solution, BFS will definitely find it out.
3. If there is more than one solution, then BFS can find the minimal one that
requires less number of steps.
Algorithm
For each vertex u in V[G] {s}
do color[u] WHITE
d[u]
partition[u] 0
color[s] GRAY
partition[s] 1
d[s] 0
Q [s]
while Queue 'Q' is non-empty
do u head [Q]
for each v in Adj[u] do
if partition [u] partition [v]
then return 0
else
if color[v] WHITE then
then color[v] gray
d[v] = d[u] + 1
partition[v] 3 partition[u]
ENQUEUE (Q, v)
DEQUEUE (Q)
Color[u] BLACK
Return 1
Conclusion:
We see that space complexity is the biggest problem for BFS than its exponential
execution time.