Mathematica Help with Prim's Algorithm in Mathematica

AI Thread Summary
The discussion focuses on implementing Prim's Algorithm in Mathematica for a project on spanning trees, as the user has not learned this in class. They express confusion about the differences between Mathematica and programming languages they previously studied. A suggestion is made to use the Combinatorica package and create an adjacency list for the graph, followed by using built-in functions to generate the minimum spanning tree. Additionally, it is advised to first thoroughly understand the algorithm and create simple instructions before attempting to code in Mathematica. The emphasis is on learning through problem-solving rather than seeking direct answers.
Shaad
Messages
13
Reaction score
0
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
 
Physics news on Phys.org
anyone?
 
This is what I am trying to get.
http://img222.imageshack.us/img222/4116/76535717ef6.jpg


...and this is what i keep getting.
http://img167.imageshack.us/img167/8883/68555492kw1.jpg
 
Last edited by a moderator:
First of all use Mathematica/combinatorica package. You have to import it. In Mathematica 7,
<<Combinatorica`
In Mathematica 5,
<<Discretemath`Combinatorica`
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
FromAdjacencyLists[ adjacency_list_name ]
. There is a built in algorithm
MinimumSpanningTree[ graph_you_just_formed ]
Though it uses Kruskal's algorithm. You can easily show any graph using
ShowGraph[ graph_name ]

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:
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.
 

Similar threads

Replies
1
Views
2K
Replies
8
Views
2K
Replies
9
Views
7K
Replies
3
Views
20K
Replies
7
Views
2K
Replies
2
Views
6K
Back
Top