Algorithms and Data Structures · Senior · Question 5 of 75

How do Prim's and Kruskal's algorithms differ?

Explanation

Both compute a minimum spanning tree. Prim adds the cheapest edge leaving the current tree (heap of edges); Kruskal sorts all edges and uses union-find to skip cycles. Kruskal is natural for sparse edge lists, Prim for dense graphs.

Further reading

Problem with a question

Algorithms and Data Structures · Senior · question 5

Test yourself

Take the Algorithms and Data Structures · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz