Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

BFS shortest paths

In a graph where every edge counts the same, BFS from a vertex finds the shortest path to every other vertex for free.

In an unweighted graph, the order BFS discovers vertices from a source s assigns each vertex v exactly d(s,v), the true shortest-path distance -- a direct consequence of BFS exploring strictly by increasing distance.

Read the full section →
Graph settings

Calculator