Discrete Mathsfor Engineers

Structures, proofs, and intuition

EN | PT

Breadth-First Search (BFS)

Part 2 — The Core Idea (Layers + Queue)

Series: Breadth-First Search (BFS) Part 2 of 8

The Core Idea of BFS


Before writing code, we must understand the geometry of the algorithm.

Breadth-First Search is not simply visiting neighbors.

It is the systematic exploration of a graph in distance layers.

BFS expands outward from a source vertex like a wave.

Distance Layers


Let G = (V, E) and let s ∈ V be a source vertex.

Define the distance function δ(s, v) as the minimum number of edges in any path from s to v.

Now define the layers:

Li = { v ∈ V ∣ δ(s, v) = i }

These sets partition the reachable vertices:

  • L0 = {s}
  • L1 = neighbors of s
  • L2 = vertices at distance 2
  • L3, and so on

This layered structure is the geometric heart of BFS.

Why Layers Matter


BFS guarantees: if a vertex is discovered in layer Li, then no shorter path to that vertex exists.

Why?

Because BFS explores all vertices at distance i before exploring any vertex at distance i + 1.

This is not accidental. It is enforced by the queue.

The Queue Discipline


BFS uses a queue.

Queue = First In, First Out (FIFO).

  • Vertices are enqueued when discovered.
  • Vertices are dequeued in the same order they were inserted.

This simple rule forces the algorithm to respect layers.

The Wavefront Interpretation


Think of BFS as a wave expanding from s.

At step i:

  • All vertices in Li are processed.
  • Their undiscovered neighbors become Li+1.

The frontier between explored and unexplored vertices is called the wavefront.

This interpretation explains both correctness and optimality.

Engineering Interpretation


Why this works:

  • Edges all have equal weight (unweighted graph).
  • Distance is measured by edge count.
  • FIFO ordering preserves shortest distance first.

Therefore:

d[v] = δ(s, v)

for every reachable vertex v.

Conclusion: BFS is a shortest-path algorithm for unweighted graphs.

Conceptual Summary


The essence of BFS:

BFS = Layered geometry + FIFO discipline + Wavefront expansion

It is not traversal by chance. It is traversal by metric structure.

Next: Part 3 — The Algorithm (CLRS Pseudocode)

Now that we understand the core idea behind BFS — layers and the FIFO queue — we move to the formal structure. In Part 3, we present the classical CLRS pseudocode and define the precise state maintained for each vertex.