# Help with Prim's Algorithm in Mathematica

1. Oct 13, 2008

This is my project of Spanning Tree by using Prim's Algorithm , I have to implies this problem (#4, PIC is attached) into Mathematica ( I have version 6 btw). Which we never learned in class. Its my Applied Math class, all we do/did is theorems. We never learned a single thing about this program in the class.

I did take computer programming about two semester ago and according to professor, both program are very similar. But I find it very different. Anyone would like to help me out with this project.

I'd really appreciate it. Thanks in Advance.

attachment didn't work, so i just uploaded the pic. Link is below.
http://img129.imageshack.us/my.php?image=sc3ju5.jpg

2. Oct 14, 2008

anyone?

3. Jan 13, 2009

This is what im trying to get.
http://img222.imageshack.us/img222/4116/76535717ef6.jpg [Broken]

........and this is what i keep getting.
http://img167.imageshack.us/img167/8883/68555492kw1.jpg [Broken]

Last edited by a moderator: May 3, 2017
4. Oct 7, 2010

First of all use Mathematica/combinatorica package. You have to import it. In Mathematica 7,
In Mathematica 5,
Then you should create an adjacency list for the graph you mentioned. (I hope you can do that?). After you've created the adjacency list you can create a graph from it using
. There is a built in algorithm
Though it uses Kruskal's algorithm. You can easily show any graph using
To employ Prim's Algorithm, you have to do the following:
1. How to traverse list of lists
2. How to write Moduels in Mathematica

Let me know if it worked.
Thanks

Last edited: Oct 7, 2010
5. Oct 7, 2010

### Bill Simpson

Based on your description of your background, I suggest you not start thinking about what to do with Mathematica yet. I suggest you first try to understand the algorithm until you can write down an EXTREMELY simple list of instructions or directions for someone else to do. Imagine this person understands nothing and can only do the simplest things that you describe exactly how to do and the order to do them in.

Once you have understood enough that you have created that very simple list of instructions then post that list here. And then begin to think about how you might turn each of those instructions into one or two programming language statements for some simple programming language you might understand.

Once you have done that then begin to think about how those statements might have a similar statement or two in Mathematica. If you are not sure about whether your Mathematica statement will do what you need then write a couple of lines of Mathematica to test your statement on data that you provide. For example, if you need to find a particular item in a list and you are not sure if your method will work to find that then write a couple of lines to test your method.

This will probably not give a Mathematica program like an experienced MMA programmer would write, but hopefully it will give you two or three smaller steps that you can accomplish one by one and hopefully will let you accomplish your task.

I suggest you not let someone tell you the answer, but only ask for hints when you are really stuck and have worked hard on it before asking for the hint you need.