Skip to content

Concept module

Breadth-First Search and Layered Frontiers

Keep the queue frontier, visited count, and graph layers visible together so breadth-first search reads as a layered process instead of a procedure list.

The simulation shows one labeled graph with the current node, the queue frontier, and the visited nodes colored differently so the BFS layers stay readable. A readout card reports the traversal mode, current node, frontier size, visited count, and target, while a cue panel shows the frontier order and the current neighbor list. Breadth-first search is running on the layered campus graph from A toward H. The start node is waiting on the frontier. The frontier currently holds 1 node, and 0 nodes have already been visited.

Interactive lab

Graph traversal bench

Keep one live graph, the current frontier, and the visited state visible together so breadth-first and depth-first search read like different process choices on the same structure.

Live graphBreadth-first search on layered campusQueue frontierAstartBCDEFGHtargetTraversal readoutLivemodeBreadth-first searchgraphLayered campuscurrentreadyfrontier1visited0targetHTraversal readyThe queue frontier starts with the start node, then expands outward layer by layer.Queue frontier keeps the next candidates visible while visited state prevents repeat work.Traversal cuesQueue frontierAStart neighborhoodB, C

Controls

Layered campus
A
H
BFS

More tools

Secondary controls, alternate presets, and less-used toggles stay nearby without crowding the main bench.

Show

More presets

Presets

Time

0.00 s / 20.3 sLivePause to inspect a specific moment, then step or scrub through it.
0.00 s20.3 s

Predict -> manipulate -> observe

Keep the active prompt next to the controls so each change has an immediate visible consequence.

ObservationPrompt 1 of 2
Breadth-first search settles the shallow layer before it lets the graph dive into deeper branches.

Graphs

Switch graph views without breaking the live stage and time link.

Visited nodes versus frontier size

Watch how many nodes have already been expanded while the waiting frontier grows or shrinks.

step: -1.62 to 21.9nodes: -0.64 to 8.64
visited nodesfrontier size
Visited nodes versus frontier sizeWatch how many nodes have already been expanded while the waiting frontier grows or shrinks.-1.624.2610.1416.0221.9-0.641.6846.328.64stepnodes
Hover or scrub to link the graph back to the stage.step / nodes

Equation map

See each variable before you move it.

Select a symbol to highlight the matching control and the graph or overlay it most directly changes.

Graph layout
0

Switches among the bounded graph scenes on the same traversal bench.

Graph: Visited nodes versus frontier sizeGraph: Current depth versus deepest claimed depthOverlay: Adjacency cueOverlay: Visited cue

Equations in play

Choose an equation to sync the active symbol, control highlight, and related graph mapping.

More tools

Detailed noticing prompts, guided overlays, and challenge tasks stay available without taking over the main bench.

Hide

What to notice

Keep the graph and one traversal graph visible together.

ObservationPrompt 1 of 2
Graph: Visited nodes versus frontier size
Breadth-first search settles the shallow layer before it lets the graph dive into deeper branches.
Control: Start nodeControl: Traversal modeGraph: Current depth versus deepest claimed depthGraph: Visited nodes versus frontier sizeOverlay: Frontier cueOverlay: Visited cueEquationEquation

Guided overlays

Focus one overlay at a time to see what it represents and what to notice in the live motion.

3 visible

Overlay focus

Adjacency cue

Keep the current node's neighbor list visible.

What to notice

  • The local neighborhood is the input that every BFS layer grows from.

Why it matters

It keeps breadth-first search tied to real graph structure instead of to a slogan about breadth.

Control: GraphControl: Start nodeGraph: Current depth versus deepest claimed depthEquationEquation
Breadth-first search is running on the layered campus graph from A toward H. The start node is waiting on the frontier. The frontier currently holds 1 node, and 0 nodes have already been visited.
Equation detailsDeeper interpretation, notes, and worked variable context.

Layer depth rule

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

Graph layout 0 Start node 0 Target node 7

Queue frontier update

Breadth-first search removes the oldest frontier node, then adds its new neighbors to the back.

Start node 0 Traversal mode 0

Progress

Not startedMastery: NewLocal-first

Start exploring and Open Model Lab will keep this concept's progress on this browser first. No finished quick test, solved challenge, or completion mark is saved yet.

Let the live model runChange one real controlOpen What to notice

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

Premium keeps named exact-state study setups in your account while stable concept links stay public below.

Checking saved setup access.

This concept can keep using stable links while the saved-setups capability resolves for this browser.

Copy current setup

Stable concept and section links stay public below while exact-state setup sharing stays behind premium.

Stable links

Starter track

Step 4 of 60 / 6 complete

Algorithms and Search Foundations

Earlier steps still set up Breadth-First Search and Layered Frontiers.

1. Sorting and Algorithmic Trade-offs2. Binary Search / Halving the Search Space3. Graph Representation and Adjacency Intuition4. Breadth-First Search and Layered Frontiers+2 more steps

Previous step: Graph Representation and Adjacency Intuition.

Short explanation

What the system is doing

Breadth-first search keeps the frontier organized like a queue. The oldest claimed node gets expanded next, so the search spreads outward in visible layers instead of diving down one branch immediately.

On this bench the graph, the queue frontier, and the visited count stay coupled. That makes the layered shape of BFS honest: nearby nodes get settled first because the queue keeps earlier discoveries ahead of later ones.

Key ideas

01Breadth-first search expands the oldest waiting node first.
02On an unweighted graph, breadth-first layers match the fewest-edge distance from the start.
03The queue frontier grows when a node discovers new neighbors and shrinks when those waiting nodes get expanded.

Worked example

Read the full frozen walkthrough.

Frozen walkthrough
Read the queue frontier directly from the layered-campus bench.

Live worked examples are available on Premium. You can still read the full frozen walkthrough on the free tier.

View plans
Frozen valuesUsing frozen parameters

On the layered campus graph, what should BFS settle first from A?

Graph layout

Layered campus

Start node

A

Queue frontier

B then C

1. Read the first layer

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. Read what that means

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

BFS layer read

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.

Common misconception

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

The important rule is not the drawing. The important rule is that the oldest claimed node leaves the frontier next.

That queue rule is what makes BFS settle the graph layer by layer.

Mini challenge

Build a BFS case where the frontier gets wide before the target is reached.

Prediction prompt

Decide whether you need an edge start or a hub start before you switch presets.

Check your reasoning

Use a hub-like start so BFS can claim several same-depth neighbors before it narrows again.
Breadth-first search widens fastest when one node has several direct neighbors at the same shallow depth.

Quick test

Reasoning

Question 1 of 2

Answer from the visible queue and depth pattern, not from memorized acronyms.

Why does BFS discover shallow nodes before deeper ones on this bench?

Choose one answer to reveal feedback, then test the idea in the live system if a guided example is available.

Accessible description

The simulation shows one labeled graph with the current node, the queue frontier, and the visited nodes colored differently so the BFS layers stay readable.

A readout card reports the traversal mode, current node, frontier size, visited count, and target, while a cue panel shows the frontier order and the current neighbor list.

Graph summary

One graph tracks visited nodes against frontier size, a second tracks current depth against the deepest claimed depth, and a third compares new discoveries with repeat skips.

Together they show how breadth-first search widens and then settles the graph layer by layer.