4.0

4.0 | 8 ratings Rate this file 46 downloads (last 30 days) File Size: 1.59 KB File ID: #8569

Prims Algorithm

by Vikramaditya Kundur

 

27 Sep 2005 (Updated 30 Sep 2005)

Code covered by the BSD License  

Minimal spanning tree.

Download Now | Watch this File

File Information
Description

In the mathematical field of graph theory, a spanning tree of a connected, undirected graph is a tree which includes every vertex of that graph. More generally, a spanning forest of an arbitrary undirected graph is a forest which includes every vertex of the graph. Spanning forests always exist, and can always be constructed so as to have exactly one tree for each connected component. In certain fields of graph theory, involving weighted graphs, it is often useful to find a minimal spanning tree.

Prim's algorithm builds a tree while having the graph connected at all times.

Prim's algorithm maintains two lists, EV which is the vertices already in the tree, and E, the list of edges that makes up the spanning tree. In determining current edges for the tree, we look for a node that's in EV, and on that isn't, such that its path is minimum.
EV = { 0 }

E = { }

while( E has < n-1 edges ) {

  find (u,v) with least cost, such that
u is in EV and v isn't in EV

  if no such edge exists, break

  add v to EV

  add (u,v) to E
}
On termination, if the graph is connected, EV will contain all the nodes in the graph, and E will contain the set edges comprising the minimum spanning tree.

MATLAB release MATLAB 6.1 (R12.1)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (8)
12 Oct 2005 Veronika Schöpf  
09 Nov 2005 Nick Cheilakos  
27 Feb 2006 Zack Voulgaris

A bit amateurish. Otherwise, okay.

06 Dec 2006 xueli an  
07 Dec 2006 John Smith

Easy to use.

16 Jul 2007 Nicholas Thompson

Interesting read. I've implemented basically this algorithm in Dark Basic Pro. This code snippet creates a random set of "nodes" (or cities in this case) with non-overlapping eges (Connections in this case)...

<a href="http://codebase.dbp-site.com/code/prims-algorithm-grid-map-generator-24"&gt;Prims Algorithm in Dark Basic Pro</a>

26 Nov 2007 Fabrício Oliveira

I haven't seen the code yet, but looks like that will only get the optimum if you allow the algorithm gets also the edges where neither u or v are in EV...

29 Apr 2008 Ricardo Leal  
Please login to add a comment or rating.
Updates
30 Sep 2005

Found an error. Need to update with a new file.

Tag Activity for this File
Tag Applied By Date/Time
specialized Vikramaditya Kundur 22 Oct 2008 08:00:51
plotting Vikramaditya Kundur 22 Oct 2008 08:00:51
prims Vikramaditya Kundur 22 Oct 2008 08:00:51
spanning Vikramaditya Kundur 22 Oct 2008 08:00:51
specialized plot Vikramaditya Kundur 22 Oct 2008 08:00:51
algorithm Vikramaditya Kundur 22 Oct 2008 08:00:51
graphics Vikramaditya Kundur 22 Oct 2008 08:00:51
tree Vikramaditya Kundur 22 Oct 2008 08:00:51
algorithm Ayman Ahmed 26 May 2009 23:16:39
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com