How to Create a Graph Online from an Adjacency Matrix and Find the Shortest Path
Updated
Paste a comma-separated square matrix into the "Using adjacency matrix" entry of Graph Online, and the tool draws the graph for you; from there you can run "Find shortest path" and other algorithms. This works when your matrix is square, uses commas as separators, and each row/column corresponds to one vertex. If the matrix is not square or uses another separator, the tool rejects it and offers a "fix matrix" or "help" option instead of building the graph.
What the adjacency matrix encodes
In this tool, an adjacency matrix is a square grid where both rows and columns represent vertices. The value at row i, column j describes the edge between vertex i and vertex j.
- A non-zero value means an edge exists; the value itself is used as the edge weight.
- A zero (or empty) value means no edge.
- For a multigraph, the matrix stores the weight of the minimum edge between two vertices, so parallel edges are collapsed to the smallest weight.
Because rows and columns must line up, the matrix has to be square. A 4×4 matrix describes 4 vertices; a 4×3 matrix is invalid.
Step-by-step: build the graph and run an algorithm
- Open the site and choose Using adjacency matrix as the input method.
- Type or paste your matrix into the input field, using commas as the separator. Each row goes on its own line.
- Confirm the matrix is square (same number of values in every row, and as many rows as columns).
- Submit it to create the graph. On success the workspace shows the vertices and edges, and you can save the graph, export it to a file, or save it as an image/SVG.
- Select Find shortest path (or another algorithm from the Algorithms menu) and run it on the generated graph.
Expected result: after a valid paste, the graph appears in the workspace with the vertices and weighted edges you described, and the algorithm returns its result on that graph.
Handling matrix errors
If the format is wrong, the tool does not create the graph. It shows a message such as "Cannot create graph. Adjacency Matrix has wrong format" and offers a fix matrix button or a help button explaining the expected format. The generic error "Matrix is incorrect. Use comma "," as separator" points to one of two common causes:
| Symptom | Likely cause | Fix |
|---|---|---|
| "Matrix should be square" | Row count ≠ column count | Add or remove values so every row has the same length as the number of rows |
| "Use comma "," as separator" | Spaces, tabs, or semicolons used instead of commas | Replace separators with commas |
| Wrong format, fix offered | Mixed row lengths or stray characters | Use fix matrix, or correct the rows manually |
After fixing, resubmit the matrix and check that the drawn graph matches your intended vertices and edges before running an algorithm.
Limits and things to know before you start
- The tool warns when a graph is too large for a given algorithm, reporting the vertex and edge counts and the maximum size that algorithm supports. If you hit this, the graph itself may still be valid — only that algorithm is out of range.
- The workspace supports zoom, moving, and styling, so you can verify a large matrix visually before running anything.
- Graph Online also accepts incidence matrices and edge lists, so if your data is not naturally a square matrix, one of those entry methods may fit better.
Once the graph is on screen and matches your matrix, running "Find shortest path" is a single selection — the matrix is the only input you need to get right.