~/ 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/7fcd80fc-f820-47ce-85a1-c27b9665f9a2/flashcard utf-8 LF