Graph Algorithms Visualizer

Type an edge list and see shortest paths, BFS, DFS, topological order or a spanning tree.

Result

Examples

Algorithms

Questions

How do I type a graph?

One edge per line: "A B" joins A and B, "A B 4" gives the edge a weight of 4, and "A -> B" makes it one way. A name on its own adds a node with no edges. Anything after # is a comment.

When should I use BFS or DFS?

Breadth-first visits nodes in order of how many edges away they are, so it finds the fewest hops. Depth-first follows one branch as far as it goes before backing up, which suits cycle checks and topological order.

What is a topological sort?

An order of the nodes where every arrow points forward, like build steps where each one comes after what it depends on. It only exists for a directed graph with no cycles, and the tool says so if there is a cycle.

What is a minimum spanning tree?

The cheapest set of edges that still connects every node, with no loops. Think of the least cable needed to link some buildings. The tool uses Kruskal's algorithm. If the graph falls apart into pieces, you get one tree per piece.

Why does Dijkstra warn about negative weights?

Dijkstra assumes a path never gets cheaper by adding an edge. A negative weight breaks that, so its answer may not be the shortest. Bellman-Ford handles negative weights.