How to use the Graph BFS DFS Visualizer
- 1. Type the edgesOne per line, like A-B. Tick directed if A-B means A → B.
- 2. Pick BFS or DFSAnd the node to start from.
- 3. Step throughSee the current node, visited nodes and the queue or stack.
BFS vs DFS
- Breadth-first search uses a queue. It visits the start node, then all its neighbours, then their neighbours, level by level. On an unweighted graph it finds the path with the fewest edges, so it's used for shortest paths, social network "degrees of separation" and web crawlers.
- Depth-first search uses a stack (or recursion). It goes as deep as it can along one branch before backing up. It's used for cycle detection, topological sort, finding connected components and solving mazes.
Both run in O(V + E) time. Neighbours are taken in alphabetical or numeric order, the usual textbook convention, so your answer matches the one in the book. In the drawing, the current node is orange, discovered nodes are yellow and finished ones are green, each labelled with its visit number.
Worked example
The sample graph has edges A-B, A-C, B-D, B-E, C-F and E-F. From A:
- BFS: A → B → C → D → E → F. A's neighbours B and C go in the queue; then B adds D and E; then C adds F. Distances in edges from A: B and C are 1, D, E and F are 2.
- DFS: A → B → D → E → F → C. From B it dives to D, backs up, goes to E, then F, and only then reaches C through F.
Tick Directed graph and the same edges become one-way, so some nodes may become unreachable; the summary lists any the search couldn't reach. The adjacency list is shown too, which helps when you're turning a drawn graph into code.
Frequently asked questions
Which DFS order does it use?
The iterative stack version that visits neighbours in sorted order, which gives the same order as the usual recursive DFS.
Can I use numbers as node names?
Yes, like 1-2. They're sorted numerically.
How big can the graph be?
Up to 26 nodes, so the circle drawing stays readable.
Is the graph bfs dfs visualizer free to use?
Yes, the graph bfs dfs visualizer is free and costs nothing. Your first traversal shows a short form for your name and WhatsApp number one time; once that's done, this tool and every other Uncodemy tool open with no form.