Help with Prim's Algorithm in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter Shaad
  • Start date Start date
  • Tags Tags
    Algorithm Mathematica
Click For Summary

Discussion Overview

The discussion revolves around implementing Prim's Algorithm in Mathematica for a project related to spanning trees. Participants explore the challenges faced by a user who is unfamiliar with Mathematica and seeks assistance in applying the algorithm, which was not covered in their class.

Discussion Character

  • Homework-related
  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant expresses difficulty in using Mathematica for their project on Prim's Algorithm, noting a lack of prior instruction in the software.
  • Another participant suggests using the Combinatorica package in Mathematica and provides steps for creating an adjacency list and utilizing built-in functions, although they mention that the MinimumSpanningTree function uses Kruskal's algorithm instead.
  • A different participant advises the original poster to first understand the algorithm conceptually and to create a simple list of instructions before attempting to implement it in Mathematica.
  • This participant emphasizes the importance of breaking down the problem into smaller, manageable steps and testing each step in Mathematica to ensure understanding and correctness.

Areas of Agreement / Disagreement

Participants generally agree on the need for a foundational understanding of the algorithm before coding, but there is no consensus on the best approach to implement Prim's Algorithm specifically in Mathematica.

Contextual Notes

The discussion highlights the original poster's unfamiliarity with Mathematica and the potential gap between theoretical understanding and practical application in programming.

Who May Find This Useful

Students learning about algorithms, particularly spanning trees, and those seeking to apply theoretical concepts in programming environments like Mathematica.

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 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 9 ·
Replies
9
Views
7K
  • · Replies 3 ·
Replies
3
Views
21K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
7K