What is the diameter of a graph with just one node?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
For a graph with exactly one node, the diameter is normally 0. The reason is simple: the diameter of a graph is the maximum shortest-path distance between pairs of vertices, and in a one-vertex graph the only relevant distance is the vertex to itself. That distance is zero because no edges need to be traversed.
Start From the Definition
For a graph G, the diameter is usually defined as:
- take every pair of vertices
- compute the shortest-path distance between them
- take the maximum of those distances
In a graph with one vertex v, there is only one meaningful case to consider: v to v.
The shortest path from a node to itself uses zero edges, so:
Therefore the diameter is 0.
Why the Answer Is Not 1
Beginners sometimes wonder whether the diameter could be 1 because there is a node "present" in the graph. But diameter is not counting nodes. It is measuring shortest-path length, typically in edges.
Since you do not traverse any edge to stay at the same node, the distance is zero, not one.
That is the same reason the diagonal entries of a graph distance matrix are zero.
Eccentricity View
Diameter can also be described using eccentricity. The eccentricity of a vertex is the maximum distance from that vertex to any other vertex in the graph.
In the one-node case:
- the only vertex is
v - the farthest reachable vertex from
vis stillv - the distance is
0
So the eccentricity of v is 0, and the diameter, which is the maximum eccentricity, is also 0.
Small Example
Consider the graph:
There is one vertex and no edges.
The only shortest-path value is:
So:
This is the standard answer in graph theory.
What About a Self-Loop
Even if the one-node graph has a self-loop, the distance from the node to itself is still considered 0 because the shortest path is the path of length zero. You are already at the destination before traversing any edge.
That matters because shortest-path definitions look for the minimum-length path, not just any existing cycle.
So the presence of a self-loop does not change the usual diameter answer.
Connectedness and Convention
Diameter questions become trickier for disconnected graphs, because some distances are infinite or undefined depending on the convention being used. But a single-node graph is connected in the ordinary graph-theory sense, so that ambiguity does not arise here.
That is one reason this is a clean base case in proofs and algorithm discussions.
Why This Case Matters
The one-node graph may feel trivial, but it is an important edge case in graph algorithms. If an implementation computes diameter, radius, or eccentricity, it should handle the single-vertex case cleanly.
For example, a BFS-based diameter routine should not return an error or -1 for a graph that clearly has a well-defined diameter of zero.
Edge cases like this matter in:
- graph libraries
- unit tests
- algorithm proofs by induction
- reasoning about base cases in recursive graph procedures
Common Pitfalls
The most common mistake is confusing path length with node count. Diameter is based on shortest-path length, usually counted in edges.
Another issue is overthinking self-loops. A self-loop does not make the shortest distance from a node to itself become 1, because the zero-length path is shorter.
Developers also sometimes import disconnected-graph conventions into the single-node case unnecessarily. For one node, the standard answer is straightforward and finite.
Finally, if you are implementing graph metrics in code, do not forget this base case. It is small, but it is still a real graph.
Summary
- The diameter of a graph with one node is normally
0. - The only shortest-path distance is the node to itself, which is zero.
- Diameter measures edge distance, not the number of vertices.
- A self-loop does not change the answer because the zero-length path is still shortest.
- This is an important base case for graph-theory reasoning and graph algorithms.

