Skip to content
doubtly

1 answer

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.
Doubtly · 3 May 2023 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.