Data structures 图的直径算法

Data structures 图的直径算法,data-structures,graph,breadth-first-search,Data Structures,Graph,Breadth First Search,我听说过使用以下算法查找图的直径的算法: Algorithm (start_vertex): 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:

我听说过使用以下算法查找图的直径的算法:

Algorithm (start_vertex):
    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;
    return ans;
以下算法多次失败:例如,当n=7时 我们可以绘制以下图表:

1 2
1 3
2 4
3 4
2 6
2 7
4 5
当start_vertex=1时,该算法给出的最短路径为3,但答案为4。
有人能给出这个算法失败的一般情况吗?请告诉我这是否适用于n=8,其中n是图的顶点数。否在这种情况下答案应该是3。。这里没有失败