logo
SEE ALGORITHMS
    Bubble Sort
    Insertion Sort
    Selection Sort
    Heap Sort
    Radix Sort
    Merge Sort
    Quick Sort

Breadth First Search

Breadth-First Search (BFS) explores a graph much like finding connections in a social network. Starting from a source node, it first visits all of its direct friends (neighbors), then all of their friends, and so on, level by level. It uses a queue to keep track of who to visit next, ensuring it doesn't go too deep down one path. This makes it perfect for finding the shortest path in an unweighted graph.

Pseudocode

queue = new Queue()
queue.enq(src)
mark src as visited
while queue is not empty:
    u = queue.deq()
    for each neighbor v of u:
        if v is not visited:
            queue.enq(v)
            mark v as visited
Draw Graph

Curious to Learn More?

Hand-picked resources to deepen your understanding

Beginner Friendly
Coding Interview Bootcamp: Algorithms + Data Structures

Learn essential data structures and algorithms step-by-step with practical JavaScript examples.

Practical Guide
JavaScript Algorithms & Data Structures Masterclass

Master DSA fundamentals, problem-solving techniques, and advanced structures using JavaScript.

Deep Dive
Master the Coding Interview: Data Structures + Algorithms

Prepare for top tech interviews with advanced DSA concepts and real-world coding challenges.

As an Udemy Associate, I earn from qualifying purchases. This helps support the site at no extra cost to you.

© 2025 SEE Algorithms. Code licensed under MIT, content under CC BY-NC 4.0.