# Graph Algorithm Visualizer - Shortest Path, MST, Max Flow

> Draw a graph, step through BFS, DFS, Dijkstra, Bellman-Ford, Floyd–Warshall, Prim, Kruskal, topological sort, SCCs, bipartite check, Euler paths and max flow.

- URL: https://qilingtools.com/en/math/graph-theory
- Category: Math Tools (https://qilingtools.com/en/math)
- Tags: [Math](https://qilingtools.com/en/tags/math), [Education](https://qilingtools.com/en/tags/education), [Charts & Visualization](https://qilingtools.com/en/tags/chart), [Algorithms](https://qilingtools.com/en/tags/algorithm)
- Last updated: 2026-10-26
- Price: Free, no sign-up
- Privacy: Runs locally in the browser; files are never uploaded

Click the canvas to add vertices, drag from one vertex to another to add an edge, click an edge to change its weight, and switch between directed and undirected graphs — or paste an edge list (“from to weight” per line) and let the tool lay it out. Pick an algorithm and press Run to watch it step by step: the current vertex, finished vertices, vertices waiting in the queue, chosen edges and rejected edges each get their own colour, every step is explained in words, and you can play, change speed or step back and forth. It covers breadth-first and depth-first search (with discovery/finish times), Dijkstra’s shortest paths, Bellman-Ford with negative weights and negative-cycle detection, Floyd–Warshall with the distance matrix after each intermediate vertex, Prim’s and Kruskal’s minimum spanning trees, Kahn’s topological sort (showing the actual cycle when there is one), connected components and Tarjan’s strongly connected components, a bipartite check that shows an odd cycle when it fails, Euler paths and circuits with Hierholzer’s algorithm, and Edmonds–Karp maximum flow with the minimum cut highlighted. The adjacency matrix updates as you edit, and the drawing exports as PNG or SVG.

## How to use

1. Click to add vertices and drag to connect them, paste an edge list, or load an example graph
2. Choose an algorithm and a start vertex (plus a sink for max flow), then press Run
3. Play or step through the animation, read the result table and export PNG/SVG if needed

## Features

- Visual editing: click to add, drag to connect, edit weights, directed or undirected
- Edge-list import and export, force-directed and circular layouts
- Step-by-step BFS and DFS with discovery/finish times
- Dijkstra, Bellman-Ford with negative-cycle detection, Floyd–Warshall distance matrix
- Prim and Kruskal minimum spanning trees (spanning forest if disconnected)
- Topological sort with cycle detection, connected components, Tarjan SCCs
- Bipartite check with odd-cycle witness, Euler paths and circuits
- Edmonds–Karp max flow and min cut, adjacency matrix, PNG/SVG export

## FAQ

### Should I use Dijkstra or Bellman-Ford?

With non-negative weights use Dijkstra: it repeatedly settles the closest unsettled vertex and is fast. With negative edges Dijkstra can give wrong answers, so use Bellman-Ford, which relaxes every edge n − 1 times; if an n-th pass still shortens a path, there is a negative cycle. Note that in an undirected graph a single negative edge is already a negative cycle.

### Do Prim’s and Kruskal’s algorithms give the same tree?

They always give the same total weight, but when several edges share a weight they may pick different edges, because a minimum spanning tree need not be unique. Kruskal sorts the edges and adds each one that doesn’t close a cycle; Prim grows a tree from one vertex by always adding the cheapest edge leaving it. On a disconnected graph you get a minimum spanning forest.

### How can I tell if a graph has an Euler path?

An undirected graph has an Euler path when all vertices with edges are connected and the number of odd-degree vertices is 0 or 2. With 0 there is an Euler circuit that returns to the start; with 2 the path must start at one odd vertex and end at the other. A directed graph needs in-degree equal to out-degree everywhere, or exactly one vertex with one extra outgoing edge and one with one extra incoming edge. The tool checks these conditions and then builds the route with Hierholzer’s algorithm.

### How are maximum flow and minimum cut related?

By the max-flow min-cut theorem, the largest flow from source to sink equals the smallest capacity of any cut separating them. Edmonds–Karp repeatedly finds the shortest augmenting path with BFS and pushes its bottleneck until no path remains. The vertices still reachable from the source in the residual network form the set S, and the edges leaving S form the minimum cut — all of them saturated.

## Related tools

- [Graphing Calculator](https://qilingtools.com/en/math/graph): Free online function graphing calculator: type sin(x), x^2 or 1/x and see the curve at once, with several functions, parametric and polar curves, PNG export.
- [Scientific Calculator](https://qilingtools.com/en/math/calculator): Free online scientific calculator: type 2*(3+4)^2, sin(pi/6) or log(8,2) and see the answer as you type, with degrees or radians and a history list.
- [Equation Solver](https://qilingtools.com/en/math/equation): Free online equation solver: enter coefficients for linear, quadratic (with discriminant, vertex and complex roots) and cubic equations, plus 2×2 systems.
- [Fraction Calculator](https://qilingtools.com/en/math/fraction): Free online fraction calculator: add, subtract, multiply and divide fractions with automatic reduction, plus fraction ↔ decimal with repeating digits.
- [Percentage Calculator](https://qilingtools.com/en/math/percentage): Free online percentage calculator: X% of Y, X as a percent of Y, increase and decrease, a value after a percentage change and the original behind it.
- [Prime Factorization](https://qilingtools.com/en/math/prime): Free online prime factorization: factor an integer with exponents, list every divisor and their sum, test primality with neighbouring primes, or list a range.
- [GCD and LCM](https://qilingtools.com/en/math/gcd-lcm): Free online GCD and LCM calculator: works with two or more integers, says whether they are coprime, shows each prime factorization and every Euclidean step.
- [Statistics Calculator](https://qilingtools.com/en/math/statistics): Free online statistics calculator: paste a data set for the mean, median, mode, range, quartiles, variance, standard deviation, standard error and outliers.
