notesonly.in

One notebook for every subject — open it anywhere.

Log in

Graphs: representation, traversal (BFS, DFS)

Data Structures · Engineering

Study notes

Find the shortest route in an unweighted map from A: BFS visits A's neighbors (level 1), then their neighbors (level 2). The first time BFS reaches target T at level 3, that 3-edge path is the shortest possible. DFS might wander down a long path first and miss it.

← Back to topics for Engineering