Menu
Coddy logo textTech

Time and Space Complexity

Lesson 7 of 9 in Coddy's Prim's Algorithm - Graph Algorithms course.

Time Complexity:

  • The edge-scan version here is O(V * E): V-1 rounds, each scanning all E edges. With a binary heap and adjacency lists, Prim runs in O((V + E) log V).

Space Complexity:

  • O(V) for the inTree array (plus the input edges).

Summary:

  • Prim grows one tree, always adding the cheapest edge leaving it, until every vertex is included.
  • It produces the same minimum total weight as Kruskal, using a different strategy.

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Prim's Algorithm - Graph Algorithms