Graph Distance Calculator

Measure shortest paths across graphs with node inputs. Inspect weighted routes, centers, diameters, and radii. Turn raw connections into clear distance insights for decisions.

Use one edge per line. For weighted graphs, enter source target weight. For unweighted graphs, enter source target.

Example Data Table

Edge Weight Meaning
A - B4Distance between A and B equals 4 units.
A - C2Node A connects to C with low cost.
C - D1C to D is the cheapest intermediate step.
D - E3Final leg from D to E adds 3 units.

Formula Used

In graph theory, the distance between two vertices is the minimum total edge cost across all valid paths connecting them.

d(u, v) = min Σ w(e)

For unweighted graphs, each edge has cost 1, so the distance becomes the minimum number of edges:

d(u, v) = min number of edges in a path from u to v

The calculator applies Dijkstra-style relaxation for nonnegative weighted edges. It also builds an all-pairs distance matrix, eccentricity values, graph radius, and graph diameter.

How to Use This Calculator

  1. Enter one edge per line in the edge list box.
  2. Use three values per line for weighted graphs: source, target, weight.
  3. Use two values per line for unweighted graphs: source, target.
  4. Set the source node and target node you want to analyze.
  5. Turn on Directed graph only when edge direction matters.
  6. Press Submit to show the result above the form.
  7. Use the CSV button to export the result table.
  8. Use the PDF button to save the page as a PDF.

Distance Interpretation in Network Analysis

Graph distance converts a collection of nodes and edges into measurable separation. In routing, each value represents either travel cost, transfer count, latency, or dependency depth. A shortest path gives the minimum feasible total among all candidate routes. Raw connectivity alone does not show which sequence is efficient.

Weighted and Unweighted Cases

Unweighted graphs treat every edge as one unit, so the answer is the fewest hops. Weighted graphs assign a cost to each edge, and the answer becomes the smallest total weight. The distinction matters in transport, communication, and process mapping because two-hop routes may still be more expensive than longer low-cost alternatives.

Shortest Path Output and Decision Value

The main result contains the shortest distance, the hop count, and the actual node sequence. Together, these measures support planning decisions. Distance measures resource burden, hops indicate structural complexity, and the route itself shows the exact chain of movement. Professionals compare these outputs when testing redundancy and bottlenecks.

Distance Matrix and Eccentricity Metrics

The all-pairs matrix extends one route calculation to every source-target combination. This reveals which nodes are central and which are remote. Eccentricity records the farthest reachable node from a given vertex. Radius is the smallest eccentricity, while diameter is the largest finite separation observed anywhere in the graph. In operational studies, these measures help rank access quality across the full network.

Practical Data Patterns

Dense graphs often produce multiple competitive routes and smaller diameters. Sparse graphs usually show larger eccentricity and more isolated zones. If disconnected pairs appear, the matrix includes infinite values, signaling that some destinations cannot be reached. That finding is often as important as the shortest path itself during design reviews. Repeated tests with updated weights also reveal how sensitive route quality is to changing conditions.

Why Visualization Improves Review Quality

A plotted network helps analysts verify whether the computed path matches graph structure. When the highlighted route passes through high-value connector nodes, it may indicate dependence on a few critical links. Combining visual structure with matrix data, radius, and diameter creates a stronger professional assessment of accessibility, reach, and overall network efficiency. It also improves communication because technical and nontechnical stakeholders can review the same result without reading a full adjacency table first.

FAQs

What does graph distance mean?

Graph distance is the minimum cost or minimum hop count needed to travel from one node to another through valid edges.

When should I use weighted mode?

Use weighted mode when edges represent different costs such as time, length, price, latency, or resistance instead of equal steps.

Why can the shortest path have more hops?

A route with more edges can still have a lower total weight if each edge is inexpensive compared with a shorter but costlier alternative.

What does an infinite distance indicate?

It means no valid path exists between those two nodes under the current graph structure and direction settings.

What are radius and diameter used for?

Radius helps identify central nodes, while diameter shows the widest finite separation in the graph and summarizes overall spread.

Can this calculator handle negative weights?

No. The current method assumes nonnegative edge weights, so negative values are rejected to keep shortest-path results valid.

Related Calculators

eulerian path calculator

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.