Breadth-First Search (BFS) Is An Algorithm For
Breadth-First Search (BFS) Is An Algorithm For
org/wiki/Breadth-first_search
Pseudocode
More details
Example
Analysis Animated example of a
Time and space complexity breadth-first search
Completeness
BFS ordering
Applications
See also
References
External links
Output: Goal state. The parent links trace the shortest path back to root
More details
1 de 4 22/01/2020 02:56 p. m.
Breadth-first search - Wikipedia https://en.wikipedia.org/wiki/Breadth-first_search
Nodes can be labelled as discovered by storing them in a set, or by an attribute on each node,
depending on the implementation.
Note that the word node is usually interchangeable with the word vertex.
The parent attribute of each node is useful for accessing the nodes in a shortest path, for example
by backtracking from the destination node up to the starting node, once the BFS has been run, and
the predecessors nodes have been set.
Breadth-first search produces a so-called breadth first tree. You can see how a breadth first tree
looks in the following example.
Example
The following is an example of the breadth-first tree obtained by running a BFS on German cities
starting from Frankfurt:
2 de 4 22/01/2020 02:56 p. m.
Breadth-first search - Wikipedia https://en.wikipedia.org/wiki/Breadth-first_search
graph is.[7]
When the number of vertices in the graph is known ahead of time, and additional data structures
are used to determine which vertices have already been added to the queue, the space complexity
can be expressed as , where is the cardinality of the set of vertices. This is in addition to
the space required for the graph itself, which may vary depending on the graph representation used
by an implementation of the algorithm.
When working with graphs that are too large to store explicitly (or infinite), it is more practical to
describe the complexity of breadth-first search in different terms: to find the nodes that are at
distance d from the start node (measured in number of edge traversals), BFS takes O(bd + 1) time
and memory, where b is the "branching factor" of the graph (the average out-degree).[8]:81
Completeness
In the analysis of algorithms, the input to breadth-first search is assumed to be a finite graph,
represented explicitly as an adjacency list or similar representation. However, in the application of
graph traversal methods in artificial intelligence the input may be an implicit representation of an
infinite graph. In this context, a search method is described as being complete if it is guaranteed to
find a goal state if one exists. Breadth-first search is complete, but depth-first search is not. When
applied to infinite graphs represented implicitly, breadth-first search will eventually find the goal
state, but depth-first search may get lost in parts of the graph that have no goal state and never
return.[9]
An enumeration of the vertices of a graph is said to be a BFS ordering if it is the possible output of
the application of BFS to this graph.
Let be a graph with vertices. Recall that is the set of neighbors of . For
be a list of distinct elements of , for , let be the
least such that is a neighbor of , if such a exists, and be otherwise.
Breadth-first search can be used to solve many problems in graph theory, for example:
Depth-first search
Iterative deepening depth-first search
Level structure
Lexicographic breadth-first search
3 de 4 22/01/2020 02:56 p. m.
Breadth-first search - Wikipedia https://en.wikipedia.org/wiki/Breadth-first_search
Knuth, Donald E. (1997), The Art of Computer Programming Vol 1. 3rd ed. (http://www-cs-facul
ty.stanford.edu/~knuth/taocp.html), Boston: Addison-Wesley, ISBN 978-0-201-89683-1
4 de 4 22/01/2020 02:56 p. m.