Photo AI

Last Updated Sep 27, 2025

Prim's Algorithm Simplified Revision Notes

Revision notes with simplified explanations to understand Prim's Algorithm quickly and effectively.

user avatar
user avatar
user avatar
user avatar
user avatar

286+ students studying

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

  1. Select the Starting Vertex
  2. Grow the MST
  3. Repeat Until Completion

  1. Select the Starting Vertex: Choose any vertex to begin the MST.

  1. 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.

  1. 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:
    • wij=weight of edge between vertices i and jw_{ij} = \text{weight of edge between vertices } i \text{ and } j
    • wij=w_{ij} = \infty (or a large value) if no edge exists.

Worked Example

infoNote

Problem:

Find the MST for the graph represented by the following weight matrix:

W=(7372632868)\mathbf{W} = \begin{pmatrix} \infty & 7 & 3 & \infty \\ 7 & \infty & 2 & 6 \\ 3 & 2 & \infty & 8 \\ \infty & 6 & 8 & \infty \end{pmatrix}

Step 1: Select the Starting Vertex

Choose AA (vertex 1) as the starting vertex.


Step 2: Find the Smallest Edge from AA

Edges from AA:

  • AB=7,AC=3,AD=A \to B = 7, A \to C = 3, A \to D = \infty
  • Smallest edge: AC=:highlight[3]A \to C = :highlight[3]
  • MST ={A,C},Total Weight: :highlight[3]\{ A, C \}, \, \text{Total Weight: } :highlight[3]

Step 3: Grow the MST

Edges from CC:

  • CB=2,CD=8,CA=3C \to B = 2, C \to D = 8, C \to A = 3 (already included)
  • Smallest edge: CB=:highlight[2]C \to B = :highlight[2]
  • MST ={A,C,B},Total Weight: :highlight[3+2=5]\{ A, C, B \}, \, \text{Total Weight: } :highlight[3 + 2 = 5]

Step 4: Add the Remaining Vertex

Edges from BB:

  • BD=6,BC=2B \to D = 6, B \to C = 2 (already included), BA=7B \to A = 7 (already included).
  • Smallest edge: BD=:highlight[6]B \to D = :highlight[6]
  • MST ={A,C,B,D},Total Weight: :highlight[5+6=11]\{ A, C, B, D \}, \, \text{Total Weight: } :highlight[5 + 6 = 11]

Result:

The MST connects vertices A,B,C,DA, B, C, D with a total weight of 11.

Algorithm Complexity

  1. Time Complexity:
  • For a graph with vv vertices and ee edges, Prim's algorithm has:
  • O(v^2) for matrix representation.
  • O(e log v) with priority queues and adjacency lists.
  1. Space Complexity:
  • O(v^2) for storing the weight matrix.

Note Summary

infoNote

Common Mistakes

  1. Incorrect Matrix Initialization: Ensure the matrix accurately represents the graph, using \infty for missing edges.
  2. Double-Counting Edges: Avoid revisiting edges already included in the MST.
  3. Choosing Larger Weights: Always select the smallest edge connecting to the MST.
  4. Stopping Too Early: Ensure all vertices are included in the MST.
  5. Misinterpreting Matrix Entries: Diagonal entries should be \infty or 00, as no vertex connects to itself.
infoNote

Key Formulas and Concepts

  1. Weight Matrix Representation:
wij={weight of edge between i and j,if edge exists,,if no edge exists.w_{ij} = \begin{cases} \text{weight of edge between } i \text{ and } j, & \text{if edge exists}, \\ \infty, & \text{if no edge exists}. \end{cases}
  1. MST Properties:
  • A spanning tree connects all vertices with v-1 edges.
  • The MST minimizes the total weight of edges.
Books

Only available for registered users.

Sign up now to view the full note, or log in if you already have an account!

500K+ Students Use These Powerful Tools to Master Prim's Algorithm

Enhance your understanding with flashcards, quizzes, and exams—designed to help you grasp key concepts, reinforce learning, and master any topic with confidence!

40 flashcards

Flashcards on Prim's Algorithm

Revise key concepts with interactive flashcards.

Try Further Maths Decision Maths 1 Flashcards

4 quizzes

Quizzes on Prim's Algorithm

Test your knowledge with fun and engaging quizzes.

Try Further Maths Decision Maths 1 Quizzes

29 questions

Exam questions on Prim's Algorithm

Boost your confidence with real exam questions.

Try Further Maths Decision Maths 1 Questions

27 exams created

Exam Builder on Prim's Algorithm

Create custom exams across topics for better practice!

Try Further Maths Decision Maths 1 exam builder

50 papers

Past Papers on Prim's Algorithm

Practice past papers to reinforce exam experience.

Try Further Maths Decision Maths 1 Past Papers

Other Revision Notes related to Prim's Algorithm you should explore

Discover More Revision Notes Related to Prim's Algorithm to Deepen Your Understanding and Improve Your Mastery

96%

114 rated

Minimum Spanning Trees

Networks & Matrices

user avatar
user avatar
user avatar
user avatar
user avatar

336+ studying

191KViews

96%

114 rated

Minimum Spanning Trees

Kruskal's Algorithm

user avatar
user avatar
user avatar
user avatar
user avatar

291+ studying

197KViews

96%

114 rated

Minimum Spanning Trees

Comparing MST Algorithms

user avatar
user avatar
user avatar
user avatar
user avatar

476+ studying

192KViews
Load more notes

Join 500,000+ A-Level students using SimpleStudy...

Join Thousands of A-Level Students Using SimpleStudy to Learn Smarter, Stay Organized, and Boost Their Grades with Confidence!

97% of Students

Report Improved Results

98% of Students

Recommend to friends

500,000+

Students Supported

50 Million+

Questions answered