Graph::eccentricity

Function


int eccentricity(const T& x);

Get eccentricity e of a specified vertex.

Parameters

x is label of specified vertex.

Return value

Return eccentricity of vertex x.

Example

#include "HKUAL_graph.h"
#include <iostream>
using namespace std;
using namespace HKUAL;

int main(){
    Graph<string> g;
    g.addVertex("A");
    g.addVertex("B");
    g.addVertex("C");
    g.addVertex("D");
    g.addEdge("A","B");
    g.addEdge("A","C");
    g.addEdge("B","D");

cout << g.eccentricity("A") << endl;
cout << g.eccentricity("C") << endl;
return 0; }

Output

2
3

Time Complexity

, for is number of edges and is total number of vertices.

© The University of Hong Kong Algorithms Library - hkual@cs.hku.hk