I want to calculate the diameter of a graph with 5 vertices. How can I do that? For example if I have a graph with 5 vertices and 8 edges.
-
1Find the shortest distance between each pair of vertices. The longest of these is the diameter: https://stackoverflow.com/questions/3174569/what-is-meant-by-diameter-of-a-network – Nick is tired Jun 23 '18 at 09:44
1 Answers
As said in Wiki:
To find the diameter of a graph, first find the shortest path between each pair of vertices. The greatest length of any of these paths is the diameter of the graph
Regarding your question about G having 5 node and 8 vertices:
Let assume each edge is weighted 1. Notice that the max |E| for DAG is |V|*(|V|-1) /2 -> so in your case is 10 (5*4/2). If you had 10 edges in your graph the diameter was 1 (the shortest path between each pair was 1 because each node connected to all others). In your case there are 8 edge so they 2 vertices that not connected directly -> which make the diameter minimum 2.
Let look at the Complete graph for 5 nodes with the 10 edges:
Note that in order to increase the path between 2 nodes let first remove their connected edge. However, between 2 node in that graph we have 3 more path with distance of 2. So if you remove 2 edges you will still have 2 path with distance of 2 -> the diameter for G(V,E) when |V|=5 and |E|=8 is 2

- 11,597
- 3
- 24
- 39