encyclopegia.org

Prim's algorithm

In computer science, Prim's algorithm is a greedy algorithm that finds a minimum spanning tree for a weighted undirected graph. This means it finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized. The algorithm operates by building this tree one vertex at a time, from an arbitrary starting vertex, at each step adding the cheapest possible connection from the tree to another vertex. The algorithm was developed in 1930 by Czech mathematician Vojtěch Jarník and later rediscovered and republished by Joseph Kruskal in 1956, Robert C. Prim in 1957, and Edsger W. Dijkstra in 1959. Therefore, it is also sometimes called Jarník's algorithm, the Prim–Jarník algorithm, the Prim–Dijkstra algorithm or the DJP algorithm. Other well-known algorithms for this problem include Kruskal's algorithm and Borůvka's algorithm. These algorithms find the minimum spanning forest in a possibly disconnected graph; in contrast, the most basic form of Prim's algorithm only finds minimum spanning trees in connected graphs. However, running Prim's algorithm separately for each connected component of the graph, it can also be used to find the minimum spanning forest. In terms of their asymptotic time complexity, these three algorithms are equally fast for sparse graphs, but slower than other more sophisticated algorithms.…

In computer science, Prim's algorithm is a greedy algorithm that finds a minimum spanning tree for a weighted undirected graph. This means it finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized. The algorithm operates by building this tree one vertex at a time, from an arbitrary starting vertex, at each step adding the cheapest possible connection from the tree to another vertex. The algorithm was developed in 1930 by Czech mathematician Vojtěch Jarník and later rediscovered and republished by Joseph Kruskal in 1956, Robert C. Prim in 1957, and Edsger W. Dijkstra in 1959. Therefore, it is also sometimes called Jarník's algorithm, the Prim–Jarník algorithm, the Prim–Dijkstra algorithm or the DJP algorithm. Other well-known algorithms for this problem include Kruskal's algorithm and Borůvka's algorithm. These algorithms find the minimum spanning forest in a possibly disconnected graph; in contrast, the most basic form of Prim's algorithm only finds minimum spanning trees in connected graphs. However, running Prim's algorithm separately for each connected component of the graph, it can also be used to find the minimum spanning forest. In terms of their asymptotic time complexity, these three algorithms are equally fast for sparse graphs, but slower than other more sophisticated algorithms. However, for graphs that are sufficiently dense, Prim's algorithm can be made to run in linear time, meeting or improving the time bounds for other algorithms. Let Y 1 be a minimum spanning tree of graph P. If Y 1 =Y then Y is a minimum spanning tree. Otherwise, let e be the first edge added during the construction of tree Y that is not in tree Y 1 , and V be the set of vertices connected by the edges added before edge e. Then one endpoint of edge e is in set V and the other is not. Since tree Y 1 is a spanning tree of graph P, there is a path in tree Y 1 joining the two endpoints. As one travels along the path, one must encounter an edge f joining a vertex in set V to one that is not in set V. Now, at the iteration when edge e was added to tree Y, edge f could also have been added and it would be added instead of edge e if its weight was less than e, and since edge f was not added, we conclude that w(f) \ge w(e). Let tree Y 2 be the graph obtained by removing edge f from and adding edge e to tree Y 1 . It is easy to show that tree Y 2 is connected, has the same number of edges as tree Y 1 , and the total weights of its edges is not larger than that of tree Y 1 , therefore it is also a minimum spanning tree of graph P and it contains edge e and all the edges added before it during the construction of set V. Repeat the steps above and we will eventually obtain a minimum spanning tree of graph P that is identical to tree Y. This shows Y is a minimum spanning tree. The minimum spanning tree allows for the first subset of the sub-region to be expanded into a larger subset X, which we assume to be the minimum.

References

  1. O jistém problému minimálním · retrieved 2026-11-17 · rev 1368985795
    Cite this reference

    MLA "O jistém problému minimálním." Jarník, V. 2026-11-17. https://en.wikipedia.org/wiki/Vojt%C4%9Bch_Jarn%C3%ADk. Accessed 24 November 2026.

    Chicago "O jistém problému minimálním." Jarník, V. 2026-11-17. https://en.wikipedia.org/wiki/Vojt%C4%9Bch_Jarn%C3%ADk.

    APA Jarník, V. (2026). O jistém problému minimálním. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/Vojt%C4%9Bch_Jarn%C3%ADk

  2. Kepner, Jeremy; Gilbert, John (2011), Graph Algorithms in the Language of Linear Algebra , Software, Environments, and Tools, vol. 22, Society for Industrial and Applied Mathematics , p. 55, ISBN 9780898719901 . Wikipedia revision 1368985795, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1368985795
    Cite this reference

    MLA "Kepner, Jeremy; Gilbert, John (2011), Graph Algorithms in the Language of Linear Algebra , Software, Environments, and Tools, vol. 22, Society for Industrial and Applied Mathematics , p. 55, ISBN 9780898719901 . Wikipedia revision 1368985795, retrieved 2026-11-18." Kepner, Jeremy; Gilbert, John (2011), Graph Algorithms in the Language of Linear Algebra , Software, Environments, and T. 2026-11-17. https://books.google.com/books?id=JBXDc83jRBwC&pg=PA55. Accessed 24 November 2026.

    Chicago "Kepner, Jeremy; Gilbert, John (2011), Graph Algorithms in the Language of Linear Algebra , Software, Environments, and Tools, vol. 22, Society for Industrial and Applied Mathematics , p. 55, ISBN 9780898719901 . Wikipedia revision 1368985795, retrieved 2026-11-18." Kepner, Jeremy; Gilbert, John (2011), Graph Algorithms in the Language of Linear Algebra , Software, Environments, and T. 2026-11-17. https://books.google.com/books?id=JBXDc83jRBwC&pg=PA55.

    APA Kepner, Jeremy; Gilbert, John (2011), Graph Algorithms in the Language of Linear Algebra , Software, Environments, and T. (2026). Kepner, Jeremy; Gilbert, John (2011), Graph Algorithms in the Language of Linear Algebra , Software, Environments, and Tools, vol. 22, Society for Industrial and Applied Mathematics , p. 55, ISBN 9780898719901 . Wikipedia revision 1368985795, retrieved 2026-11-18. Retrieved November 24, 2026, from https://books.google.com/books?id=JBXDc83jRBwC&pg=PA55

  3. Priority queues with update and finding minimum spanning trees · retrieved 2026-11-17 · rev 1368985795
    Cite this reference

    MLA "Priority queues with update and finding minimum spanning trees." Johnson, Donald B. 2026-11-17. https://en.wikipedia.org/wiki/Donald_B._Johnson. Accessed 24 November 2026.

    Chicago "Priority queues with update and finding minimum spanning trees." Johnson, Donald B. 2026-11-17. https://en.wikipedia.org/wiki/Donald_B._Johnson.

    APA Johnson, Donald B. (2026). Priority queues with update and finding minimum spanning trees. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/Donald_B._Johnson

  4. Parallel graph algorithms · retrieved 2026-11-17 · rev 1368985795
    Cite this reference

    MLA "Parallel graph algorithms." Quinn, Michael J. 2026-11-17. https://en.wikipedia.org/wiki/Doi_(identifier). Accessed 24 November 2026.

    Chicago "Parallel graph algorithms." Quinn, Michael J. 2026-11-17. https://en.wikipedia.org/wiki/Doi_(identifier).

    APA Quinn, Michael J. (2026). Parallel graph algorithms. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/Doi_(identifier)

  5. A new parallel algorithm for minimum spanning tree problem · retrieved 2026-11-17 · rev 1368985795
    Cite this reference

    MLA "A new parallel algorithm for minimum spanning tree problem." Setia, Rohit (2009), "A new parallel algorithm for minimum spanning tree problem" (PDF) , Proc. 2026-11-17. https://ncit-cluster.grid.pub.ro/trac/PP2009/export/157/proiecte/pgraph/Documentation/parallelspannintree.pdf. Accessed 24 November 2026.

    Chicago "A new parallel algorithm for minimum spanning tree problem." Setia, Rohit (2009), "A new parallel algorithm for minimum spanning tree problem" (PDF) , Proc. 2026-11-17. https://ncit-cluster.grid.pub.ro/trac/PP2009/export/157/proiecte/pgraph/Documentation/parallelspannintree.pdf.

    APA Setia, Rohit (2009), "A new parallel algorithm for minimum spanning tree problem" (PDF) , Proc. (2026). A new parallel algorithm for minimum spanning tree problem. Retrieved November 24, 2026, from https://ncit-cluster.grid.pub.ro/trac/PP2009/export/157/proiecte/pgraph/Documentation/parallelspannintree.pdf

  6. On the shortest spanning subtree of a graph and the traveling salesman problem · retrieved 2026-11-17 · rev 1368985795
    Cite this reference

    MLA "On the shortest spanning subtree of a graph and the traveling salesman problem." Kruskal, J. 2026-11-17. https://en.wikipedia.org/wiki/Joseph_Kruskal. Accessed 24 November 2026.

    Chicago "On the shortest spanning subtree of a graph and the traveling salesman problem." Kruskal, J. 2026-11-17. https://en.wikipedia.org/wiki/Joseph_Kruskal.

    APA Kruskal, J. (2026). On the shortest spanning subtree of a graph and the traveling salesman problem. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/Joseph_Kruskal

  7. Shortest connection networks And some generalizations · retrieved 2026-11-17 · rev 1368985795
    Cite this reference

    MLA "Shortest connection networks And some generalizations." Prim, R. 2026-11-17. https://en.wikipedia.org/wiki/Robert_C._Prim. Accessed 24 November 2026.

    Chicago "Shortest connection networks And some generalizations." Prim, R. 2026-11-17. https://en.wikipedia.org/wiki/Robert_C._Prim.

    APA Prim, R. (2026). Shortest connection networks And some generalizations. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/Robert_C._Prim

  8. A note on two problems in connexion with graphs · retrieved 2026-11-17 · rev 1368985795
    Cite this reference

    MLA "A note on two problems in connexion with graphs." Dijkstra, E. 2026-11-17. https://en.wikipedia.org/wiki/Edsger_W._Dijkstra. Accessed 24 November 2026.

    Chicago "A note on two problems in connexion with graphs." Dijkstra, E. 2026-11-17. https://en.wikipedia.org/wiki/Edsger_W._Dijkstra.

    APA Dijkstra, E. (2026). A note on two problems in connexion with graphs. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/Edsger_W._Dijkstra

  9. Sedgewick, Robert ; Wayne, Kevin Daniel (2011), Algorithms (4th ed.), Addison-Wesley, p. 628, ISBN 978-0-321-57351-3 . Wikipedia revision 1368985795, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1368985795
    Cite this reference

    MLA "Sedgewick, Robert ; Wayne, Kevin Daniel (2011), Algorithms (4th ed.), Addison-Wesley, p. 628, ISBN 978-0-321-57351-3 . Wikipedia revision 1368985795, retrieved 2026-11-18." Sedgewick, Robert ; Wayne, Kevin Daniel (2011), Algorithms (4th ed. 2026-11-17. https://en.wikipedia.org/wiki/Robert_Sedgewick_(computer_scientist). Accessed 24 November 2026.

    Chicago "Sedgewick, Robert ; Wayne, Kevin Daniel (2011), Algorithms (4th ed.), Addison-Wesley, p. 628, ISBN 978-0-321-57351-3 . Wikipedia revision 1368985795, retrieved 2026-11-18." Sedgewick, Robert ; Wayne, Kevin Daniel (2011), Algorithms (4th ed. 2026-11-17. https://en.wikipedia.org/wiki/Robert_Sedgewick_(computer_scientist).

    APA Sedgewick, Robert ; Wayne, Kevin Daniel (2011), Algorithms (4th ed. (2026). Sedgewick, Robert ; Wayne, Kevin Daniel (2011), Algorithms (4th ed.), Addison-Wesley, p. 628, ISBN 978-0-321-57351-3 . Wikipedia revision 1368985795, retrieved 2026-11-18. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/Robert_Sedgewick_(computer_scientist)

  10. Rosen, Kenneth (2011), Discrete Mathematics and Its Applications (7th ed.), McGraw-Hill Science, p. 798 . Wikipedia revision 1368985795, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1368985795
    Cite this reference

    MLA "Rosen, Kenneth (2011), Discrete Mathematics and Its Applications (7th ed.), McGraw-Hill Science, p. 798 . Wikipedia revision 1368985795, retrieved 2026-11-18." Rosen, Kenneth (2011), Discrete Mathematics and Its Applications (7th ed. 2026-11-17. https://books.google.com/books?id=6EJOCAAAQBAJ&pg=PA798. Accessed 24 November 2026.

    Chicago "Rosen, Kenneth (2011), Discrete Mathematics and Its Applications (7th ed.), McGraw-Hill Science, p. 798 . Wikipedia revision 1368985795, retrieved 2026-11-18." Rosen, Kenneth (2011), Discrete Mathematics and Its Applications (7th ed. 2026-11-17. https://books.google.com/books?id=6EJOCAAAQBAJ&pg=PA798.

    APA Rosen, Kenneth (2011), Discrete Mathematics and Its Applications (7th ed. (2026). Rosen, Kenneth (2011), Discrete Mathematics and Its Applications (7th ed.), McGraw-Hill Science, p. 798 . Wikipedia revision 1368985795, retrieved 2026-11-18. Retrieved November 24, 2026, from https://books.google.com/books?id=6EJOCAAAQBAJ&pg=PA798

  11. Chapter 6. Minimum spanning trees. 6.2. Three classical algorithms · retrieved 2026-11-17 · rev 1368985795
    Cite this reference

    MLA "Chapter 6. Minimum spanning trees. 6.2. Three classical algorithms." Tarjan, Robert Endre (1983), "Chapter 6. 2026-11-17. https://en.wikipedia.org/wiki/Robert_Tarjan. Accessed 24 November 2026.

    Chicago "Chapter 6. Minimum spanning trees. 6.2. Three classical algorithms." Tarjan, Robert Endre (1983), "Chapter 6. 2026-11-17. https://en.wikipedia.org/wiki/Robert_Tarjan.

    APA Tarjan, Robert Endre (1983), "Chapter 6. (2026). Chapter 6. Minimum spanning trees. 6.2. Three classical algorithms. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/Robert_Tarjan

  12. Finding minimum spanning trees · retrieved 2026-11-17 · rev 1368985795
    Cite this reference

    MLA "Finding minimum spanning trees." a b Cheriton, David ; Tarjan, Robert Endre (1976), "Finding minimum spanning trees", SIAM Journal on Computing , 5 (4):. 2026-11-17. https://en.wikipedia.org/wiki/David_Cheriton. Accessed 24 November 2026.

    Chicago "Finding minimum spanning trees." a b Cheriton, David ; Tarjan, Robert Endre (1976), "Finding minimum spanning trees", SIAM Journal on Computing , 5 (4):. 2026-11-17. https://en.wikipedia.org/wiki/David_Cheriton.

    APA a b Cheriton, David ; Tarjan, Robert Endre (1976), "Finding minimum spanning trees", SIAM Journal on Computing , 5 (4):. (2026). Finding minimum spanning trees. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/David_Cheriton

  13. a b c Grama, Ananth; Gupta, Anshul; Karypis, George; Kumar, Vipin (2003), Introduction to Parallel Computing , Addison-Wesley, pp. 444– 446, ISBN 978-0201648652 Wikipedia revision 1368985795, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1368985795
    Cite this reference

    MLA "a b c Grama, Ananth; Gupta, Anshul; Karypis, George; Kumar, Vipin (2003), Introduction to Parallel Computing , Addison-Wesley, pp. 444– 446, ISBN 978-0201648652 Wikipedia revision 1368985795, retrieved 2026-11-18." a b c Grama, Ananth; Gupta, Anshul; Karypis, George; Kumar, Vipin (2003), Introduction to Parallel Computing , Addison-W. 2026-11-17. https://en.wikipedia.org/wiki/ISBN_(identifier). Accessed 24 November 2026.

    Chicago "a b c Grama, Ananth; Gupta, Anshul; Karypis, George; Kumar, Vipin (2003), Introduction to Parallel Computing , Addison-Wesley, pp. 444– 446, ISBN 978-0201648652 Wikipedia revision 1368985795, retrieved 2026-11-18." a b c Grama, Ananth; Gupta, Anshul; Karypis, George; Kumar, Vipin (2003), Introduction to Parallel Computing , Addison-W. 2026-11-17. https://en.wikipedia.org/wiki/ISBN_(identifier).

    APA a b c Grama, Ananth; Gupta, Anshul; Karypis, George; Kumar, Vipin (2003), Introduction to Parallel Computing , Addison-W. (2026). a b c Grama, Ananth; Gupta, Anshul; Karypis, George; Kumar, Vipin (2003), Introduction to Parallel Computing , Addison-Wesley, pp. 444– 446, ISBN 978-0201648652 Wikipedia revision 1368985795, retrieved 2026-11-18. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/ISBN_(identifier)

  14. An optimal minimum spanning tree algorithm · retrieved 2026-11-17 · rev 1368985795
    Cite this reference

    MLA "An optimal minimum spanning tree algorithm." a b Pettie, Seth; Ramachandran, Vijaya (January 2002), "An optimal minimum spanning tree algorithm" (PDF) , Journal of t. 2026-11-17. https://en.wikipedia.org/wiki/Vijaya_Ramachandran. Accessed 24 November 2026.

    Chicago "An optimal minimum spanning tree algorithm." a b Pettie, Seth; Ramachandran, Vijaya (January 2002), "An optimal minimum spanning tree algorithm" (PDF) , Journal of t. 2026-11-17. https://en.wikipedia.org/wiki/Vijaya_Ramachandran.

    APA a b Pettie, Seth; Ramachandran, Vijaya (January 2002), "An optimal minimum spanning tree algorithm" (PDF) , Journal of t. (2026). An optimal minimum spanning tree algorithm. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/Vijaya_Ramachandran

  15. a b Tarjan (1983) , p. 77. Wikipedia revision 1368985795, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1368985795
    Cite this reference

    MLA "a b Tarjan (1983) , p. 77. Wikipedia revision 1368985795, retrieved 2026-11-18." a b Tarjan (1983) , p. 2026-11-17. https://en.wikipedia.org/w/index.php?oldid=1368985795. Accessed 24 November 2026.

    Chicago "a b Tarjan (1983) , p. 77. Wikipedia revision 1368985795, retrieved 2026-11-18." a b Tarjan (1983) , p. 2026-11-17. https://en.wikipedia.org/w/index.php?oldid=1368985795.

    APA a b Tarjan (1983) , p. (2026). a b Tarjan (1983) , p. 77. Wikipedia revision 1368985795, retrieved 2026-11-18. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1368985795

Cite this article

MLA

"Prim's algorithm." encyclopegia.org, 2026, https://encyclopegia.org/wiki/prim-s-algorithm. Accessed 24 November 2026.

Chicago

"Prim's algorithm." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/prim-s-algorithm.

APA

encyclopegia.org. (2026). Prim's algorithm. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/prim-s-algorithm

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Claims

PredicateValueSource
year mentioned1930article body
year mentioned1956article body
year mentioned1957article body
year mentioned1959article body

Related articles

Ri Song-hui

stub · references available

William Phillips

stub · references available

Bruna Genovese

stub · references available

Carlos Tiny

stub · references available

E20

stub · references available

Ryan Stone

stub · references available
CC BY-SA 4.0 · tier1-factual · https://en.wikipedia.org/w/index.php?oldid=1368985795 · 0.55 · snapshot prim-s-algorithm-054253-05993e9f8184a9e9 · QID Q470813

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.