Graph BFS DFS Visualizer

Paste an edge list, choose a start node, then compare breadth-first and depth-first traversal order on the same graph.

Nodes
7
Edges
7
Visited
0
Components
1

Edge-list input

Use one edge per line. Formats like A B, A,B, or A -> B are accepted.

Traversal

Adjacency list

A: B, C

B: A, D, E

C: A, F

D: B

E: B, F

F: C, E, G

G: F

Undirected graph

Sample graph loaded. Choose BFS or DFS from a start node.

Visited Last
Graph diagramCurrent graph with 7 nodes and 7 edges.ABCDEFG

BFS visit order

Run BFS or DFS to see the traversal order from the selected start node.

Traversal rule

BFS uses a queue and visits neighbors level by level. DFS uses a stack-style walk and follows a branch before backtracking.

Neighbors are visited in alphabetical or numeric order so repeated runs are predictable.

What is a Graph BFS DFS Visualizer?

A graph BFS DFS visualizer draws a graph from an edge list and shows the visit order for breadth-first search or depth-first search. It is useful when learning graph traversal, queues, stacks, connected components, and coding interview problems.

For the full visual learning set, browse the Data Structure Visualizers hub.

How to use this graph traversal tool

  • Paste one edge per line, such as A B.
  • Choose whether the graph is undirected or directed.
  • Enter a start node.
  • Click Run BFS or Run DFS.
  • Compare the highlighted nodes, traversed edges, visit order, and adjacency list.

BFS explores neighbors level by level. DFS follows one path as deeply as possible before backtracking.

BFS vs DFS

Breadth-first search usually uses a queue and is useful for shortest paths in an unweighted graph.

Depth-first search usually uses recursion or a stack and is useful for exploring connected components, cycle checks, and topological-style traversals.

If you need a dependency-safe order for a directed acyclic graph, use the Topological Sort Visualizer. If you are comparing traversal on grids, use the Matrix Traversal Visualizer. If you are comparing traversal output on trees, use the Binary Tree Visualizer. If you need connected components without traversing every query, try the Union Find Visualizer. If you need weighted shortest paths, try the Dijkstra Algorithm Visualizer. If you are comparing ordering algorithms, use the Sorting Algorithm Visualizer.

Frequently Asked Questions

What edge list format should I use?
Use one edge per line with two node labels, for example A B. Commas and arrows such as A -> B are also accepted.
Can I visualize a directed graph?
Yes. Turn on directed mode and the tool will only add each edge in the direction you entered.
Why do BFS and DFS produce different orders?
BFS visits all immediate neighbors before going deeper. DFS goes deeper along one branch before returning to other neighbors.
Can labels be numbers instead of letters?
Yes. Node labels can be letters, numbers, or short words.

Related tools