Zeitkomplexität von Prims MST-Algorithmus ist O(|V|^2)
, wenn Sie Adjazenzmatrix-Darstellung verwenden.Prims MST-Algorithmus in O (| V |^2)
Ich versuche Prim-Algorithmus mit Adjazenz-Matrix zu implementieren. Ich verwende this als Referenz.
V = {1,2...,n}
U = {1}
T = NULL
while V != U:
/*
Now this implementation means that
I find lowest cost edge in O(n).
How do I do that using adjacency list?
*/
let (u, v) be the lowest cost edge
such that u is in U and v is in V - U;
T = T + {(u,v)}
U = U + {v}
EDIT:
- Ich verstehe Prim-Algorithmus sehr gut.
- Ich weiß, wie man es effizient mit Heaps und Prioritätswarteschlangen implementieren.
- Ich kenne auch bessere Algorithmen.
- Ich möchte Adjazenzmatrix-Darstellung des Graphen verwenden und O (| V |^2) Implementierung erhalten.
Ich will die ineffiziente IMPLEMENTATION
Hier ist V^2 Implementierung gegen Ende der Seite http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/GraphAlgor/primAlgor.htm – Ankush