data structures - Algorithm for diameter of graph -


i have heard of algorithm of finding diameter of graph using following algorithm:

algorithm (start_vertex):     find out set of vertices s having maximum value of          shortest distance start_vertex.     ans = 0;     each vertex v in s         temp = 0;         each vertex u in graph g:             temp = max(temp, shortest distance between u , v).         ans = temp;     return ans; 

the following algorithm fails several times: example when n=7 can draw following graph:

1 2 1 3 2 4 3 4 2 6 2 7 4 5 

with start_vertex=1 ,this algorithm gives shortest path 3 answer 4. can give general case when algorithm fails.also tell me whether work n=8 n no of vertices of graph

no answer should 3 in case.. doesn't fail here


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -