DEV Community

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

Posted on

1

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.

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay