Menu
Coddy logo textTech

Motivation

Lesson 2 of 9 in Coddy's Breadth-First Search - Graph Algorithms course.

BFS uses a queue (first in, first out) so that vertices are processed in the exact order they are discovered, which produces the layer-by-layer exploration.

Why learn BFS?

  • Shortest paths: in an unweighted graph, BFS finds the fewest-edges path from the start to every other vertex.
  • Simple and linear: it runs in O(V + E) with a queue and a visited marker.
  • Everywhere: shortest hops in networks, word ladders, maze solving, and level-order tree traversal are all BFS.

As with DFS, we enqueue a vertex's neighbors in ascending order so results are predictable.

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Breadth-First Search - Graph Algorithms