Skip to content

Resource · Guide or article

Breadth-First Search (BFS)

One-paragraph definition of breadth-first search on trees and graphs: begin at the root or a chosen node and visit every neighbor before going a level deeper.

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 Graphs.

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, 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

  • Level-by-level exploration order, with an animated visualization
  • Reference links on tree traversals, BFS versus DFS on binary trees and an interactive BFS visualizer

How to use it

PrepKit study advice, not a claim made by the source.

Implement BFS with a queue over an adjacency list, return the visit order and each node's distance from the start, and compare your result with the linked visualizer on the same graph.

Scope and limitations

Very thin: no pseudocode, complexity, queue explanation or uses such as shortest paths in unweighted graphs. Most of the substance sits behind external links.

Access and format

Free English README on GitHub in the MIT-licensed trekhleb/javascript-algorithms repository.

Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88

Evidence behind this overview
  • src/algorithms/graph/breadth-first-search/README.md

Related preparation

These are PrepKit study suggestions, not employer endorsements or predictions of interview questions.

Pages that include this

Get the PrepKit newsletter

Optional. You don't need it to use PrepKit.

How we handle your email