Science  People  Locations  Timeline
Index: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Home > Breadth-first search


In computer science, Breadth-first search (BFS) is a tree search algorithm used for traversing or searching a tree (graph theory) or tree structure. Intuitively, you start at the root node and explore all the neighboring nodes. Then for each of those nearest nodes, explore their unexplored neighbor nodes, and so on until it finds the goal.

Formally, BFS is an uninformed search method that aims to expand and examine all nodes of a tree systematically in search of a solution. In other words, it exhaustively searches the entire tree without considering the goal until it finds it. It does not use a heuristic.

From the standpoint of the algorithm, all nodes obtained by expanding any node are placed at the end of the search queue. In typical implementations, nodes that have not yet been examined for their neighbors are placed in some container (such as a queue or linked list) called "open" and then once examined are placed in the container "closed".

When searching in an unweighted cyclic graph (one that is not a tree) for a shortest path, BFS may be adapted by keeping a bit on each node to indicate that it has already been visited.

For the following graph:


a breadth-first search starting at A, and assuming that the left edges in the shown graph are chosen before right edges, will result in the search visiting the nodes in the following order: A, B, C, E, D, F, G. Compare with depth-first search.

1 pseudocode

BFS(Start,Goal) push(Queue,Start) while(notEmpty(Queue)) Node <- Pop(Queue) if (Node == Goal) return Node forall Child <- Expand(Node) push(Queue, Child)

2 See also

3 External links


BFS can also stand for the pop punkPop punk is really used for two separate subgenres of punk rock music: the kind typically found on Lookout! Records, which stray very little from the three-chord formula that The Ramones pioneered, as well as a newer subgenre of melodic, more emotional pu band, Bowling for SoupBowling for Soup is a Wichita Falls-based punk-pop band formed in 1994, best known for their singles "Girl All The Bad Guys Want" in 2002 on Drunk Enough to Dance and "1985" in 2004 on Hangover You Don't Deserve''. The band's name is derived from comedian.


Trees (structure)

Read more »

Non User