RK DSA Studio

Breadth-first search

Explore reachable vertices one layer at a time using a queue. First discovery gives shortest edge counts in an unweighted graph.

Remember: Queue → layer by layer.

Example: A → B → C gives distances 0,1,2 from A.

Time: O(V + E). Auxiliary space: O(V).

Formula: dist[v] = dist[u] + 1 on first discovery

Up to 8 unique integer vertex labels and 16 edges. Edges: from,to; separate edges with semicolons. Directed graph. Explore only the source component. Graph storage O(V + E) is excluded from auxiliary space.

Complexities describe the underlying algorithm; tutorial snapshots and rendering can use additional resources.

The interactive workspace loads here when JavaScript is available. You can still browse the learning notes and links above without it.