← back to algorithms

dedicated visualizer

Breadth-First Search

Explores graph layers in queue order and finds shortest paths in unweighted graphs. This page keeps the runner, chart, and controls focused on a single algorithm so the walkthrough feels calmer than the overview page.

graphsbeginnerbest O(V + E)worst O(V + E)space O(V)
queuelevel-order explorationunweighted shortest path

session controls

Compare this algorithm against a related one, turn on quiz mode, or keep the current state in a shareable URL.

current shareable URL

Copy the URL to preserve this exact dataset, target, compare mode, and quiz state.

browse more

Want a different problem or visual mode? Jump back to the catalog and open another dedicated page.

open catalog

scenario presets

Load a focused input that reveals a specific behavior quickly instead of hand-editing every value first.

graph controls

Graph algorithms reuse the same learning graph so you can compare traversal and shortest-path behavior side by side.

graph note

BFS and DFS emphasize traversal order. Dijkstra adds weighted relaxations and a cost-aware final route.

step 1 / 150% complete

current action

enqueue start

queue

A

current node

none

run summary

Finished in 15 steps. G is the target node, so BFS stops here.

visited

7

queue

0

frontier

0

steps

15

final route

A → C → F → G

current explanation

Breadth-first search starts by enqueueing A.

simple explanation

BFS explores level by level using a queue.

pseudocode

1enqueue the start node
2dequeue the front node
3return if it is the target
4enqueue each undiscovered neighbor
5repeat until the queue is empty

complexity card

best

O(V + E)

average

O(V + E)

worst

O(V + E)

space

O(V)

algorithm notes

intuition

BFS moves outward in waves, so the first time it reaches a node is the shortest unweighted route.

tradeoffs

  • Excellent for shortest paths in unweighted graphs.
  • Queue can grow large on wide graphs.
  • Visits neighbors in strict breadth order.

when to use it

Use for reachability, level-order traversal, and shortest paths when every edge has equal cost.

interview tips

  • Mention parent tracking if you need to reconstruct the path.
  • Explain why the first visit to a node is enough in an unweighted graph.

what I learned building this

typed definitions

One algorithm schema now drives the catalog, counters, pseudocode, notes, and visual modes, which keeps the UI consistent as the lab grows.

replay over mutation

Precomputed steps made it much easier to synchronize explanations, metrics, quiz prompts, and scrubber playback without hidden state drifting out of sync.

portfolio framing

Shareable URL state, compare mode, and responsive layouts mattered as much as the algorithm logic because this page needs to teach clearly and still feel polished as a product.

more in this lane

Want a different take on the same problem family? These stay in the same category but change the strategy.