Skip to content

Breadth-First Search and Layered Frontiers

Simulation loading

Open Model Lab is preparing the live lab, controls, and graph surface for this concept.

Wrap-up

What you learned

Recommended next
Open concept testCheck whether the core ideas are ready without leaving this concept.
Read next
Depth-First Search and Backtracking PathsContrast queue order with stack order

Key takeaway

  1. BFS fills the first frontier with same-depth neighbors before it goes deeper.
  2. The queue frontier clears older discoveries first, which is what makes the search layered.
  3. On an unweighted graph, BFS layers line up with fewest-edge distance from the start.

Common misconception

Breadth-first search just means moving around the page in a wide-looking pattern.

The drawing can be misleading. What matters is queue order: the oldest discovered node is expanded next.

  1. Layer depth rule

    A newly discovered neighbor is one edge deeper than the node that found it.

  2. Queue frontier update

    BFS removes the oldest frontier node first, then adds its newly discovered neighbors to the back of the queue.

Why it behaves this way

Explanation

Breadth-first search explores an unweighted graph in layers. From the start node, it first reaches nodes one edge away, then nodes two edges away, and so on.

That layered pattern comes from the queue frontier. The oldest discovered node is expanded next, so shallow discoveries stay ahead of later deeper ones. On this bench, keep the graph, frontier cue, and depth history together so the rule stays visible.

Key ideas

01Breadth-first search reaches nodes in increasing fewest-edge distance from the start.
02The queue frontier expands the oldest waiting node first.
03The frontier can widen before it shrinks because one shallow node may discover several new neighbors.

Worked examples

Worked examples

Open examples when you want to see the same idea walked through step by step.

Frozen walkthrough

Step through the frozen example

Frozen walkthrough
Use the graph, frontier cue, and depth picture together to read what BFS should do first.

Supporter unlocks saved study tools, exact-state sharing, and the richer review surfaces that support this guided flow.

View plans
Frozen valuesUsing frozen parameters

Starting from A on the layered campus graph, which nodes should BFS settle before it goes deeper?

Graph layout

Layered campus

Start node

A

Traversal mode

B then C

1. Read the first frontier

Starting from A, the first neighbors B and C become the first queue frontier.

2. Keep the queue order honest

Because BFS uses a queue frontier, B should leave the frontier before the later discovery C.

3. Connect queue order to layer depth

That oldest-first rule makes the search finish the shallow layer before it moves into deeper nodes like D, E, F, and H.

Layer-order summary

From A, BFS settles the B/C layer before it pushes deeper.
The queue frontier is what turns a graph traversal into a layered search rather than a branch-first dive.

Quick test

Loading saved test state.

Bench tools and share links

Keep stable concept links and exact-state sharing tucked away until you actually need to relaunch or share the bench.

Try this setup

Jump to a named bench state or copy the one you are looking at now. Shared links reopen the same controls, graph, overlays, and compare context.

Saved setups

Saved setups are a Supporter study tool. Stable concept links still work for everyone.

Checking saved setup access

Open Model Lab is resolving whether this bench can save locally, sync to an account, or open Supporter-only compare tools.

Copy current setup

Exact-state sharing is part of Supporter. Stable concept and section links still stay available.

Stable links

Progress and next steps

Keep progress signals, starter-track handoffs, and review prompts available without letting them compete with the live lesson flow.

Progress

Loading progress

Loading saved concept progress for this browser or synced account before showing completion status.