Tutorials Books Videos Forums

Change the theme! Search!
Rambo ftw!

Customize Theme


Color

Background


Done

DFS and BFS Lab

by kirupa   |   filed under Data Structures and Algorithms

This lab will allow you to test your knowledge of what you saw earlier in Depth-First Search (DFS) and Breadth-First Search (BFS) with practical examples. The default graph mirrors the article's A-through-H example, starts at node A, and looks for a path to node F. Generate unweighted node networks, switch between DFS and BFS, and step through how each traversal decides which node to explore next.

DFS and BFS Graph Lab

Select or drag nodes. Traversal is ready.

0 nodes
0 edges
0 steps

DFS: A to F

Generate a graph or find a path to begin.

0 / 0

Tip: drag nodes to rearrange the graph. Use Customize to generate graphs, add nodes, connect edges, and choose the start and target nodes.

Customize Graph

Generate a fresh graph, edit nodes and edges, or choose how the next traversal begins.

Node Generator

Custom Editing

Use these controls when you want to create a graph with its own little personality.

Traversal

Path Search Steps

Step What Happened

Path Result

No run yet.

Search Notes

Node Discovered From Visit Order Status

What to Look For

DFS and BFS can both search the same connected graph, but they make different choices about the next node to visit. DFS treats the discovered list like a stack by putting newly found nodes at the front. BFS treats it like a queue by putting newly found nodes at the back.

The initial graph matches the article example, but this lab gives it a concrete goal: find a path from A to F. BFS will find the fewest-edge path, while DFS may find a perfectly valid path that depends more heavily on the order neighbors are discovered.

If you need a quick refresher, revisit the Depth-First Search (DFS) and Breadth-First Search (BFS) walkthrough and then come back here to compare the two approaches step by step.

Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence, ads, and algorithm-driven doodads. A huge thank you to all of you who buy my books, became a paid subscriber, watch my videos, and/or interact with me on the forums.

Your support keeps this site going! 😇

Kirupa's signature!

The KIRUPA Newsletter

Thought provoking content that lives at the intersection of design 🎨, development 🤖, and business 💰 - delivered weekly to over a bazillion subscribers!

SUBSCRIBE NOW

Creating engaging and entertaining content for designers and developers since 1998.

Follow:

Popular

Loose Ends

:: Copyright KIRUPA 2026 //--