I'm using Prim's algorithm from NGenerics to find the minimum spanning tree that connects some vertexes. That's like searching for a MST on a graph in which every vertex is connected to every other vertex, which means there's more edges than vertexes and I should be using Prim's algorithm (rather than Kruskal's). Prim's algorithm, if properly implemented, has O(|E| + |V| log |V|) time complexity. Since NGenerics is a well known library, it probably has the best possible implementation of Prim's algorithm, or at least one that's better than O(|V|^2).
However, there's a problem:
If I want to use the NGenerics library I have to add all the edges of my graph to the NGenerics graph data structure. Something like this (this is pseudocode):
for i = 0 to |V| - 1
for j = i + 1 to |V| - 1
graph.Add(new Edge(vertices[i], vertices[j])
However, that part of the code obviously has O(|V|^2) time complexity, which kind of beats the purpose of using a library which has a better implementation of the algorithm. Well, not really, because the constants make a difference too, but it's still frustrating that my algorithm is now O(|V|^2).
Anyway, am I missing something over here? Can I make this work in O(|E| + |V| log |V|)?