I'm trying to apply Prim's or Kruskal's algorithms to certain situations. I understand that Prim is used when graphs are dense (Example: as adjacency matrix with priority queue as unordered array would be good for a dense tree where E = O(V^2)
. And Kruskal is used when graphs are sparse (Example: as adjacency list with fast sort where E = O(V)
. What I'm unsure about is the in between. For example, a graph with a moderate number of edges such that
E = O(V log V)
Would this be Prim or Kruskal? I think it may be either one because Prim O(E log V)
and Kruskal O(E log E)
have similar time complexities.