Math & science

Graph Algorithm Visualizer

BFS, DFS, Dijkstra, Bellman–Ford, A*, MST, topological sort and SCCs on your edge list.

Formats: "A B 4", "A -> B 4", "A,B,4". A line with one name adds an isolated node. # starts a comment. Max 200 nodes, 2,000 edges.

Default: the first node. Used by BFS, DFS, Dijkstra, Bellman–Ford, A* and Prim.

Optional for searches; required for A*.

A* uses the straight-line distance as heuristic; it is admissible only if no edge is shorter than the distance between its end points.

Try an example: Dijkstra from A to F · Kruskal MST · Topological sort of build steps · Bellman–Ford with a negative edge · A* on a grid · Strongly connected components

How it works

Paste an edge list (weighted or not, directed or not) and run a classic graph algorithm: BFS, DFS, Dijkstra, Bellman–Ford (with negative-cycle detection), A* with node coordinates, Prim or Kruskal minimum spanning tree, Kahn topological sort or Tarjan strongly connected components. Shows every step, the distances and the highlighted path or tree.

  • Neighbours are visited in the order nodes first appear in your edge list, so every run is deterministic. Undirected edges are usable in both directions.
  • BFS finds fewest-edge paths; DFS records discovery and finish times. Dijkstra settles nodes in order of distance with a binary heap and refuses negative weights; Bellman–Ford relaxes all edges up to n − 1 times and then checks for a negative cycle.
  • A* is Dijkstra ordered by g + h with h = straight-line distance between coordinates. It returns optimal paths when h never overestimates (admissible) and is consistent; the tool warns when an edge is shorter than its straight-line length.
  • Prim grows a tree from the start node (a forest if the graph is disconnected); Kruskal adds the cheapest edges that do not close a cycle (union–find). Kahn's algorithm outputs nodes without remaining incoming edges and detects cycles; Tarjan's algorithm finds strongly connected components in one DFS.

Sources

  • Cormen, Leiserson, Rivest, Stein: Introduction to Algorithms, 4th ed. (2022), chapters 20–23 (MIT Press)
  • Hart, Nilsson, Raphael (1968): A Formal Basis for the Heuristic Determination of Minimum Cost Paths (IEEE Trans. SSC 4(2))

For scripts and AI agents

  • JSON API: POST https://graphalgorithmvisualizer.usefulweb.site/api/v1/calculate (same calculation as this page)
  • Interface description: OpenAPI 3.1 · AI guide: llms.txt
  • MCP server (Streamable HTTP): https://graphalgorithmvisualizer.usefulweb.site/mcp · tool name graph_algorithm_visualizer
Example request
curl -s -X POST https://graphalgorithmvisualizer.usefulweb.site/api/v1/calculate \
  -H 'content-type: application/json' \
  -d '{"algorithm":"dijkstra","source":"A","target":"F"}'

Related tools

Feedback