BFS
BFS, or breadth-first search, is a graph traversal algorithm that starts at a designated source node and explores all neighboring vertices at the present depth prior to moving on to vertices at the next depth level. In graphs, BFS visits nodes in order of increasing distance from the start node, where distance is measured by the number of edges in a path.
Implementation typically uses a queue. The algorithm enqueues the start node, marks it as discovered, then repeatedly
Performance: On a graph with V vertices and E edges, BFS runs in O(V+E) time and uses
Variations and related techniques include bidirectional BFS, which runs two simultaneous searches from the start and
Applications include finding the shortest unweighted path, solving puzzles such as word ladders, aggregating nodes by