Breadth First Search VS. Depth First Search (with Pictures!)

An illustrated introduction to BFS and DFS through an undirected graph (no prior knowledge necessary).

Kiersten Campbell
Geek Culture

--

Photo by Fletcher Pride on Unsplash

Breadth First Search and Depth First Search are basic search algorithms that represent a simple method to solve a problem. They are a precursor to modern types of search and in my opinion a must know building block for learning artificial intelligence.

If learning artificial intelligence is your overall goal I recommend checking out this great post by Daniel Bourke:

Background

Undirected vs Directed Graph

To be completely honest I was confused when I first heard the terms “undirected graph” and “directed graph”. Before we get into the meat of this article let me clarify:

Image by author, illustration by author.

--

--