Breadth-First Search
Summarized notes on Introduction to Algorithms, Chapter 22
- works on both directed and undirected graphs
- Given source vertex
, BFS systematically explores edges of to discover every vertex that is reachable from - it computes the shortest-path distance (min number of edges) from
to each reachable vertex - output of BFS is one breadth-first tree, where
is root and all reachable vertices are nodes - result of BFS depends on which order each adjacent vertexes are visited but the computed distances will be the same independent of order
Edge coloring
- all vertices start out as white
- when edge is discovered it becomes nonwhite
- grey vertices are the "frontier" - may have some adjacent white vertices
- black vertices are such that they have no undiscovered adjacent vertices
- BFS FIFO queue consists of grey vertices
Complexity
Running Time | |
---|---|
BFS is linear time |
Breadth-First Tree
- is a predecessor subgraph such that
- consists of vertices reachable form
- contains a unique simple path from
to - is connected and has |
| tree edges