# Is it possible that the diameter of a graph be shorter than the longest shortest path?

I used networkx to find the diameter of a graph that I have. It gave a diameter of 4. However, I found that between two particular nodes, using networkx's shortest path function, the path length is 5. I also coded dijkstra's algorithm and BFS from scratch and both returned a shortest path length of 5 too.

Is anything wrong with this? Isn't the diameter of a graph the longest shortest path?

This is what I'm using: http://vlado.fmf.uni-lj.si/pub/networks/data/Erdos/Erdos02.net

• Perhaps you're confusing the number of vertices in the shortest path with the length of the path? If the shortest path contains 5 vertices, then the path length (and distance) between those vertices is 4 – Ariel Apr 7 '17 at 15:51
• Ah, that was so dumb of me, I didn't even think about that. Thank you! – User1915 Apr 7 '17 at 16:15

$$\mathrm{diam}(G) = \max_{x,y\in V(G)} \min\, \{\mathrm{len}(P)\mid P\text{ is a path from }x\text{ to }y\}\,.$$