3

I have learned the basics of graph data structures. Now I want to implement all the structure/algorithms/operations that can be performed on graphs.

Please share some useful links wherein I can get started doing graph implementations in C.

0

2 Answers 2

3

adjacency list and adjacency matrix are the two most classic alternatives for implementing graphs. I'm not sure if there are many examples of each online in C, but here is one for the adjacency matrix representation.

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

2 Comments

Thanks Alex.... Looks pretty good example... I will work it out..... but there is one article on adjacency list with incomplete implementation cs.bu.edu/teaching/c/graph/linked........ But i am finding it difficult to get the start.... Can you help it out..... I have understood the structures,, but now if we want to insert a vertex or edge.. etc....
@AGeek, in adj matrix: insert edge (between existing vertices I and J) → just set the matrix[I][J]=1; insert new vertex N+1 → allocate new N+1 by N+1 matrix and copy the old one over padding with the new row and col of 0s. adj list: in adj matrix: insert edge (between existing vertices I and J) → append J to the adj list of I; insert new vertex → append it to the list of existing vertices.
1

The book,The Algorithm Design Manual[PDF] has C code implementing a graph.

For a more thorough textbook on graphs and related algorithms (DFS, Bellman-Ford etc) Introduction to Algorithms (excellent) has pseudocode implementations that you could implement.

The standard adjacency list or matrix representations mentioned by Alex are described in both.

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.