Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
In an unweighted graph, the shortest path is simply the path with the minimum number of edges. By exploring the graph layer-by-layer, BFS ensures that every node is reached via its optimal distance.
BFS visits all nodes at distance k before moving to distance k+1, guaranteeing the shortest path property.
By storing the 'parent' of each node (the vertex that discovered it), we can reconstruct the actual shortest path back to the source.