- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Representation of Graphs

There are mainly two ways to represent a graph −

- Adjacency Matrix
- Adjacency List

## Adjacency Matrix

An Adjacency Matrix A[V][V] is a 2D array of size V × V where $V$ is the number of vertices in a undirected graph. If there is an edge between V_{x} to V_{y} then the value of A[V_{x}][V_{y}]=1 and A[V_{y}][V_{x}]=1, otherwise the value will be zero. And for a directed graph, if there is an edge between V_{x} to V_{y}, then the value of A[V_{x}][V_{y}]=1, otherwise the value will be zero.

**Adjacency Matrix of an Undirected Graph**

Let us consider the following undirected graph and construct the adjacency matrix −

The adjacency matrix of the above-undirected graph will be −

a | b | c | d | |

a | 0 | 1 | 1 | 0 |

b | 1 | 0 | 1 | 0 |

c | 1 | 1 | 0 | 1 |

d | 0 | 0 | 1 | 0 |

**Adjacency Matrix of a Directed Graph**

Let us consider the following directed graph and construct its adjacency matrix −

The adjacency matrix of the above-directed graph will be −

a | b | c | d | |

a | 0 | 1 | 1 | 0 |

b | 0 | 0 | 1 | 0 |

c | 0 | 0 | 0 | 1 |

d | 0 | 0 | 0 | 0 |

## Adjacency List

In the adjacency list, an array (A[V]) of linked lists is used to represent the graph G with ** V** number of vertices. An entry A[V

_{x}] represents the linked list of vertices adjacent to the Vx-th vertex. The adjacency list of the undirected graph is as shown in the figure below −

- Related Questions & Answers
- Matrix Representation of Graphs
- Basic Concepts of Graphs
- Representation of fractions
- Isomorphism and Homeomorphism of graphs
- Bipartite Graphs
- Eulerian Graphs
- Hamiltonian Graphs
- Planar Graphs
- Strongly Connected Graphs
- Representation of Relations using Graph
- Array Representation Of Binary Heap
- What are the applications of Bipartite graphs?
- Connected vs Disconnected Graphs
- Representation of class hierarchy in DBMS
- String representation of Boolean in Java