# The breadth-first search algorithm

Breadth-first search assigns two values to each vertex

A

**distance**, giving the minimum number of edges in any path from the source vertex to vertex$v$ .The

**predecessor**vertex of$v$ along some shortest path from the source vertex. The source vertex's predecessor is some special value, such as*null*, indicating that it has no predecessor.

If there is no path from the source vertex to vertex

For example, here's an undirected graph with eight vertices, numbered *null*:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy