Prim's Algorithm (Edexcel A-Level Further Mathematics): Revision Notes
📚 Revision Notes
10.3.3 Prim's Algorithm
Introduction to Prim's Algorithm
Prim's algorithm is used to find a minimum spanning tree (MST) for a connected, weighted graph. Unlike Kruskal's algorithm, Prim's algorithm grows the MST by starting with one vertex and adding the smallest connecting edge at each step.
Prim's algorithm is particularly useful when the graph is represented as a matrix.
Steps of Prim's Algorithm
- Select the Starting Vertex
- Grow the MST
- Repeat Until Completion
- Select the Starting Vertex: Choose any vertex to begin the MST.
- Grow the MST:
- Identify all edges connecting the current MST to vertices not yet included.
- Select the smallest edge among these.
- Add the corresponding vertex and edge to the MST.
- Repeat Until Completion: Continue until all vertices are included in the MST.
Matrix Representation in Prim's Algorithm
A weight matrix represents the graph:
- Rows and columns correspond to vertices.
- Entries represent edge weights:
- (or a large value) if no edge exists.
Worked Example
infoNote
Problem:
Find the MST for the graph represented by the following weight matrix:
Step 1: Select the Starting Vertex
Choose (vertex 1) as the starting vertex.
Step 2: Find the Smallest Edge from
Edges from :
- Smallest edge:
- MST =
Step 3: Grow the MST
Edges from :
- (already included)
- Smallest edge:
- MST =
Step 4: Add the Remaining Vertex
Edges from :
- (already included), (already included).
- Smallest edge:
- MST =
Result:
The MST connects vertices with a total weight of 11.
Algorithm Complexity
- Time Complexity:
- For a graph with vertices and edges, Prim's algorithm has:
- O(v^2) for matrix representation.
- O(e log v) with priority queues and adjacency lists.
- Space Complexity:
- O(v^2) for storing the weight matrix.
Note Summary
infoNote
Common Mistakes
- Incorrect Matrix Initialisation: Ensure the matrix accurately represents the graph, using for missing edges.
- Double-Counting Edges: Avoid revisiting edges already included in the MST.
- Choosing Larger Weights: Always select the smallest edge connecting to the MST.
- Stopping Too Early: Ensure all vertices are included in the MST.
- Misinterpreting Matrix Entries: Diagonal entries should be or , as no vertex connects to itself.
infoNote
Key Formulas and Concepts
- Weight Matrix Representation:
- MST Properties:
- A spanning tree connects all vertices with v-1 edges.
- The MST minimises the total weight of edges.