Resource · Guide or article
Breadth-First Search (BFS)
Explains level-order traversal: BFS visits a node's neighbors before moving down to the next level, shown here on a binary tree.
Reviewed
Open the original: Breadth-First Search (BFS) (opens the original site in a new tab)Practice this topicOpens the practice interviewer with a question on Trees.
Add to a roadmap
Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.
Source content: English
Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data structures. It starts at the tree root (or some arbitrary node of a graph, sometimes referred to as a 'search key') and explores the neighbor nodes first, before moving to the next level neighbors.
PrepKit overview
PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.
- Suited to
- The source does not state a level
- Format
- Reference
What it covers
- One-paragraph definition for trees and graphs, with an animated visualization
- Queue-based pseudocode that visits left then right children
How to use it
PrepKit study advice, not a claim made by the source.
Turn the pseudocode into code that returns nodes grouped by level, a common follow-up, and test it on an unbalanced tree.
Scope and limitations
The pseudocode as recorded writes the null checks as 'root = ø' where a not-equal test is meant, so read it carefully. There is no complexity or graph-specific version.
Access and format
Short README on GitHub, trekhleb/javascript-algorithms (MIT). English, free.
Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88
Evidence behind this overview
- src/algorithms/tree/breadth-first-search/README.md
Pages that include this
Get the PrepKit newsletter
Optional. You don't need it to use PrepKit.