Kyu Bi
Kyu Bi

Reputation: 31

C programming language Graph Structure

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

Upvotes: 1

Views: 2153

Answers (1)

Jack
Jack

Reputation: 133577

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.

Upvotes: 2

Related Questions