I have heard of algorithm of finding diameter of graph using the following algorithm:
find out the set of vertices S having maximum value of
shortest distance from start_vertex.
ans = 0;
for each vertex v in S
temp = 0;
for each vertex u in graph G:
temp = max(temp, shortest distance between u and v).
ans = temp;
The following algorithm fails several times: for example when n=7
we can draw the following graph:
With start_vertex=1 ,this algorithm gives shortest path as 3 but the answer is 4.
Can someone give the general case when does this algorithm fails.Also tell me whether this will work for n=8 where n is the no of vertices of the graph