HiveBrain v1.2.0
Get Started
← Back to all entries
patternMajor

The time complexity of finding the diameter of a graph

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
thegraphtimediameterfindingcomplexity

Problem

What is the time complexity of finding the diameter of a graph
$G=(V,E)$?



  • ${O}(|V|^2)$



  • ${O}(|V|^2+|V| \cdot |E|)$



  • ${O}(|V|^2\cdot |E|)$



  • ${O}(|V|\cdot |E|^2)$




The diameter of a graph $G$ is the maximum of the set of shortest path distances between all pairs of vertices in a graph.

I have no idea what to do about it, I need a complete analysis on how to solve a problem like this.

Solution

I assume you mean the diameter of $G$ which is the longest shortest path found in $G$.

Finding the diameter can be done by finding all pair shortest paths first and determining the maximum length found. Floyd-Warshall algorithm does this in $\Theta(|V|^3)$ time. Johnson's algorithm can be implemented to achieve $\cal{O}(|V|^2\log |V| + |V|\cdot|E|)$ time.

A smaller worst-case runtime bound seems hard to achieve as there are $\cal{O}(|V|^2)$ distances to consider and calculating those distance in sublinear (amortised) time each is going to be tough; see here for a related bound. Note this paper which uses a different approach and obtains a (slightly) faster algorithm.

Context

StackExchange Computer Science Q#194, answer score: 34

Revisions (0)

No revisions yet.