Skip to main content

Adjacency list representation of graph

In Programming language graph is represented in a two ways. Such as Adjacency list Adjacency matrix. In this post are mentioning example of Adjacency list of Directed and Undirected graph.

Directed Graph Adjacency list

Here given code implementation process.

Un-Directed Graph Adjacency list

Adjacency list of undirected graph

Note that in both example first use an array which are contain actual node values. Array is useful to get any node quickly in existing array. When graph nodes are not predefined or you are remove existing graph node then array are not suitable here.

Because after create array, In most of programming language are not allowing to resize the array size such as add or delete existing node. In this case you'll can use linked list to storing the value of actual graph node.





Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment