When there are directed edges in the graph, as it is impossible to move back from B to A when the edges are directed.
Chat with our AI personalities
dfgbrgffee
Both algorithms have the same efficiency and both are based on the same greedy approach. But Kruskal's algorithm is much easier to implement.
Complexity prim = O(E+ V logV). E edge and V vertex. kurskal = O(E lgV ).
The correctness of either Prim's or Kruskal's algorithm, is not affected by negative edges in the graph. They both work fine with negative edges. The question boils down to "Does a Priority Queue of numbers work with negative numbers?" because of the fact that both Prim's and Kruskal's algorithm use a priority queue. Of course -- as negative numbers are simply numbers smaller than 0. The "<" sign will still work with negative numbers.
First a vertex is selected arbitrarily. on each iteration we expand the tree by simply attaching to it the nearest vertex not in the tree. the algorithm stops after all yhe graph vertices have been included.. one main criteria is the tree should not be cyclic.