educative.io

Graph application

I wanted to ask that Why and When is an Adjacency Matrix/List used? What is their real world application?

1 Like

Hi Regina,

Thank you for reaching out! We are happy to hear from you.

Well, the use of Adjacency Matrix or List totally depends upon the requirement and nature of your problem.
If you need to represent a graph that is sparse, i.e., it contains a very few edges, then using adjacency list is a wiser option as it lets you store only existing edges and hence saves a lot of space.

Adjacency matrices are used when the graphs are dense, i.e., it contains a lot of edges and is almost a complete graph. In this way, most of the cells get filled. Adjacency matrices do take a lot of space but they provide lookup in constant time. Adjacency lists on the other hand take linear time.

Coming to the second part of your question… they are widely used in almost every sub-field of computer science, Machine Learning, Information Retrieval, Computer Vision… you name it!

Hope this answers your question. :slight_smile:

2 Likes