Help with Prim's Algorithm in Mathematica

In summary: Remember, you are not an expert in Mathematica yet. You should only be asking for help when you really do not understand something.
  • #1
Shaad
13
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
  • #2
anyone?
 
  • #3
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:
  • #4
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:
  • #5
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.
 

Related to Help with Prim's Algorithm in Mathematica

What is Prim's Algorithm in Mathematica?

Prim's Algorithm is a method for finding the minimum spanning tree of a connected, weighted graph. It is used to find the shortest path between all vertices in a graph, and is commonly used in network optimization and graph theory.

How does Prim's Algorithm work?

Prim's Algorithm works by starting at a random vertex in the graph and repeatedly adding the shortest edge that connects to a new vertex. This process continues until all vertices in the graph have been connected, resulting in a minimum spanning tree.

What is the time complexity of Prim's Algorithm?

The time complexity of Prim's Algorithm is O(ElogV), where E is the number of edges in the graph and V is the number of vertices. This makes Prim's Algorithm an efficient method for finding the minimum spanning tree of a graph.

Can Prim's Algorithm be implemented in Mathematica?

Yes, Prim's Algorithm can be implemented in Mathematica using the built-in functions for graph manipulation and shortest path algorithms. There are also several packages and libraries available that provide implementations of Prim's Algorithm in Mathematica.

What are some applications of Prim's Algorithm?

Prim's Algorithm has many practical applications, such as network optimization, route planning, and cluster analysis. It is also commonly used in data analysis and machine learning for tasks such as feature selection and dimensionality reduction.

Similar threads

  • Programming and Computer Science
Replies
8
Views
1K
  • Science and Math Textbooks
Replies
2
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
8
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Programming and Computer Science
Replies
30
Views
4K
  • STEM Academic Advising
Replies
5
Views
920
  • Introductory Physics Homework Help
Replies
1
Views
976
  • Computing and Technology
Replies
7
Views
2K
  • Introductory Physics Homework Help
Replies
2
Views
2K
  • Programming and Computer Science
Replies
5
Views
1K
Back
Top