0 votes
139 views
in Analysis of Algorithm by (98.9k points)
retagged by
differentiates between Prim's Algorithm and Kruskal's Algorithm:

1 Answer

0 votes
by (98.9k points)
selected by
 
Best answer
Prim's Algorithm Kruskal's Algorithm
A greedy algorithm that finds the minimum spanning tree (MST) of a weighted undirected graph. Another greedy algorithm that also finds the minimum spanning tree of a weighted undirected graph.
Starts with a single vertex and gradually expands the tree by adding the cheapest edge that connects the tree to a new vertex until all vertices are in the tree. Sorts all the edges in non-decreasing order of their weights and then gradually adds edges to the tree, skipping those that create cycles, until all vertices are in the tree.
Uses a priority queue to keep track of the cheapest edges to add to the tree. Uses a union-find data structure to keep track of which vertices are connected and avoid creating cycles.
Can have different outputs depending on the starting vertex. Always produces the same output regardless of the starting vertex.
Has a time complexity of O(E log V) using a binary heap for the priority queue. Has a time complexity of O(E log E) using a sorting algorithm to sort the edges.
Good for dense graphs (many edges) where E is close to V^2. Good for sparse graphs (few edges) where E is much smaller than V^2.

Related questions

0 votes
1 answer 217 views
0 votes
1 answer 125 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

559 users

...