~/ learn/ comp-372/ cards/ Breadth-first search & shortest paths
1 of 5

Type the BFS discovery step for a white neighbour v of u

Type the BFS discovery step for a white neighbour v of u

Answer

dist[v] = dist[u] + 1 parent[v] = u q.append(v)

When v is first discovered from u, its distance is one more than u’s, its parent is u, and it joins the frontier queue. The white-check (dist[v] == INF) guards this so each vertex enqueues once.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/20484ca9-b406-4073-9a22-d2f21b6b7dd4/flashcard utf-8 LF