Prim’s Algorithm
course Algorithmics
last review @April 2, 2023
mastery rookie
assignment
progress not started
Weight
Files
date
due date
notes
days left
Prim’s algorithm:
It is a greedy algorithm that finds the minimum spanning tree for weighted undirected
trees it turns a cyclic graph into a minimum spanning tree. it finds a subset of the
edges which connect every node where the total weight of all the edges in the tree is
minimised. Kruskal’s algorithm can find a minimum spanning forest, whilst prims only
finds the minimum spanning tree.
Here are the corrected steps for Prim's algorithm:
1. Initialise the minimum spanning tree with an arbitrary node.
2. Find the edge with the minimum weight connecting a vertex in the minimum
spanning tree and a vertex not in the minimum spanning tree.
3. Add the selected edge and the new vertex to the minimum spanning tree.
4. Repeat steps 2 and 3 until all vertices are in the minimum spanning tree.
Prim’s Algorithm 1
, Note that there is no bias for a shorter path from the first node if two edges
connecting the same vertex in the graph one of them is randomly selected. The
algorithm finds the minimum weight tree that connects all vertices in a graph and has
no concern for the starting point and ending point; all nodes are treated equally.
Time Complexity:
The time complexity of Prim's algorithm depends on the data structure used to
represent the graph and the method used to order the edge weights. Typically, a
priority queue is used to order the edges by weight. The time complexity of the
algorithm is O(E log V), where E is the number of edges and V is the number of
vertices in the graph. This is because the algorithm needs to visit every edge in the
graph and perform a constant amount of work for each edge. In addition to this, the
priority queue operations take O(log E) time, which is dominated by the O(E log V)
term. Therefore, Prim's algorithm is efficient for dense graphs and can handle graphs
with many edges. However, for sparse graphs, a different algorithm such as
Kruskal's algorithm may be more efficient.
Facts and Stats:
1. Prim's algorithm finds minimum spanning trees in weighted graphs.
2. It starts with a single vertex and adds edges gradually.
3. The algorithm is greedy, selecting the cheapest edge at each step.
4. It guarantees to find the optimal solution for connected graphs.
5. The time complexity is O(E log V) using a priority queue.
6. It was developed by Czech mathematician Vojtěch Jarník in 1930s.
7. Prim's algorithm can be used for network design and clustering problems.
8. It is similar to Kruskal's algorithm but more efficient on dense graphs.
Prim’s Algorithm 2