Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

does Java have graphs as an intergrated data structure? How about Python?

I was assigned to write a program, that solves the TSP (travelling salesman problem) via the GRASP (greedy randomized adaptive search procedure). I'm just familiarizing myself with GRASP, and I would like to have a good working data structure for graphs, that includes plotting the graph and the option to assign special colour to edges (so I can colour the final solution: cheapest hamiltonian path).

I'm gonna have a presentation, explaining my final solution, whence the need for plotting the graph. Also, it would be desirable to have the option to generate a random graph on n vertices, so I have some easily accessible examples.

I was really hoping this has been done by someone before, so I don't start from scratch. I'm a mathematician (or atleast trying to be), so please, no fancy programmer slang.

thank you

share|improve this question
Google points me towards and…. – btilly Apr 28 '11 at 19:50
@btilly Good links, thank you. – Leon Apr 28 '11 at 20:01
up vote 2 down vote accepted

For python.

also check out

you generate a text file, feed it to graphviz, and it makes a graph as png, pdf, etc.

share|improve this answer
+1. Also re graphviz: take a look at pydot, which allows you to build the graph directly in python then render via graphviz. Also take a look at python-graph ( for graph algorithms & rendering via graphviz. hth. – sfinnie Apr 28 '11 at 20:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.