Prim's Algorithm: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 5: Line 5:
* [[The Minimum Spanning Tree Problem|The Minimum Spanning Tree Problem]]
* [[The Minimum Spanning Tree Problem|The Minimum Spanning Tree Problem]]
=Overview=
=Overview=
Prim's algorithm is a [[Algorithms#Greedy_Algorithms|greedy algorithm]] that computes the minimum cost spanning tree of a an undirected graph. Even if the algorithm was named after Prim, it was discovered earlier by Jarník. The algorithm is similar to [[Dijkstra%27s_Shortest-Path_Algorithm|Dijkstra's shortest-path algorithm]].
Prim's algorithm is a [[Algorithms#Greedy_Algorithms|greedy algorithm]] that computes the [[The_Minimum_Spanning_Tree_Problem|minimum cost spanning tree]] of a an undirected graph. Even if the algorithm was named after Prim, it was discovered earlier by Jarník. The algorithm is similar to [[Dijkstra%27s_Shortest-Path_Algorithm|Dijkstra's shortest-path algorithm]].


=Non-Optimized Implementation=
=Non-Optimized Implementation=


The Prim algorithm randomly selects a node. It then enters a loop where at each iteration adds a new edge and spans one new vertex, adjacent to the ones already spanning. The new vertex added to the "explored territory" is selected so it can be reached via the cheapest edge. This is what makes Prim's algorithm a [[Algorithms#Greedy_Algorithms|greedy algorithm]].
The Prim algorithm randomly selects a node. It then enters a loop where at each iteration adds a new edge and spans one new vertex, adjacent to the ones already spanning. The new vertex added to the "explored territory" is selected so it can be reached via the cheapest edge. This is what makes Prim's algorithm a [[Algorithms#Greedy_Algorithms|greedy algorithm]].

Revision as of 22:09, 20 October 2021

External

Internal

Overview

Prim's algorithm is a greedy algorithm that computes the minimum cost spanning tree of a an undirected graph. Even if the algorithm was named after Prim, it was discovered earlier by Jarník. The algorithm is similar to Dijkstra's shortest-path algorithm.

Non-Optimized Implementation

The Prim algorithm randomly selects a node. It then enters a loop where at each iteration adds a new edge and spans one new vertex, adjacent to the ones already spanning. The new vertex added to the "explored territory" is selected so it can be reached via the cheapest edge. This is what makes Prim's algorithm a greedy algorithm.