DDSA Solutions

Breadth-First Search

56 problems · 39 with full explanations

3 Easy26 Medium13 Hard
BFS explores nodes level by level, guaranteeing the shortest path in unweighted graphs. Use a Queue<T> and a visited set. Classic applications: shortest path, level-order tree traversal, multi-source distance (e.g., "01 matrix"), and word ladder transformations.

How to practice

To practice Breadth-First Search problems effectively, start with the Easy problems listed below, trace through each solution on paper, then re-implement without looking. When you can recognise the breadth-first search pattern within 30 seconds of reading a new problem, move on to Medium difficulty. Use the related topic pages and our study guide for a structured progression.

Open the full study guide →

Start here (Easy + explained)

All Breadth-First Search problems