1

I have some trouble with building Graph Structure. I know how to build a simply linked list and doubly too. But I want to construct a graph structure like in this site (the pic. output) http://www.cs.sunysb.edu/~algorith/files/graph-data-structures.shtml

1
  • What part of it exactly are you having problems with? Are you familiar with the graph data structure? Commented Jun 4, 2012 at 22:02

1 Answer 1

2

You have three common solutions:

  • an adjacency matrix (in which you store a matrix of N*N where N is the number of vertices and in matrix[x][y] you will store a value if x has an edge to y, 0 otherwise
  • an edge list, in which you just keep a long lists of edges so that if the couple (x,y) is in the list, then there is an edge from x to y
  • an adjacency list, in which you have a list of vertices and every vertex x has a list of edges to the nodes for which x has an edge to.

Every different approach is good or bad according to

  • space required
  • computational complexity related to specific operations more than other

So according to what you need to do with the graph you could choose any of those. If you want to know specific characteristic of the above possible implementations take a look at my answer to another SO question.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.