DEV Community

Cover image for Breadth-First Search
Nicko Cruz M
Nicko Cruz M

Posted on

Breadth-First Search

This is a submission for DEV Computer Science Challenge v24.06.12: One Byte Explainer.

Explainer

I want to find something in my strange house, that has n-floors. I must check all the rooms on the curr floor if I find it then I'm done. If I don't find it in any of the rooms on that floor then, AND ONLY THEN, will I go down to the next floor.

Additional Context

This is my attempt to explain BFS using the strange house that is (n) stories tall to act as a representation of the tree data structure. The given example is meant to emphasize the BREADTH in breadth-first search.

When studying algorithms in college it is obvious, in hindsight, the differences between DFS and BFS. However, during undergraduate studies, it is easy for the obvious to become obscured.

With this in mind, I wanted to focus on what makes the Breadth-first approach different from other approaches, which is the fact that this algorithm searches all nodes at the current depth, before traversing nodes at a deeper levels.

Top comments (0)