01The problem and the wave
Given an unweighted graph (every edge counts as 1) and a source vertex s, find the distance, meaning the number of edges, from s to every reachable vertex. BFS works on directed and undirected graphs alike, and while it runs it builds the BFS tree rooted at s, in which the path from s to each vertex is one of the shortest.
The lecture calls BFS a wave algorithm: it first finds all vertices one edge away from s, then all vertices two edges away, and so on, like a ripple spreading over water. On the lecture’s graph with s = 4: first 5, 2 and 3; then 7, 1, 6 and 8; finally 9.
Because the wave reaches nearer vertices first, a distance found by BFS is final: it is already the shortest and never improves on later steps.